From 54f0724de56c2bde8394c0f832501a5e36ad43f4 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 3 Mar 2019 13:04:18 -1000 Subject: [PATCH] D3D fixes --- CMakeLists.txt | 2 +- Runtime/Graphics/CGraphics.hpp | 2 +- .../Graphics/Shaders/CFluidPlaneShader.cpp | 1 + .../Graphics/Shaders/CModelShadersGLSL.cpp | 2 +- .../Graphics/Shaders/CModelShadersHLSL.cpp | 33 +- .../Graphics/Shaders/CModelShadersMetal.cpp | 7 +- Shaders/CColoredQuadFilter.shader | 1 + Shaders/CElementGenShaders.shader | 15 +- Shaders/CEnvFxShaders.shader | 8 +- Shaders/CLineRendererShaders.shader | 660 ++++++++++++++---- Shaders/CRandomStaticFilter.shader | 2 + Shaders/CScanLinesFilter.shader | 1 + Shaders/CTexturedQuadFilter.shader | 5 + Shaders/CThermalColdFilter.shader | 4 +- Shaders/shader_CFluidPlaneShaderGLSL.cpp | 2 +- Shaders/shader_CFluidPlaneShaderHLSL.cpp | 4 +- Shaders/shader_CFluidPlaneShaderMetal.cpp | 2 +- hecl | 2 +- specter | 2 +- 19 files changed, 596 insertions(+), 159 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c06f0469..59318eb44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ if(MSVC) -D_SCL_SECURE_NO_DEPRECATE=1 -D_CRT_NONSTDC_NO_WARNINGS=1 /IGNORE:4221 /wd4018 /wd4800 /wd4005 /wd4311 /wd4068 /wd4267 /wd4244 /wd4200 /wd4305 /wd4067 /wd4146 /wd4309 /wd4805 - -D_ENABLE_EXTENDED_ALIGNED_STORAGE=1 ${VS_DEFINES}) + -D_ENABLE_EXTENDED_ALIGNED_STORAGE=1 -D_ITERATOR_DEBUG_LEVEL=0 ${VS_DEFINES}) if(WINDOWS_STORE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /AI\"$ENV{PROGRAMFILES\(X86\)}/Microsoft Visual Studio/2017/Community/Common7/IDE/VC/vcpackages\" /AI\"$ENV{PROGRAMFILES\(X86\)}/Windows Kits/10/UnionMetadata\"") diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index 1d95f3674..873191a80 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -190,11 +190,11 @@ public: }; struct CFogState { - ERglFogMode m_mode; zeus::CColor m_color; float m_A = 0.f; float m_B = 0.5f; float m_C = 0.f; + ERglFogMode m_mode; }; static CProjectionState g_Proj; diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp index 376d88fbb..97154549f 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp @@ -205,6 +205,7 @@ void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info) { for (int i = 0; i < 3; ++i) uni.m_lighting.colorRegs[i] = info.kColors[i]; uni.m_lighting.mulColor = info.kColors[3]; + uni.m_lighting.fog = CGraphics::g_Fog; uni.m_pad2.x() = info.indScale; m_uniBuf->unmap(); } diff --git a/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp b/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp index 9560e7c64..f3dca84ca 100644 --- a/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp @@ -10,11 +10,11 @@ extern const hecl::Backend::Function ExtensionPostFuncsGLSL[]; #define FOG_STRUCT_GLSL \ "struct Fog\n" \ "{\n" \ - " int mode;\n" \ " vec4 color;\n" \ " float A;\n" \ " float B;\n" \ " float C;\n" \ + " int mode;\n" \ "};\n" #define FOG_ALGORITHM_GLSL \ diff --git a/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp b/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp index e033f5efd..deaaa52c9 100644 --- a/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp @@ -9,39 +9,40 @@ extern const hecl::Backend::Function ExtensionPostFuncsHLSL[]; #define FOG_STRUCT_HLSL \ "struct Fog\n" \ "{\n" \ - " int mode;\n" \ " float4 color;\n" \ - " float rangeScale;\n" \ - " float start;\n" \ + " float A;\n" \ + " float B;\n" \ + " float C;\n" \ + " int mode;\n" \ "};\n" #define FOG_ALGORITHM_HLSL \ - " float fogZ, temp;\n" \ + " float fogZ;\n" \ + " float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.mvpPos.z))) - fog.C);\n" \ " switch (fog.mode)\n" \ " {\n" \ " case 2:\n" \ - " fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n" \ + " fogZ = fogF;\n" \ " break;\n" \ " case 4:\n" \ - " fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - fog.start) * fog.rangeScale);\n" \ + " fogZ = 1.0 - exp2(-8.0 * fogF);\n" \ " break;\n" \ " case 5:\n" \ - " temp = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n" \ - " fogZ = 1.0 - exp2(-8.0 * temp * temp);\n" \ + " fogZ = 1.0 - exp2(-8.0 * fogF * fogF);\n" \ " break;\n" \ " case 6:\n" \ - " fogZ = exp2(-8.0 * (fog.start + vtf.mvPos.z) * fog.rangeScale);\n" \ + " fogZ = exp2(-8.0 * (1.0 - fogF));\n" \ " break;\n" \ " case 7:\n" \ - " temp = (fog.start + vtf.mvPos.z) * fog.rangeScale;\n" \ - " fogZ = exp2(-8.0 * temp * temp);\n" \ + " fogF = 1.0 - fogF;\n" \ + " fogZ = exp2(-8.0 * fogF * fogF);\n" \ " break;\n" \ " default:\n" \ " fogZ = 0.0;\n" \ " break;\n" \ " }\n" \ "#ifdef BLEND_DST_ONE\n" \ - " return float4(lerp(colorIn, float4(0.0, 0.0, 0.0, 0.0), saturate(fogZ)).rgb, colorIn.a);\n" \ + " return float4(lerp(colorIn, float4(0.0,0.0,0.0,0.0), saturate(fogZ)).rgb, colorIn.a);\n" \ "#else\n" \ " return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ "#endif\n" @@ -99,13 +100,7 @@ static std::string_view LightingShadowHLSL = " float4 linAtt;\n" " float4 angAtt;\n" "};\n" -"struct Fog\n" -"{\n" -" int mode;\n" -" float4 color;\n" -" float rangeScale;\n" -" float start;\n" -"};\n" +FOG_STRUCT_HLSL "\n" "cbuffer LightingUniform : register(b2)\n" "{\n" diff --git a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp index 299f8c961..f6defaea5 100644 --- a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp @@ -9,10 +9,11 @@ extern const hecl::Backend::Function ExtensionPostFuncsMetal[]; #define FOG_STRUCT_METAL \ "struct Fog\n" \ "{\n" \ - " int mode;\n" \ " float4 color;\n" \ - " float rangeScale;\n" \ - " float start;\n" \ + " float A;\n" \ + " float B;\n" \ + " float C;\n" \ + " int mode;\n" \ "};\n" #define FOG_ALGORITHM_METAL \ diff --git a/Shaders/CColoredQuadFilter.shader b/Shaders/CColoredQuadFilter.shader index 19dd93e39..1a26593e4 100644 --- a/Shaders/CColoredQuadFilter.shader +++ b/Shaders/CColoredQuadFilter.shader @@ -128,3 +128,4 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) #shader CColoredQuadFilterMul : CColoredQuadFilter #srcfac zero #dstfac srccolor +#overwritealpha true diff --git a/Shaders/CElementGenShaders.shader b/Shaders/CElementGenShaders.shader index 742c91c15..5298dac34 100644 --- a/Shaders/CElementGenShaders.shader +++ b/Shaders/CElementGenShaders.shader @@ -256,7 +256,9 @@ float4 main(in VertToFrag vtf) : SV_Target0 { float4 texel = tex0.Sample(samp, vtf.uv); float4 tmp = texel * vtf.color; - return float4(tmp * tmp.a, tmp.a * texel.r); + float4 colorOut = tmp * tmp.a; + colorOut.a = tmp.a * texel.r; + return colorOut; } #fragment metal @@ -273,7 +275,9 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], { float4 texel = tex0.sample(samp, vtf.uv); float4 tmp = texel * vtf.color; - return float4(tmp * tmp.a, tmp.a * texel.r); + float4 colorOut = tmp * tmp.a; + colorOut.a = tmp.a * texel.r; + return colorOut; } #shader CElementGenShaderTexRedToAlphaZTestAWrite : CElementGenShaderTexRedToAlphaZTest @@ -404,8 +408,6 @@ VertToFrag main(in VertData v, in uint vertId : SV_VertexID) VertToFrag vtf; vtf.color = v.colorIn * moduColor; vtf.uvScene = v.uvsInScene; - vtf.uvScene.y = 1.0 - vtf.uvScene.y; - vtf.uvScene.w = 1.0 - vtf.uvScene.w; vtf.uvTexr = v.uvsInTexrTind[vertId].xy; vtf.uvTind = v.uvsInTexrTind[vertId].zw; vtf.position = mul(mvp, v.posIn[vertId]); @@ -495,8 +497,9 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], float2 tindTexel = tex2.sample(samp, vtf.uvTind).ba; float4 sceneTexel = tex1.sample(samp, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); float4 texrTexel = tex0.sample(samp, vtf.uvTexr); - float4 colr = vtf.color * float4(sceneTexel.rgb, 1.0) + texrTexel; - return float4(colr.rgb, vtf.color.a * texrTexel.a); + float4 colorOut = vtf.color * float4(sceneTexel.rgb, 1.0) + texrTexel; + colorOut.a = vtf.color.a * texrTexel.a; + return colorOut; } #shader CElementGenShaderIndTexZWriteAWrite : CElementGenShaderIndTexZWrite diff --git a/Shaders/CEnvFxShaders.shader b/Shaders/CEnvFxShaders.shader index 4b22adce6..ddb23e634 100644 --- a/Shaders/CEnvFxShaders.shader +++ b/Shaders/CEnvFxShaders.shader @@ -64,11 +64,11 @@ TBINDING1 uniform sampler2D texEnv; UBINDING1 uniform FogUniform { - int mode; vec4 color; float A; float B; float C; + int mode; }; vec4 MainPostFunc(vec4 colorIn) @@ -158,17 +158,17 @@ struct VertToFrag cbuffer FogUniform : register(b1) { - int mode; float4 color; float A; float B; float C; + int mode; }; static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn) { float fogZ; - float fogF = saturate((A / (B - vtf.position.z)) - C); + float fogF = saturate((A / (B - (1.0 - vtf.position.z))) - C); switch (mode) { case 2: @@ -251,11 +251,11 @@ struct VertToFrag struct FogUniform { - int mode; float4 color; float A; float B; float C; + int mode; }; float4 MainPostFunc(thread VertToFrag& vtf, constant FogUniform& fu, float4 colorIn) diff --git a/Shaders/CLineRendererShaders.shader b/Shaders/CLineRendererShaders.shader index 4a9903959..149b8608e 100644 --- a/Shaders/CLineRendererShaders.shader +++ b/Shaders/CLineRendererShaders.shader @@ -32,11 +32,248 @@ void main() #fragment glsl struct Fog { - int mode; vec4 color; float A; float B; float C; + int mode; +}; + +UBINDING0 uniform LineUniform +{ + vec4 moduColor; + Fog fog; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +vec4 MainPostFunc(vec4 colorIn) +{ + float fogZ; + float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); + switch (fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); +} + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = MainPostFunc(vtf.color * moduColor * texture(tex, vtf.uv)); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 colorIn : COLOR; + float4 uvIn : UV; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = v.colorIn; + vtf.uv = v.uvIn.xy; + vtf.position = v.posIn; + return vtf; +} + +#fragment hlsl +struct Fog +{ + float4 color; + float A; + float B; + float C; + int mode; +}; + +cbuffer LineUniform : register(b0) +{ + float4 moduColor; + Fog fog; +}; + +SamplerState samp : register(s3); +Texture2D tex0 : register(t0); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn) +{ + float fogZ; + float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.position.z))) - fog.C); + switch (fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a); +} + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return MainPostFunc(vtf, vtf.color * moduColor * tex0.Sample(samp, vtf.uv)); +} + +#vertex metal +struct VertData +{ + float4 posIn; + float4 colorIn; + float4 uvIn; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], + uint vertId [[ vertex_id ]]) +{ + VertToFrag vtf; + constant VertData& v = va[vertId]; + vtf.color = v.colorIn; + vtf.uv = v.uvIn.xy; + vtf.position = v.posIn; + return vtf; +} + +#fragment metal +struct Fog +{ + float4 color; + float A; + float B; + float C; + int mode; +}; + +struct LineUniform +{ + float4 moduColor; + Fog fog; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +static float4 MainPostFunc(thread VertToFrag& vtf, constant LineUniform& line, float4 colorIn) +{ + float fogZ; + float fogF = saturate((line.fog.A / (line.fog.B - vtf.position.z)) - line.fog.C); + switch (line.fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return float4(mix(colorIn, line.fog.color, saturate(fogZ)).rgb, colorIn.a); +} + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(3) ]], + texture2d tex0 [[ texture(0) ]], + constant LineUniform& line [[ buffer(2) ]]) +{ + return MainPostFunc(vtf, line, vtf.color * line.moduColor * tex0.sample(samp, vtf.uv)); +} + +#shader CLineRendererShaderTexAlphaAWrite : CLineRendererShaderTexAlpha +#alphawrite true + +#shader CLineRendererShaderTexAdditive : CLineRendererShaderTexAlpha +#srcfac srcalpha +#dstfac one +#depthtest none +#alphawrite false + +#fragment glsl +struct Fog +{ + vec4 color; + float A; + float B; + float C; + int mode; }; UBINDING0 uniform LineUniform @@ -88,36 +325,22 @@ void main() colorOut = MainPostFunc(vtf.color * moduColor * texture(tex, vtf.uv)); } -#vertex hlsl -struct VertData +#fragment hlsl +struct Fog { - float4 posIn : POSITION; - float4 colorIn : COLOR; - float4 uvIn : UV; + float4 color; + float A; + float B; + float C; + int mode; }; cbuffer LineUniform : register(b0) { float4 moduColor; + Fog fog; }; -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; - float2 uv : UV; -}; - -VertToFrag main(in VertData v) -{ - VertToFrag vtf; - vtf.color = v.colorIn * moduColor; - vtf.uv = v.uvIn.xy; - vtf.position = v.posIn; - return vtf; -} - -#fragment hlsl SamplerState samp : register(s3); Texture2D tex0 : register(t0); struct VertToFrag @@ -127,22 +350,54 @@ struct VertToFrag float2 uv : UV; }; -float4 main(in VertToFrag vtf) : SV_Target0 +static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn) { - return vtf.color * tex0.Sample(samp, vtf.uv); + float fogZ; + float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.position.z))) - fog.C); + switch (fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return float4(lerp(colorIn, float4(0.0,0.0,0.0,0.0), saturate(fogZ)).rgb, colorIn.a); } -#vertex metal -struct VertData +float4 main(in VertToFrag vtf) : SV_Target0 { - float4 posIn; - float4 colorIn; - float4 uvIn; + return MainPostFunc(vtf, vtf.color * moduColor * tex0.Sample(samp, vtf.uv)); +} + +#fragment metal +struct Fog +{ + float4 color; + float A; + float B; + float C; + int mode; }; struct LineUniform { float4 moduColor; + Fog fog; }; struct VertToFrag @@ -152,42 +407,43 @@ struct VertToFrag float2 uv; }; -vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], - uint vertId [[ vertex_id ]], - constant LineUniform& line [[ buffer(2) ]]) +static float4 MainPostFunc(thread VertToFrag& vtf, constant LineUniform& line, float4 colorIn) { - VertToFrag vtf; - constant VertData& v = va[vertId]; - vtf.color = v.colorIn * line.moduColor; - vtf.uv = v.uvIn.xy; - vtf.position = v.posIn; - return vtf; + float fogZ; + float fogF = saturate((line.fog.A / (line.fog.B - vtf.position.z)) - line.fog.C); + switch (line.fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a); } -#fragment metal -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; - float2 uv; -}; - fragment float4 fmain(VertToFrag vtf [[ stage_in ]], sampler samp [[ sampler(3) ]], - texture2d tex0 [[ texture(0) ]]) + texture2d tex0 [[ texture(0) ]], + constant LineUniform& line [[ buffer(2) ]]) { - return vtf.color * tex0.sample(samp, vtf.uv); + return MainPostFunc(vtf, line, vtf.color * line.moduColor * tex0.sample(samp, vtf.uv)); } -#shader CLineRendererShaderTexAlphaAWrite : CLineRendererShaderTexAlpha -#alphawrite true - -#shader CLineRendererShaderTexAdditive : CLineRendererShaderTexAlpha -#srcfac srcalpha -#dstfac one -#depthtest none -#alphawrite false - #shader CLineRendererShaderTexAdditiveAWrite : CLineRendererShaderTexAdditive #alphawrite true @@ -200,7 +456,7 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #shader CLineRendererShaderTexAlphaZAWrite : CLineRendererShaderTexAlphaZ #alphawrite true -#shader CLineRendererShaderTexAdditiveZ : CLineRendererShaderTexAlpha +#shader CLineRendererShaderTexAdditiveZ : CLineRendererShaderTexAdditive #srcfac srcalpha #dstfac one #depthtest lequal @@ -239,11 +495,234 @@ void main() #fragment glsl struct Fog { - int mode; vec4 color; float A; float B; float C; + int mode; +}; + +UBINDING0 uniform LineUniform +{ + vec4 moduColor; + Fog fog; +}; + +struct VertToFrag +{ + vec4 color; +}; + +vec4 MainPostFunc(vec4 colorIn) +{ + float fogZ; + float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); + switch (fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); +} + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = MainPostFunc(vtf.color * moduColor); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 colorIn : COLOR; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = v.colorIn; + vtf.position = v.posIn; + return vtf; +} + +#fragment hlsl +struct Fog +{ + float4 color; + float A; + float B; + float C; + int mode; +}; + +cbuffer LineUniform : register(b0) +{ + float4 moduColor; + Fog fog; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +static float4 MainPostFunc(float4 colorIn, float4 FragCoord) +{ + float fogZ; + float fogF = saturate((fog.A / (fog.B - (1.0 - FragCoord.z))) - fog.C); + switch (fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a); +} + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return MainPostFunc(vtf.color * moduColor, vtf.position); +} + +#vertex metal +struct VertData +{ + float4 posIn; + float4 colorIn; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], + uint vertId [[ vertex_id ]]) +{ + VertToFrag vtf; + constant VertData& v = va[vertId]; + vtf.color = v.colorIn; + vtf.position = v.posIn; + return vtf; +} + +#fragment metal +struct Fog +{ + float4 color; + float A; + float B; + float C; + int mode; +}; + +struct LineUniform +{ + float4 moduColor; + Fog fog; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float FragCoord) +{ + float fogZ; + float fogF = saturate((line.fog.A / (line.fog.B - FragCoord.z)) - line.fog.C); + switch (line.fog.mode) + { + case 2: + fogZ = fogF; + break; + case 4: + fogZ = 1.0 - exp2(-8.0 * fogF); + break; + case 5: + fogZ = 1.0 - exp2(-8.0 * fogF * fogF); + break; + case 6: + fogZ = exp2(-8.0 * (1.0 - fogF)); + break; + case 7: + fogF = 1.0 - fogF; + fogZ = exp2(-8.0 * fogF * fogF); + break; + default: + fogZ = 0.0; + break; + } + return float4(mix(colorIn, line.fog.color, saturate(fogZ)).rgb, colorIn.a); +} + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + constant LineUniform& line [[ buffer(2) ]]) +{ + return MainPostFunc(vtf.color * line.moduColor, line, vtf.position); +} + +#shader CLineRendererShaderNoTexAlphaAWrite : CLineRendererShaderNoTexAlpha +#alphawrite true + +#shader CLineRendererShaderNoTexAdditive : CLineRendererShaderNoTexAlpha +#srcfac srcalpha +#dstfac one +#depthtest none +#alphawrite false + +#fragment glsl +struct Fog +{ + vec4 color; + float A; + float B; + float C; + int mode; }; UBINDING0 uniform LineUniform @@ -293,35 +772,14 @@ void main() colorOut = MainPostFunc(vtf.color * moduColor); } -#vertex hlsl -struct VertData -{ - float4 posIn : POSITION; - float4 colorIn : COLOR; -}; - -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; -}; - -VertToFrag main(in VertData v) -{ - VertToFrag vtf; - vtf.color = v.colorIn; - vtf.position = v.posIn; - return vtf; -} - #fragment hlsl struct Fog { - int mode; float4 color; float A; float B; float C; + int mode; }; cbuffer LineUniform : register(b0) @@ -339,7 +797,7 @@ struct VertToFrag static float4 MainPostFunc(float4 colorIn, float4 FragCoord) { float fogZ; - float fogF = saturate((fog.A / (fog.B - FragCoord.z)) - fog.C); + float fogF = saturate((fog.A / (fog.B - (1.0 - FragCoord.z))) - fog.C); switch (fog.mode) { case 2: @@ -370,37 +828,14 @@ float4 main(in VertToFrag vtf) : SV_Target0 return MainPostFunc(vtf.color * moduColor, vtf.position); } -#vertex metal -struct VertData -{ - float4 posIn; - float4 colorIn; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; -}; - -vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], - uint vertId [[ vertex_id ]]) -{ - VertToFrag vtf; - constant VertData& v = va[vertId]; - vtf.color = v.colorIn; - vtf.position = v.posIn; - return vtf; -} - #fragment metal struct Fog { - int mode; float4 color; float A; float B; float C; + int mode; }; struct LineUniform @@ -450,15 +885,6 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], return MainPostFunc(vtf.color * line.moduColor, line, vtf.position); } -#shader CLineRendererShaderNoTexAlphaAWrite : CLineRendererShaderNoTexAlpha -#alphawrite true - -#shader CLineRendererShaderNoTexAdditive : CLineRendererShaderNoTexAlpha -#srcfac srcalpha -#dstfac one -#depthtest none -#alphawrite false - #shader CLineRendererShaderNoTexAdditiveAWrite : CLineRendererShaderNoTexAdditive #alphawrite true @@ -471,7 +897,7 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #shader CLineRendererShaderNoTexAlphaZAWrite : CLineRendererShaderNoTexAlphaZ #alphawrite true -#shader CLineRendererShaderNoTexAdditiveZ : CLineRendererShaderNoTexAlpha +#shader CLineRendererShaderNoTexAdditiveZ : CLineRendererShaderNoTexAdditive #srcfac srcalpha #dstfac one #depthtest lequal diff --git a/Shaders/CRandomStaticFilter.shader b/Shaders/CRandomStaticFilter.shader index e96b7816f..5c034344a 100644 --- a/Shaders/CRandomStaticFilter.shader +++ b/Shaders/CRandomStaticFilter.shader @@ -200,10 +200,12 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #shader CRandomStaticFilterMult : CRandomStaticFilterAlpha #srcfac zero #dstfac srccolor +#overwritealpha true #shader CRandomStaticFilterCookieCutter : CRandomStaticFilterAlpha #srcfac zero #dstfac srccolor +#overwritealpha true #depthwrite true #colorwrite false #depthtest lequal diff --git a/Shaders/CScanLinesFilter.shader b/Shaders/CScanLinesFilter.shader index ef1879592..b7b2c040b 100644 --- a/Shaders/CScanLinesFilter.shader +++ b/Shaders/CScanLinesFilter.shader @@ -121,3 +121,4 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) #shader CScanLinesFilterMult : CScanLinesFilterAlpha #srcfac zero #dstfac srccolor +#overwritealpha true diff --git a/Shaders/CTexturedQuadFilter.shader b/Shaders/CTexturedQuadFilter.shader index 3065108e5..504700f9f 100644 --- a/Shaders/CTexturedQuadFilter.shader +++ b/Shaders/CTexturedQuadFilter.shader @@ -180,6 +180,7 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #srcfac zero #dstfac srccolor #depthtest none +#overwritealpha true #shader CTexturedQuadFilterMultGEqual : CTexturedQuadFilterMult #depthtest gequal @@ -191,6 +192,7 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #srcfac zero #dstfac invsrccolor #depthtest none +#overwritealpha true #shader CTexturedQuadFilterInvDstMultGEqual : CTexturedQuadFilterInvDstMult #depthtest gequal @@ -204,6 +206,7 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #srcfac srcalpha #dstfac invsrcalpha #depthtest none +#overwritealpha false #fragment glsl struct VertToFrag @@ -265,10 +268,12 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #shader CTexturedQuadFilterAlphaTexMult : CTexturedQuadFilterAlphaTexAlpha #srcfac zero #dstfac srccolor +#overwritealpha true #shader CTexturedQuadFilterAlphaTexInvDstMult : CTexturedQuadFilterAlphaTexAlpha #srcfac zero #dstfac invsrccolor +#overwritealpha true #shader CTexturedQuadFilterAlphaGEqualZWrite : CTexturedQuadFilterAlpha #depthtest gequal diff --git a/Shaders/CThermalColdFilter.shader b/Shaders/CThermalColdFilter.shader index be6da9777..2c1f7a757 100644 --- a/Shaders/CThermalColdFilter.shader +++ b/Shaders/CThermalColdFilter.shader @@ -159,7 +159,9 @@ float4 main(in VertToFrag vtf) : SV_Target0 { float4 noiseTexel = noiseTex.Load(Lookup8BPP(vtf.noiseUv, vtf.randOff)); float2 indCoord = mul(vtf.indMtx, float3(noiseTexel.r - 0.5, noiseTexel.a - 0.5, 1.0)).xy; - float indScene = dot(sceneTex.Sample(samp, vtf.sceneUv + indCoord), kRGBToYPrime) + 16.0 / 255.0; + float2 sceneUv = vtf.sceneUv + indCoord; + sceneUv.y = 1.0 - sceneUv.y; + float indScene = dot(sceneTex.Sample(samp, sceneUv), kRGBToYPrime) + 16.0 / 255.0; float4 colorOut = vtf.colorReg0 * indScene + vtf.colorReg2 - vtf.colorReg1 * noiseTexel.r; colorOut.a = vtf.colorReg1.a + vtf.colorReg1.a * noiseTexel.r + vtf.colorReg2.a; return colorOut; diff --git a/Shaders/shader_CFluidPlaneShaderGLSL.cpp b/Shaders/shader_CFluidPlaneShaderGLSL.cpp index 3d4b16b92..ef284b706 100644 --- a/Shaders/shader_CFluidPlaneShaderGLSL.cpp +++ b/Shaders/shader_CFluidPlaneShaderGLSL.cpp @@ -3,11 +3,11 @@ #define FOG_STRUCT_GLSL \ "struct Fog\n" \ "{\n" \ - " int mode;\n" \ " vec4 color;\n" \ " float A;\n" \ " float B;\n" \ " float C;\n" \ + " int mode;\n" \ " float indScale;\n" \ "};\n" diff --git a/Shaders/shader_CFluidPlaneShaderHLSL.cpp b/Shaders/shader_CFluidPlaneShaderHLSL.cpp index f05538772..38c887c94 100644 --- a/Shaders/shader_CFluidPlaneShaderHLSL.cpp +++ b/Shaders/shader_CFluidPlaneShaderHLSL.cpp @@ -3,11 +3,11 @@ #define FOG_STRUCT_HLSL \ "struct Fog\n" \ "{\n" \ - " int mode;\n" \ " float4 color;\n" \ " float A;\n" \ " float B;\n" \ " float C;\n" \ + " int mode;\n" \ " float indScale;\n" \ "};\n" @@ -15,7 +15,7 @@ "static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n" \ "{\n" \ " float fogZ;\n" \ - " float fogF = saturate((fog.A / (fog.B - vtf.pos.z)) - fog.C);\n" \ + " float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.pos.z))) - fog.C);\n" \ " switch (fog.mode)\n" \ " {\n" \ " case 2:\n" \ diff --git a/Shaders/shader_CFluidPlaneShaderMetal.cpp b/Shaders/shader_CFluidPlaneShaderMetal.cpp index 7c3ca0e61..5b046027f 100644 --- a/Shaders/shader_CFluidPlaneShaderMetal.cpp +++ b/Shaders/shader_CFluidPlaneShaderMetal.cpp @@ -3,11 +3,11 @@ #define FOG_STRUCT_METAL \ "struct Fog\n" \ "{\n" \ - " int mode;\n" \ " float4 color;\n" \ " float A;\n" \ " float B;\n" \ " float C;\n" \ + " int mode;\n" \ " float indScale;\n" \ "};\n" diff --git a/hecl b/hecl index bfd649cd9..ad075d532 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit bfd649cd9f2b9d4382d83d5b0971f97e0ac98d84 +Subproject commit ad075d532e478c0f90b86200828ef7585050c817 diff --git a/specter b/specter index 935f781e0..c56b69627 160000 --- a/specter +++ b/specter @@ -1 +1 @@ -Subproject commit 935f781e03a7f23b17d202ce8740a4b32a06140a +Subproject commit c56b69627ca3daee510ca1c52aa7198634519d0a