diff --git a/CMakeLists.txt b/CMakeLists.txt index 59318eb44..0c06f0469 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 -D_ITERATOR_DEBUG_LEVEL=0 ${VS_DEFINES}) + -D_ENABLE_EXTENDED_ALIGNED_STORAGE=1 ${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/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp index a7dbeb5e4..969f3a126 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -146,7 +146,7 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = { {1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true}, /* Thermal cold shading */ - {1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, + {0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, false, false, true, false, false, false, true}, /* Normal lit shading with alpha */ diff --git a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp index f6defaea5..4107e2deb 100644 --- a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp @@ -17,25 +17,25 @@ extern const hecl::Backend::Function ExtensionPostFuncsMetal[]; "};\n" #define FOG_ALGORITHM_METAL \ - " float fogZ, temp;\n" \ + " float fogZ;\n" \ + " float fogF = saturate((lu.fog.A / (lu.fog.B - (1.0 - vtf.mvpPos.z))) - lu.fog.C);\n" \ " switch (lu.fog.mode)\n" \ " {\n" \ " case 2:\n" \ - " fogZ = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n" \ + " fogZ = fogF;\n" \ " break;\n" \ " case 4:\n" \ - " fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale);\n" \ + " fogZ = 1.0 - exp2(-8.0 * fogF);\n" \ " break;\n" \ " case 5:\n" \ - " temp = (-vtf.mvPos.z - lu.fog.start) * lu.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 * (lu.fog.start + vtf.mvPos.z) * lu.fog.rangeScale);\n" \ + " fogZ = exp2(-8.0 * (1.0 - fogF));\n" \ " break;\n" \ " case 7:\n" \ - " temp = (lu.fog.start + vtf.mvPos.z) * lu.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" \ @@ -44,7 +44,7 @@ extern const hecl::Backend::Function ExtensionPostFuncsMetal[]; "#ifdef BLEND_DST_ONE\n" \ " return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n" \ "#else\n" \ - " return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ + " return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ "#endif\n" static std::string_view LightingMetal = @@ -100,13 +100,7 @@ static std::string_view LightingShadowMetal = " 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_METAL "\n" "struct LightingUniform\n" "{\n" @@ -221,7 +215,7 @@ static std::string_view DisintegratePostMetal = FOG_STRUCT_METAL "\n"sv; static std::string_view ThermalColdPostMetal = - "static float4 ThermalColdPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n" + "static float4 ThermalColdPostFunc(thread VertToFrag& vtf, float4 colorIn)\n" "{\n" " return colorIn * float4(0.75, 0.75, 0.75, 0.75);\n" "}\n" diff --git a/Shaders/CElementGenShaders.shader b/Shaders/CElementGenShaders.shader index 5298dac34..ed488cceb 100644 --- a/Shaders/CElementGenShaders.shader +++ b/Shaders/CElementGenShaders.shader @@ -470,8 +470,6 @@ vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], constant VertData& v = va[instId]; vtf.color = v.colorIn * particle.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 = particle.mvp * v.posIn[vertId]; diff --git a/Shaders/CEnvFxShaders.shader b/Shaders/CEnvFxShaders.shader index ddb23e634..ee43e3b4e 100644 --- a/Shaders/CEnvFxShaders.shader +++ b/Shaders/CEnvFxShaders.shader @@ -261,7 +261,7 @@ struct FogUniform float4 MainPostFunc(thread VertToFrag& vtf, constant FogUniform& fu, float4 colorIn) { float fogZ; - float fogF = saturate((fu.A / (fu.B - vtf.position.z)) - fu.C); + float fogF = saturate((fu.A / (fu.B - (1.0 - vtf.position.z))) - fu.C); switch (fu.mode) { case 2: diff --git a/Shaders/CLineRendererShaders.shader b/Shaders/CLineRendererShaders.shader index 149b8608e..328e2535e 100644 --- a/Shaders/CLineRendererShaders.shader +++ b/Shaders/CLineRendererShaders.shader @@ -223,7 +223,7 @@ struct VertToFrag 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); + float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - vtf.position.z))) - line.fog.C); switch (line.fog.mode) { case 2: @@ -410,7 +410,7 @@ struct VertToFrag 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); + float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - vtf.position.z))) - line.fog.C); switch (line.fog.mode) { case 2: @@ -671,10 +671,10 @@ struct VertToFrag float4 color; }; -static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float FragCoord) +static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float4 FragCoord) { float fogZ; - float fogF = saturate((line.fog.A / (line.fog.B - FragCoord.z)) - line.fog.C); + float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - FragCoord.z))) - line.fog.C); switch (line.fog.mode) { case 2: @@ -850,10 +850,10 @@ struct VertToFrag float4 color; }; -static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float FragCoord) +static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float4 FragCoord) { float fogZ; - float fogF = saturate((line.fog.A / (line.fog.B - FragCoord.z)) - line.fog.C); + float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - FragCoord.z))) - line.fog.C); switch (line.fog.mode) { case 2: diff --git a/Shaders/CThermalColdFilter.shader b/Shaders/CThermalColdFilter.shader index 2c1f7a757..9bf590ca3 100644 --- a/Shaders/CThermalColdFilter.shader +++ b/Shaders/CThermalColdFilter.shader @@ -247,8 +247,11 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], texture2d noiseTex [[ texture(1) ]]) { float4 noiseTexel = noiseTex.read(Lookup8BPP(vtf.noiseUv, vtf.randOff)); - float2 indCoord = (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 indCoord = (float3x3(vtf.indMtx0, vtf.indMtx1, vtf.indMtx2) * float3(noiseTexel.r - 0.5, noiseTexel.a - 0.5, 1.0)).xy; + 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_CFluidPlaneShaderMetal.cpp b/Shaders/shader_CFluidPlaneShaderMetal.cpp index 5b046027f..9db811baf 100644 --- a/Shaders/shader_CFluidPlaneShaderMetal.cpp +++ b/Shaders/shader_CFluidPlaneShaderMetal.cpp @@ -15,7 +15,7 @@ "static float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n" \ "{\n" \ " float fogZ;\n" \ - " float fogF = saturate((lu.fog.A / (lu.fog.B - vtf.pos.z)) - lu.fog.C);\n" \ + " float fogF = saturate((lu.fog.A / (lu.fog.B - (1.0 - vtf.pos.z))) - lu.fog.C);\n" \ " switch (lu.fog.mode)\n" \ " {\n" \ " case 2:\n" \ @@ -41,7 +41,7 @@ "#if %d\n" \ " return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n" \ "#else\n" \ - " return float4(mix(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ + " return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ "#endif\n" \ "}\n"