-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add ability to turn on and off post process plugins - Improve dithering - Add drawText background
- Loading branch information
Showing
20 changed files
with
284 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
#ifndef INCLUDED_DITHER | ||
#define INCLUDED_DITHER | ||
|
||
float3 getDither(float2 pos, float3 c, float intensity) { | ||
int DITHER_THRESHOLDS[16] = { | ||
-4, 0, -3, 1, | ||
2, -2, 3, -1, | ||
-3, 1, -4, 0, | ||
3, -1, 2, -2 | ||
}; | ||
|
||
int DITHER_COLORS = 256; | ||
uint index = (uint(pos.x) & 3) * 4 + (uint(pos.y) & 3); | ||
|
||
c.rgb = clamp(c.rgb * (DITHER_COLORS - 1) + DITHER_THRESHOLDS[index] * (intensity * 100), min16float3(0, 0, 0), min16float3(DITHER_COLORS - 1, DITHER_COLORS - 1, DITHER_COLORS - 1)); | ||
c /= DITHER_COLORS; | ||
|
||
return c; | ||
} | ||
|
||
float getDitherFast(float2 uv, float factor) { | ||
float DITHER_THRESHOLDS[16] ={ | ||
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0, | ||
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0, | ||
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0, | ||
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0 | ||
}; | ||
|
||
uint index = (uint(uv.x) % 4) * 4 + uint(uv.y) % 4; | ||
return factor - DITHER_THRESHOLDS[index]; | ||
} | ||
|
||
float alphaDither(float2 uv, float alpha) { | ||
float DITHER_THRESHOLDS[16] ={ | ||
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0, | ||
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0, | ||
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0, | ||
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0 | ||
}; | ||
|
||
uint index = (uint(uv.x) % 4) * 4 + uint(uv.y) % 4; | ||
clip(alpha - DITHER_THRESHOLDS[index]); | ||
|
||
return alpha; | ||
} | ||
#define INCLUDED_DITHER | ||
|
||
float3 getDither(float2 pos, float3 c, float intensity) { | ||
int DITHER_THRESHOLDS[16] = { | ||
-4, 0, -3, 1, | ||
2, -2, 3, -1, | ||
-3, 1, -4, 0, | ||
3, -1, 2, -2 | ||
}; | ||
|
||
int DITHER_COLORS = 128; | ||
uint index = (uint(pos.x) & 3) * 4 + (uint(pos.y) & 3); | ||
|
||
c.rgb = clamp(c.rgb * (DITHER_COLORS - 1) + DITHER_THRESHOLDS[index] * (intensity * 100), min16float3(0, 0, 0), min16float3(DITHER_COLORS - 1, DITHER_COLORS - 1, DITHER_COLORS - 1)); | ||
c /= DITHER_COLORS; | ||
|
||
return c; | ||
} | ||
|
||
float getDitherFast(float2 uv, float factor) { | ||
float DITHER_THRESHOLDS[16] ={ | ||
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0, | ||
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0, | ||
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0, | ||
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0 | ||
}; | ||
|
||
uint index = (uint(uv.x) % 4) * 4 + uint(uv.y) % 4; | ||
return factor - DITHER_THRESHOLDS[index]; | ||
} | ||
|
||
float alphaDither(float2 uv, float alpha) { | ||
float DITHER_THRESHOLDS[16] ={ | ||
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0, | ||
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0, | ||
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0, | ||
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0 | ||
}; | ||
|
||
uint index = (uint(uv.x) % 4) * 4 + uint(uv.y) % 4; | ||
clip(alpha - DITHER_THRESHOLDS[index]); | ||
|
||
return alpha; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "camera.fxh" | ||
|
||
#define UINT_DATA | ||
#include "pixel_post_process_uniforms.fxh" | ||
|
||
#include "math.fxh" | ||
#include "unpack.fxh" | ||
|
||
// ## MAPPING ---------------- | ||
#define START_COLOR PostProcessConstants.data[0].x | ||
#define END_COLOR PostProcessConstants.data[0].y | ||
#define PSX_BANDING PostProcessConstants.data[0].z | ||
// ======================== | ||
|
||
Texture2DArray g_Textures[]; | ||
SamplerState g_Sampler; | ||
|
||
struct PSInput { | ||
float4 Pos : SV_POSITION; | ||
float2 UV : TEX_COORD; | ||
}; | ||
|
||
struct PSOutput { | ||
float4 Color : SV_TARGET; | ||
}; | ||
|
||
void main(in PSInput PSIn, out PSOutput PSOut) { | ||
#if defined(DESKTOP_GL) || defined(GL_ES) | ||
float3 UV = float3(PSIn.UV.x, 1.0 - PSIn.UV.y, 0); | ||
#else | ||
float3 UV = float3(PSIn.UV.xy, 0); | ||
#endif | ||
|
||
float Depth = g_Textures[PostProcessConstants.textureDepthID].Sample(g_Sampler, UV).r; | ||
Depth = 1.0 - (2.0 * NearFar.x) / (NearFar.y + NearFar.x - Depth * (NearFar.y - NearFar.x)); | ||
if (Depth > 0.01) { | ||
PSOut.Color = g_Textures[PostProcessConstants.textureID].Sample(g_Sampler, UV); | ||
return; | ||
} | ||
|
||
// Calculate the view direction vector | ||
float3 viewDir = mul(float4(PSIn.UV * 2.0 - 1.0, 1.0, 1.0), Camera.viewInv).xyz; | ||
viewDir = normalize(viewDir); | ||
|
||
float2 texCoord = float2( | ||
floor((atan2(viewDir.z, viewDir.x) / (2.0 * PI) + 0.5) * PSX_BANDING) / PSX_BANDING, | ||
floor((acos(viewDir.y) / PI) * PSX_BANDING) / PSX_BANDING | ||
); | ||
|
||
PSOut.Color = lerp(Unpack_RGBA8_UNORM(END_COLOR), Unpack_RGBA8_UNORM(START_COLOR), texCoord.y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
rawrbox.render/include/rawrbox/render/post_process/skybox.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#define UINT_DATA | ||
#include <rawrbox/render/post_process/base.hpp> | ||
|
||
namespace rawrbox { | ||
class PostProcessSkybox : public rawrbox::PostProcessBase { | ||
public: | ||
explicit PostProcessSkybox(const rawrbox::Colorf& startColor, const rawrbox::Colorf& endColor); | ||
PostProcessSkybox(PostProcessSkybox&&) = delete; | ||
PostProcessSkybox& operator=(PostProcessSkybox&&) = delete; | ||
PostProcessSkybox(const PostProcessSkybox&) = delete; | ||
PostProcessSkybox& operator=(const PostProcessSkybox&) = delete; | ||
~PostProcessSkybox() override = default; | ||
|
||
virtual void setStartColor(const rawrbox::Colorf& col); | ||
virtual void setEndColor(const rawrbox::Colorf& col); | ||
virtual void setPSXBanding(uint32_t banding); | ||
|
||
void init() override; | ||
}; | ||
} // namespace rawrbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.