From 3997d456cd2e0fd0adccf8b5260931fe6c88aaf9 Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Sun, 16 Jul 2023 21:39:57 -0700 Subject: [PATCH 1/6] ci: add clang_format action --- .github/workflows/clang_format.yml | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/clang_format.yml diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml new file mode 100644 index 000000000..ee66dd585 --- /dev/null +++ b/.github/workflows/clang_format.yml @@ -0,0 +1,32 @@ +name: Run clang-format Linter + +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # check out HEAD on the branch + ref: ${{ github.head_ref }} + # make sure the parent commit is grabbed as well, because + # that's what will get formatted (i.e. the most recent commit) + fetch-depth: 2 + # format the latest commit + - uses: DoozyX/clang-format-lint-action@v0.16.2 + with: + source: "." + exclude: "./extern,./include" + extensions: "h,cpp,c,hlsl,hlsli" + clangFormatVersion: 16 + inplace: True # commit the changes (if there are any) + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4.1.2 + with: + commit_message: "style: 🎨 apply clang-format changes" + branch: ${{ github.head_ref }} From 4a5766683314021325ec32e9052521d66bfba3de Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Sun, 16 Jul 2023 21:46:47 -0700 Subject: [PATCH 2/6] ci: fix exclude syntax --- .github/workflows/clang_format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml index ee66dd585..c98126c6d 100644 --- a/.github/workflows/clang_format.yml +++ b/.github/workflows/clang_format.yml @@ -21,7 +21,7 @@ jobs: - uses: DoozyX/clang-format-lint-action@v0.16.2 with: source: "." - exclude: "./extern,./include" + exclude: "extern include" extensions: "h,cpp,c,hlsl,hlsli" clangFormatVersion: 16 inplace: True # commit the changes (if there are any) From 3b1d1f10fddcb5e382ab020f9413cd61f9fc64b1 Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Sun, 16 Jul 2023 21:47:08 -0700 Subject: [PATCH 3/6] ci: unpin commit version --- .github/workflows/clang_format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml index c98126c6d..7b18e33f4 100644 --- a/.github/workflows/clang_format.yml +++ b/.github/workflows/clang_format.yml @@ -26,7 +26,7 @@ jobs: clangFormatVersion: 16 inplace: True # commit the changes (if there are any) - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4.1.2 + uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "style: 🎨 apply clang-format changes" branch: ${{ github.head_ref }} From 47ff847e8476b8c7e91d2e578307b828a699a436 Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Sun, 16 Jul 2023 21:47:22 -0700 Subject: [PATCH 4/6] ci: give write permission to clang --- .github/workflows/clang_format.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml index 7b18e33f4..05bd02811 100644 --- a/.github/workflows/clang_format.yml +++ b/.github/workflows/clang_format.yml @@ -9,6 +9,10 @@ on: jobs: format: runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write steps: - uses: actions/checkout@v3 with: From 3b4eb8628f857dd70e916388022517c3476ab4fb Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Sun, 16 Jul 2023 22:05:48 -0700 Subject: [PATCH 5/6] build: ignore include and extern from clang --- .clang-format-ignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .clang-format-ignore diff --git a/.clang-format-ignore b/.clang-format-ignore new file mode 100644 index 000000000..1ddcdadce --- /dev/null +++ b/.clang-format-ignore @@ -0,0 +1,3 @@ +#ignore third party +./extern/* +./include/* From 53b39566ced75f2ead4d600fe9235d953df8a4ec Mon Sep 17 00:00:00 2001 From: alandtse Date: Mon, 17 Jul 2023 05:06:36 +0000 Subject: [PATCH 6/6] =?UTF-8?q?style:=20=F0=9F=8E=A8=20apply=20clang-forma?= =?UTF-8?q?t=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComplexParallaxMaterials/CRPM.hlsli | 214 +- .../ComplexParallaxMaterials.hlsli | 4 +- .../GrassCollision/GrassCollision.hlsli | 18 +- features/Grass Lighting/Shaders/RunGrass.hlsl | 445 ++-- .../Shaders/ScreenSpaceShadows/FilterCS.hlsl | 130 +- .../ScreenSpaceShadows/RaymarchCS.hlsl | 170 +- .../ScreenSpaceShadows/ShadowsPS.hlsli | 38 +- .../Shaders/DistantTree.hlsl | 156 +- .../Shaders/WaterBlending/WaterBlending.hlsli | 4 +- package/Shaders/BloodSplatter.hlsl | 52 +- package/Shaders/Common/Color.hlsl | 8 +- package/Shaders/Common/FrameBuffer.hlsl | 30 +- package/Shaders/DistantTree.hlsl | 84 +- package/Shaders/Effect.hlsl | 446 ++-- package/Shaders/Lighting.hlsl | 2026 ++++++++--------- package/Shaders/Particle.hlsl | 141 +- package/Shaders/RunGrass.hlsl | 128 +- package/Shaders/Sky.hlsl | 141 +- package/Shaders/Water.hlsl | 530 +++-- src/Buffer.h | 2 +- src/Feature.cpp | 2 +- src/Features/ExtendedMaterials.h | 7 +- src/Features/GrassLighting.h | 1 - src/Features/WaterBlending.h | 3 +- src/ShaderCache.cpp | 18 +- src/ShaderCache.h | 2 +- src/State.cpp | 2 +- src/State.h | 2 - src/Util.cpp | 2 +- 29 files changed, 2337 insertions(+), 2469 deletions(-) diff --git a/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli b/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli index 111a6227e..851396948 100644 --- a/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli +++ b/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli @@ -8,7 +8,7 @@ float linearstep(float edge0, float edge1, float x) { - return saturate((x - edge0) / (edge1 - edge0)); + return saturate((x - edge0) / (edge1 - edge0)); } float GetMipLevel(float2 coords, Texture2D tex) @@ -21,15 +21,15 @@ float GetMipLevel(float2 coords, Texture2D tex) float2 dxSize = ddx(texCoordsPerSize); float2 dySize = ddy(texCoordsPerSize); - + // Find min of change in u and v across quad: compute du and dv magnitude across quad float2 dTexCoords = dxSize * dxSize + dySize * dySize; // Standard mipmapping uses max here - float minTexCoordDelta = max( dTexCoords.x, dTexCoords.y ); + float minTexCoordDelta = max(dTexCoords.x, dTexCoords.y); // Compute the current mip level (* 0.5 is effectively computing a square root before ) - float mipLevel = max( 0.5 * log2( minTexCoordDelta ), 0 ); + float mipLevel = max(0.5 * log2(minTexCoordDelta), 0); return mipLevel; } @@ -39,7 +39,7 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v #else float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 viewDir, float3x3 tbn, Texture2D tex, SamplerState texSampler, uint channel) #endif -{ +{ #if defined(ENVMAP) // Cannot shift alpha tested geometry if (perPassParallax[0].CullingMode == 0) @@ -47,7 +47,7 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v #endif float3 viewDirTS = mul(viewDir, tbn).xyz; - + distance /= (float)perPassParallax[0].MaxDistance; float nearQuality = linearstep(0.0, perPassParallax[0].CRPMRange, distance); @@ -58,15 +58,13 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v float minHeight = maxHeight / 2; float2 output; - if (nearBlendToMid < 1.0) - { - float heightCorrectionScale = ((-1.0*viewDirTS.z)+2.0); + if (nearBlendToMid < 1.0) { + float heightCorrectionScale = ((-1.0 * viewDirTS.z) + 2.0); uint numSteps; #if defined(PARALLAX) float quality = 1.0 - nearQuality; - if (perPassParallax[0].EnableHighQuality) - { + if (perPassParallax[0].EnableHighQuality) { numSteps = round(lerp(4, 32, quality)); numSteps = clamp((numSteps + 3) & ~0x03, 4, 32); } else { @@ -75,165 +73,156 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v } #else mipLevel++; -#if defined(LANDSCAPE) +# if defined(LANDSCAPE) float quality = min(1.0 - nearQuality, pow(saturate(blend), 0.5)); - if (perPassParallax[0].EnableHighQuality) - { + if (perPassParallax[0].EnableHighQuality) { numSteps = round(lerp(4, 16, quality)); numSteps = clamp((numSteps + 3) & ~0x03, 4, 16); } else { numSteps = round(lerp(4, 8, quality)); numSteps = clamp((numSteps + 3) & ~0x03, 4, 8); } -#else - if (perPassParallax[0].EnableHighQuality) - { +# else + if (perPassParallax[0].EnableHighQuality) { numSteps = round(lerp(4, 16, 1.0 - nearQuality)); numSteps = clamp((numSteps + 3) & ~0x03, 4, 16); } else { numSteps = round(lerp(4, 8, 1.0 - nearQuality)); numSteps = clamp((numSteps + 3) & ~0x03, 4, 8); } -#endif +# endif #endif float stepSize = 1.0 / ((float)numSteps + 1.0); - - float2 offsetPerStep = viewDirTS.xy * float2(maxHeight,maxHeight) * stepSize.xx; - float2 prevOffset = viewDirTS.xy * float2(minHeight,minHeight) + coords.xy; + + float2 offsetPerStep = viewDirTS.xy * float2(maxHeight, maxHeight) * stepSize.xx; + float2 prevOffset = viewDirTS.xy * float2(minHeight, minHeight) + coords.xy; float prevBound = 1.0; - + uint numStepsTemp = numSteps; - [loop] - while(numSteps > 0) - { - float4 currentOffset[2]; - currentOffset[0] = prevOffset.xyxy - float4(1,1,2,2) * offsetPerStep.xyxy; - currentOffset[1] = prevOffset.xyxy - float4(3,3,4,4) * offsetPerStep.xyxy; - float4 currentBound = prevBound.xxxx - float4(1,2,3,4) * stepSize; - - float4 currHeight; - currHeight.x = tex.SampleLevel(texSampler, currentOffset[0].xy, mipLevel)[channel]; - currHeight.y = tex.SampleLevel(texSampler, currentOffset[0].zw, mipLevel)[channel]; - currHeight.z = tex.SampleLevel(texSampler, currentOffset[1].xy, mipLevel)[channel]; + [loop] while (numSteps > 0) + { + float4 currentOffset[2]; + currentOffset[0] = prevOffset.xyxy - float4(1, 1, 2, 2) * offsetPerStep.xyxy; + currentOffset[1] = prevOffset.xyxy - float4(3, 3, 4, 4) * offsetPerStep.xyxy; + float4 currentBound = prevBound.xxxx - float4(1, 2, 3, 4) * stepSize; + + float4 currHeight; + currHeight.x = tex.SampleLevel(texSampler, currentOffset[0].xy, mipLevel)[channel]; + currHeight.y = tex.SampleLevel(texSampler, currentOffset[0].zw, mipLevel)[channel]; + currHeight.z = tex.SampleLevel(texSampler, currentOffset[1].xy, mipLevel)[channel]; currHeight.w = tex.SampleLevel(texSampler, currentOffset[1].zw, mipLevel)[channel]; currHeight.xyzw -= 0.5; - currHeight.xyzw = heightCorrectionScale* currHeight.xyzw + 0.5; + currHeight.xyzw = heightCorrectionScale * currHeight.xyzw + 0.5; - bool4 testResult = currHeight >= currentBound; - [branch] - if (any(testResult)) - { + bool4 testResult = currHeight >= currentBound; + [branch] if (any(testResult)) + { float2 outOffset = 0; float outBound = 0; - [flatten] - if(testResult.w){ + [flatten] if (testResult.w) + { outOffset = currentOffset[1].xy; outBound = currentBound.z; } - [flatten] - if(testResult.z){ + [flatten] if (testResult.z) + { outOffset = currentOffset[0].zw; outBound = currentBound.y; } - [flatten] - if(testResult.y){ + [flatten] if (testResult.y) + { outOffset = currentOffset[0].xy; outBound = currentBound.x; } - [flatten] - if(testResult.x){ + [flatten] if (testResult.x) + { outOffset = prevOffset; outBound = prevBound; - } + } prevOffset = outOffset; prevBound = outBound; - break; - } + break; + } - prevOffset = currentOffset[1].zw; + prevOffset = currentOffset[1].zw; prevBound = currentBound.w; - numSteps -= 4; + numSteps -= 4; } - numSteps = numStepsTemp; + numSteps = numStepsTemp; stepSize /= (float)numSteps; - offsetPerStep /= (float)numSteps; + offsetPerStep /= (float)numSteps; float prevHeight = 1.0; float2 pt1 = 0; float2 pt2 = 0; - [loop] - while(numSteps > 0) - { - float4 currentOffset[2]; - currentOffset[0] = prevOffset.xyxy - float4(1,1,2,2) * offsetPerStep.xyxy; - currentOffset[1] = prevOffset.xyxy - float4(3,3,4,4) * offsetPerStep.xyxy; - float4 currentBound = prevBound.xxxx - float4(1,2,3,4) * stepSize; - - float4 currHeight; - currHeight.x = tex.SampleLevel(texSampler, currentOffset[0].xy, mipLevel)[channel]; - currHeight.y = tex.SampleLevel(texSampler, currentOffset[0].zw, mipLevel)[channel]; - currHeight.z = tex.SampleLevel(texSampler, currentOffset[1].xy, mipLevel)[channel]; + [loop] while (numSteps > 0) + { + float4 currentOffset[2]; + currentOffset[0] = prevOffset.xyxy - float4(1, 1, 2, 2) * offsetPerStep.xyxy; + currentOffset[1] = prevOffset.xyxy - float4(3, 3, 4, 4) * offsetPerStep.xyxy; + float4 currentBound = prevBound.xxxx - float4(1, 2, 3, 4) * stepSize; + + float4 currHeight; + currHeight.x = tex.SampleLevel(texSampler, currentOffset[0].xy, mipLevel)[channel]; + currHeight.y = tex.SampleLevel(texSampler, currentOffset[0].zw, mipLevel)[channel]; + currHeight.z = tex.SampleLevel(texSampler, currentOffset[1].xy, mipLevel)[channel]; currHeight.w = tex.SampleLevel(texSampler, currentOffset[1].zw, mipLevel)[channel]; currHeight.xyzw -= 0.5; - currHeight.xyzw = heightCorrectionScale* currHeight.xyzw + 0.5; - - bool4 testResult = currHeight >= currentBound; - [branch] - if (any(testResult)) - { - [flatten] - if(testResult.w){ + currHeight.xyzw = heightCorrectionScale * currHeight.xyzw + 0.5; + + bool4 testResult = currHeight >= currentBound; + [branch] if (any(testResult)) + { + [flatten] if (testResult.w) + { pt1 = float2(currentBound.w, currHeight.w); pt2 = float2(currentBound.z, currHeight.z); } - [flatten] - if(testResult.z){ + [flatten] if (testResult.z) + { pt1 = float2(currentBound.z, currHeight.z); pt2 = float2(currentBound.y, currHeight.y); } - [flatten] - if(testResult.y){ + [flatten] if (testResult.y) + { pt1 = float2(currentBound.y, currHeight.y); pt2 = float2(currentBound.x, currHeight.x); } - [flatten] - if(testResult.x){ + [flatten] if (testResult.x) + { pt1 = float2(currentBound.x, currHeight.x); pt2 = float2(prevBound, prevHeight); - } - break; - } + } + break; + } - prevOffset = currentOffset[1].zw; + prevOffset = currentOffset[1].zw; prevBound = currentBound.w; - prevHeight = currHeight.w; - numSteps -= 4; + prevHeight = currHeight.w; + numSteps -= 4; } - if (perPassParallax[0].EnableHighQuality) - { + if (perPassParallax[0].EnableHighQuality) { float delta2 = pt2.x - pt2.y; float delta1 = pt1.x - pt1.y; - float denominator = delta2-delta1; + float denominator = delta2 - delta1; float parallaxAmount = 0.0; - if(denominator==0.0){ - parallaxAmount=0.0; - } - else - { + if (denominator == 0.0) { + parallaxAmount = 0.0; + } else { parallaxAmount = (pt1.x * delta2 - pt2.x * delta1) / denominator; } - + float offset = (1.0 - parallaxAmount) * -maxHeight + minHeight; output = viewDirTS.xy * offset + coords.xy; } else { @@ -241,18 +230,14 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v output = viewDirTS.xy * offset + coords.xy; } - if (nearBlendToMid > 0.0) - { + if (nearBlendToMid > 0.0) { float height = tex.Sample(texSampler, coords.xy)[channel]; height = height * maxHeight - minHeight; - output = lerp( output, viewDirTS.xy * height.xx + coords.xy, nearBlendToMid); + output = lerp(output, viewDirTS.xy * height.xx + coords.xy, nearBlendToMid); } - } - else if (midBlendToFar < 1.0 ) - { + } else if (midBlendToFar < 1.0) { float height = tex.Sample(texSampler, coords.xy)[channel]; - if ( midBlendToFar > 0.0 ) - { + if (midBlendToFar > 0.0) { maxHeight *= (1 - midBlendToFar); minHeight *= (1 - midBlendToFar); } @@ -272,12 +257,11 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v // Only uses 1 sample vs the 8 in the original paper's example, which makes this effect very scaleable at the cost of small details float GetParallaxSoftShadowMultiplier(float2 coords, float mipLevel, float3 L, float sh0, Texture2D tex, SamplerState texSampler, uint channel, float quality) { - if (quality > 0.0f) - { + if (quality > 0.0f) { const float height = 0.05; const float2 rayDir = L.xy * height; - - const float h0 = 1.0 - sh0; + + const float h0 = 1.0 - sh0; const float h = 1.0 - tex.SampleLevel(texSampler, coords + rayDir * 0.5, mipLevel)[channel]; // Compare the difference between the two heights to see if the height blocks it @@ -293,19 +277,19 @@ float GetParallaxSoftShadowMultiplier(float2 coords, float mipLevel, float3 L, f float GetParallaxSoftShadowMultiplierTerrain(PS_INPUT input, float2 coords[6], float mipLevel[6], float3 L, float sh0[6], float quality) { float occlusion = 0.0; - + if (input.LandBlendWeights1.x > 0) - occlusion += GetParallaxSoftShadowMultiplier(coords[0], mipLevel[0], L, sh0[0], TexColorSampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.x; + occlusion += GetParallaxSoftShadowMultiplier(coords[0], mipLevel[0], L, sh0[0], TexColorSampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.x; if (input.LandBlendWeights1.y > 0) - occlusion += GetParallaxSoftShadowMultiplier(coords[1], mipLevel[1], L, sh0[1], TexLandColor2Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.y; + occlusion += GetParallaxSoftShadowMultiplier(coords[1], mipLevel[1], L, sh0[1], TexLandColor2Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.y; if (input.LandBlendWeights1.z > 0) - occlusion += GetParallaxSoftShadowMultiplier(coords[2], mipLevel[2], L, sh0[2], TexLandColor3Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.z; + occlusion += GetParallaxSoftShadowMultiplier(coords[2], mipLevel[2], L, sh0[2], TexLandColor3Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.z; if (input.LandBlendWeights1.w > 0) - occlusion += GetParallaxSoftShadowMultiplier(coords[3], mipLevel[3], L, sh0[3], TexLandColor4Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.w; + occlusion += GetParallaxSoftShadowMultiplier(coords[3], mipLevel[3], L, sh0[3], TexLandColor4Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights1.w; if (input.LandBlendWeights2.x > 0) - occlusion += GetParallaxSoftShadowMultiplier(coords[4], mipLevel[4], L, sh0[4], TexLandColor5Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights2.x; + occlusion += GetParallaxSoftShadowMultiplier(coords[4], mipLevel[4], L, sh0[4], TexLandColor5Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights2.x; if (input.LandBlendWeights2.y > 0) - occlusion += GetParallaxSoftShadowMultiplier(coords[5], mipLevel[5], L, sh0[5], TexLandColor6Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights2.y; - return saturate(occlusion); // Blend weights seem to go greater than 1.0 sometimes + occlusion += GetParallaxSoftShadowMultiplier(coords[5], mipLevel[5], L, sh0[5], TexLandColor6Sampler, SampTerrainParallaxSampler, 3, quality) * input.LandBlendWeights2.y; + return saturate(occlusion); // Blend weights seem to go greater than 1.0 sometimes } #endif diff --git a/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli b/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli index 67c2b862e..214669bc7 100644 --- a/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli +++ b/features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli @@ -6,9 +6,9 @@ struct PerPassParallax bool EnableComplexMaterial; bool EnableParallax; - bool EnableTerrainParallax; + bool EnableTerrainParallax; bool EnableHighQuality; - + uint MaxDistance; float CRPMRange; float BlendRange; diff --git a/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli b/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli index 658400601..8f8f8420d 100644 --- a/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli +++ b/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli @@ -3,7 +3,7 @@ cbuffer GrassCollisionPerFrame : register(b5) { float3 boundCentre; float boundRadius; - bool EnableGrassCollision; + bool EnableGrassCollision; float RadiusMultiplier; float DisplacementMultiplier; } @@ -17,37 +17,35 @@ struct StructuredCollision StructuredBuffer collisions : register(t0); float3 GetDisplacedPosition(float3 position, float alpha) -{ +{ float3 worldPosition = mul(World, float4(position, 1)).xyz; float3 displacement = 0; // Player bound culling { float dist = distance(boundCentre, worldPosition); - if (dist > boundRadius) - { + if (dist > boundRadius) { return 0; } } - if (EnableGrassCollision){ + if (EnableGrassCollision) { uint counter = 0; uint collision_count, dummy; collisions.GetDimensions(collision_count, dummy); - for (uint collision_index = 0; collision_index < collision_count; collision_index++) - { + for (uint collision_index = 0; collision_index < collision_count; collision_index++) { StructuredCollision collision = collisions[collision_index]; float dist = distance(collision.centre, worldPosition); float power = smoothstep(collision.radius, 0.0, dist); float3 direction = worldPosition - collision.centre; - direction.y = 0; // stops expanding/stretching + direction.y = 0; // stops expanding/stretching direction = normalize(direction); float3 shift = power * direction; - shift.z -= power; // bias downwards + shift.z -= power; // bias downwards displacement += shift.xyz; } } - + return displacement * saturate(alpha * alpha * 5) * DisplacementMultiplier; } diff --git a/features/Grass Lighting/Shaders/RunGrass.hlsl b/features/Grass Lighting/Shaders/RunGrass.hlsl index bc141c1e9..7b8ce8377 100644 --- a/features/Grass Lighting/Shaders/RunGrass.hlsl +++ b/features/Grass Lighting/Shaders/RunGrass.hlsl @@ -1,142 +1,140 @@ struct VS_INPUT { - float4 Position : POSITION0; - float2 TexCoord : TEXCOORD0; - float4 Normal : NORMAL0; - float4 Color : COLOR0; - float4 InstanceData1 : TEXCOORD4; - float4 InstanceData2 : TEXCOORD5; - float4 InstanceData3 : TEXCOORD6; - float4 InstanceData4 : TEXCOORD7; + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD0; + float4 Normal : NORMAL0; + float4 Color : COLOR0; + float4 InstanceData1 : TEXCOORD4; + float4 InstanceData2 : TEXCOORD5; + float4 InstanceData3 : TEXCOORD6; + float4 InstanceData4 : TEXCOORD7; #ifdef VR - uint InstanceID: SV_INSTANCEID; -#endif // VR - + uint InstanceID : SV_INSTANCEID; +#endif // VR }; struct VS_OUTPUT { - float4 HPosition : SV_POSITION0; - float4 VertexColor : COLOR0; - float3 TexCoord : TEXCOORD0; - float3 ViewSpacePosition : + float4 HPosition : SV_POSITION0; + float4 VertexColor : COLOR0; + float3 TexCoord : TEXCOORD0; + float3 ViewSpacePosition : #if !defined(VR) - TEXCOORD1; + TEXCOORD1; #else - TEXCOORD2; -#endif // !VR + TEXCOORD2; +#endif // !VR #if defined(RENDER_DEPTH) - float2 Depth : -#if !defined(VR) - TEXCOORD2; -#else - TEXCOORD3; -#endif // !VR -#endif // RENDER_DEPTH - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; + float2 Depth : +# if !defined(VR) + TEXCOORD2; +# else + TEXCOORD3; +# endif // !VR +#endif // RENDER_DEPTH + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; #if !defined(VR) - float3 ViewDirectionVec : POSITION3; -#endif // !VR - float3 VertexNormal : POSITION4; + float3 ViewDirectionVec : POSITION3; +#endif // !VR + float3 VertexNormal : POSITION4; #ifdef VR float ClipDistance : SV_ClipDistance0; - float CullDistance : SV_CullDistance0; -#endif // !VR + float CullDistance : SV_CullDistance0; +#endif // !VR }; // Constant Buffers (Flat and VR) -cbuffer PerGeometry : register( +cbuffer PerGeometry : register( #ifdef VSHADER - b2 + b2 #else - b3 + b3 #endif -) + ) { #if !defined(VR) - row_major float4x4 WorldViewProj : packoffset(c0); - row_major float4x4 WorldView : packoffset(c4); - row_major float4x4 World : packoffset(c8); - row_major float4x4 PreviousWorld : packoffset(c12); - float4 FogNearColor : packoffset(c16); - float3 WindVector : packoffset(c17); - float WindTimer : packoffset(c17.w); - float3 DirLightDirection : packoffset(c18); - float PreviousWindTimer : packoffset(c18.w); - float3 DirLightColor : packoffset(c19); - float AlphaParam1 : packoffset(c19.w); - float3 AmbientColor : packoffset(c20); - float AlphaParam2 : packoffset(c20.w); - float3 ScaleMask : packoffset(c21); - float ShadowClampValue : packoffset(c21.w); + row_major float4x4 WorldViewProj : packoffset(c0); + row_major float4x4 WorldView : packoffset(c4); + row_major float4x4 World : packoffset(c8); + row_major float4x4 PreviousWorld : packoffset(c12); + float4 FogNearColor : packoffset(c16); + float3 WindVector : packoffset(c17); + float WindTimer : packoffset(c17.w); + float3 DirLightDirection : packoffset(c18); + float PreviousWindTimer : packoffset(c18.w); + float3 DirLightColor : packoffset(c19); + float AlphaParam1 : packoffset(c19.w); + float3 AmbientColor : packoffset(c20); + float AlphaParam2 : packoffset(c20.w); + float3 ScaleMask : packoffset(c21); + float ShadowClampValue : packoffset(c21.w); #else - float4 cb2[32] : packoffset(c0); - float4 FogNearColor : packoffset(c32); - float3 WindVector : packoffset(c33); - float WindTimer : packoffset(c33.w); - float3 DirLightDirection : packoffset(c34); - float PreviousWindTimer : packoffset(c34.w); - float3 DirLightColor : packoffset(c35); - float AlphaParam1 : packoffset(c35.w); - float3 AmbientColor : packoffset(c36); - float AlphaParam2 : packoffset(c36.w); - float3 ScaleMask : packoffset(c37); - float ShadowClampValue : packoffset(c37.w); -#endif // !VR + float4 cb2[32] : packoffset(c0); + float4 FogNearColor : packoffset(c32); + float3 WindVector : packoffset(c33); + float WindTimer : packoffset(c33.w); + float3 DirLightDirection : packoffset(c34); + float PreviousWindTimer : packoffset(c34.w); + float3 DirLightColor : packoffset(c35); + float AlphaParam1 : packoffset(c35.w); + float3 AmbientColor : packoffset(c36); + float AlphaParam2 : packoffset(c36.w); + float3 ScaleMask : packoffset(c37); + float ShadowClampValue : packoffset(c37.w); +#endif // !VR } cbuffer PerFrame : register( #ifdef VSHADER - b3 + b3 #else - b4 + b4 #endif -) + ) { #if !defined(VR) - float4 EyePosition; + float4 EyePosition; #else - float4 EyePosition[2]; -#endif //!VR - row_major float3x4 DirectionalAmbient; - float SunlightScale; - float Glossiness; - float SpecularStrength; - float SubsurfaceScatteringAmount; - bool EnableDirLightFix; - bool EnablePointLights; + float4 EyePosition[2]; +#endif //!VR + row_major float3x4 DirectionalAmbient; + float SunlightScale; + float Glossiness; + float SpecularStrength; + float SubsurfaceScatteringAmount; + bool EnableDirLightFix; + bool EnablePointLights; float pad[2]; } #ifdef VSHADER -#ifdef GRASS_COLLISION - #include "GrassCollision\\GrassCollision.hlsli" -#endif +# ifdef GRASS_COLLISION +# include "GrassCollision\\GrassCollision.hlsli" +# endif -cbuffer cb7 : register(b7) -{ - float4 cb7[1]; +cbuffer cb7 : register(b7) +{ + float4 cb7[1]; } -cbuffer cb8 : register(b8) +cbuffer cb8 : register(b8) { - float4 cb8[240]; + float4 cb8[240]; } -#ifdef VR +# ifdef VR cbuffer cb13 : register(b13) { - float4 cb13[3]; + float4 cb13[3]; } -#endif // VR +# endif // VR -#define M_PI 3.1415925 // PI -#define M_2PI 6.283185 // PI * 2 +# define M_PI 3.1415925 // PI +# define M_2PI 6.283185 // PI * 2 -const static float4x4 M_IdentityMatrix = -{ +const static float4x4 M_IdentityMatrix = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, @@ -153,7 +151,7 @@ float4 GetMSPosition(VS_INPUT input, float windTimer, float3x3 world3x3) float windTmp1 = sin(M_PI * windAngleSin); float windTmp2 = sin(M_2PI * windAngleSin); float windPower = WindVector.z * (((windTmp1 + windTmp2) * 0.3 + windTmp3) * - (0.5 * (input.Color.w * input.Color.w))); + (0.5 * (input.Color.w * input.Color.w))); float3 inputPosition = input.Position.xyz * (input.InstanceData4.yyy * ScaleMask.xyz + float3(1, 1, 1)); float3 InstanceData4 = mul(world3x3, inputPosition); @@ -171,8 +169,8 @@ VS_OUTPUT main(VS_INPUT input) { VS_OUTPUT vsout; -#ifdef VR -/* +# ifdef VR + /* https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/htmlpresent This section looks like this code Matrix WorldToEyeClipMatrix[2] // computed from SDK @@ -185,7 +183,7 @@ clipPos.x *= 0.5; // shrink to half of the screen clipPos.x += EyeOffsetScale[eyeIndex] * clipPos.w; // scoot left or right. clipPositionOut = clipPos */ - float4 r0,r1,r2,r3,r4,r5,r6; + float4 r0, r1, r2, r3, r4, r5, r6; uint4 bitmask, uiDest; float4 fDest; @@ -195,37 +193,37 @@ clipPositionOut = clipPos r0.x = (uint)r0.x; r0.z = (uint)r0.x << 2; r0.y = (uint)r0.x << 2; -#endif // VR +# endif // VR float3x3 world3x3 = float3x3(input.InstanceData2.xyz, input.InstanceData3.xyz, float3(input.InstanceData4.x, input.InstanceData2.w, input.InstanceData3.w)); float4 msPosition = GetMSPosition(input, WindTimer, world3x3); -#ifdef GRASS_COLLISION +# ifdef GRASS_COLLISION float3 displacement = GetDisplacedPosition(msPosition.xyz, input.Color.w); msPosition.xyz += displacement; -#endif +# endif -#if !defined(VR) +# if !defined(VR) float4 projSpacePosition = mul(WorldViewProj, msPosition); vsout.HPosition = projSpacePosition; -#else +# else float4 projSpacePosition; - projSpacePosition.x = dot(cb2[r0.z+0].xyzw, msPosition.xyzw); - projSpacePosition.y = dot(cb2[r0.z+1].xyzw, msPosition.xyzw); - projSpacePosition.z = dot(cb2[r0.z+2].xyzw, msPosition.xyzw); - projSpacePosition.w = dot(cb2[r0.z+3].xyzw, msPosition.xyzw); -#endif // !VR + projSpacePosition.x = dot(cb2[r0.z + 0].xyzw, msPosition.xyzw); + projSpacePosition.y = dot(cb2[r0.z + 1].xyzw, msPosition.xyzw); + projSpacePosition.z = dot(cb2[r0.z + 2].xyzw, msPosition.xyzw); + projSpacePosition.w = dot(cb2[r0.z + 3].xyzw, msPosition.xyzw); +# endif // !VR -#if defined(RENDER_DEPTH) +# if defined(RENDER_DEPTH) vsout.Depth = projSpacePosition.zw; -#endif // RENDER_DEPTH +# endif // RENDER_DEPTH -#ifdef VR +# ifdef VR float3 instanceNormal = float3(input.InstanceData2.z, input.InstanceData3.zw); float dirLightAngle = dot(DirLightDirection.xyz, instanceNormal); float3 diffuseMultiplier = input.InstanceData1.www * input.Color.xyz * saturate(dirLightAngle.xxx); -#endif // VR +# endif // VR float perInstanceFade = dot(cb8[(asuint(cb7[0].x) >> 2)].xyzw, M_IdentityMatrix[(asint(cb7[0].x) & 3)].xyzw); float distanceFade = 1 - saturate((length(projSpacePosition.xyz) - AlphaParam1) / AlphaParam2); @@ -236,37 +234,37 @@ clipPositionOut = clipPos vsout.TexCoord.xy = input.TexCoord.xy; vsout.TexCoord.z = FogNearColor.w; -#if !defined(VR) +# if !defined(VR) vsout.ViewSpacePosition = mul(WorldView, msPosition).xyz; vsout.WorldPosition = mul(World, msPosition); -#else - vsout.ViewSpacePosition.x = dot(cb2[r0.z+8].xyzw, msPosition.xyzw); - vsout.ViewSpacePosition.y = dot(cb2[r0.z+9].xyzw, msPosition.xyzw); - vsout.ViewSpacePosition.z = dot(cb2[r0.z+10].xyzw, msPosition.xyzw); +# else + vsout.ViewSpacePosition.x = dot(cb2[r0.z + 8].xyzw, msPosition.xyzw); + vsout.ViewSpacePosition.y = dot(cb2[r0.z + 9].xyzw, msPosition.xyzw); + vsout.ViewSpacePosition.z = dot(cb2[r0.z + 10].xyzw, msPosition.xyzw); - vsout.WorldPosition.x = dot(cb2[r0.z+16].xyzw, msPosition.xyzw); - vsout.WorldPosition.y = dot(cb2[r0.z+17].xyzw, msPosition.xyzw); - vsout.WorldPosition.z = dot(cb2[r0.z+18].xyzw, msPosition.xyzw); - vsout.WorldPosition.w = dot(cb2[r0.z+19].xyzw, msPosition.xyzw); -#endif // !VR + vsout.WorldPosition.x = dot(cb2[r0.z + 16].xyzw, msPosition.xyzw); + vsout.WorldPosition.y = dot(cb2[r0.z + 17].xyzw, msPosition.xyzw); + vsout.WorldPosition.z = dot(cb2[r0.z + 18].xyzw, msPosition.xyzw); + vsout.WorldPosition.w = dot(cb2[r0.z + 19].xyzw, msPosition.xyzw); +# endif // !VR float4 previousMsPosition = GetMSPosition(input, PreviousWindTimer, world3x3); -#ifdef GRASS_COLLISION +# ifdef GRASS_COLLISION previousMsPosition.xyz += displacement; -#endif // GRASS_COLLISION +# endif // GRASS_COLLISION -#if !defined(VR) +# if !defined(VR) vsout.PreviousWorldPosition = mul(PreviousWorld, previousMsPosition); vsout.ViewDirectionVec.xyz = EyePosition.xyz - vsout.WorldPosition.xyz; -#else - vsout.PreviousWorldPosition.x = dot(cb2[r0.z+24].xyzw, previousMsPosition.xyzw); - vsout.PreviousWorldPosition.y = dot(cb2[r0.z+25].xyzw, previousMsPosition.xyzw); - vsout.PreviousWorldPosition.z = dot(cb2[r0.z+26].xyzw, previousMsPosition.xyzw); - vsout.PreviousWorldPosition.w = dot(cb2[r0.z+27].xyzw, previousMsPosition.xyzw); +# else + vsout.PreviousWorldPosition.x = dot(cb2[r0.z + 24].xyzw, previousMsPosition.xyzw); + vsout.PreviousWorldPosition.y = dot(cb2[r0.z + 25].xyzw, previousMsPosition.xyzw); + vsout.PreviousWorldPosition.z = dot(cb2[r0.z + 26].xyzw, previousMsPosition.xyzw); + vsout.PreviousWorldPosition.w = dot(cb2[r0.z + 27].xyzw, previousMsPosition.xyzw); -/* + /* https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/htmlpresent This section looks like this code Matrix WorldToEyeClipMatrix[2] // computed from SDK @@ -280,22 +278,22 @@ clipPos.x += EyeOffsetScale[eyeIndex] * clipPos.w; // scoot left or right. clipPositionOut = clipPos */ if (0 < cb13[0].y) { - r0.yz = dot(projSpacePosition, cb13[r0.x+1].xyzw); + r0.yz = dot(projSpacePosition, cb13[r0.x + 1].xyzw); } else { - r0.yz = float2(1,1); + r0.yz = float2(1, 1); } r0.w = 2 + -cb13[0].y; - r0.x = dot(cb13[0].zw, M_IdentityMatrix[r0.x+0].xy); - r0.xw = r0.xw * projSpacePosition.wx; - r0.x = cb13[0].y * r0.x; + r0.x = dot(cb13[0].zw, M_IdentityMatrix[r0.x + 0].xy); + r0.xw = r0.xw * projSpacePosition.wx; + r0.x = cb13[0].y * r0.x; vsout.HPosition.x = r0.w * 0.5 + r0.x; vsout.HPosition.yzw = projSpacePosition.yzw; vsout.ClipDistance.x = r0.z; - vsout.CullDistance.x = r0.y; -#endif // !VR + vsout.CullDistance.x = r0.y; +# endif // !VR // Vertex normal needs to be transformed to world-space for lighting calculations. float3 vertexNormal = input.Normal.xyz * 2.0 - 1.0; @@ -304,32 +302,30 @@ clipPositionOut = clipPos return vsout; } -#endif // VSHADER +#endif // VSHADER typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { #if defined(RENDER_DEPTH) - float4 PS : SV_Target0; + float4 PS : SV_Target0; #else - float4 Albedo : SV_Target0; - float2 MotionVectors : SV_Target1; - float4 Normal : SV_Target2; -#endif // RENDER_DEPTH + float4 Albedo : SV_Target0; + float2 MotionVectors : SV_Target1; + float4 Normal : SV_Target2; +#endif // RENDER_DEPTH }; #ifdef PSHADER -SamplerState SampBaseSampler : register(s0); -SamplerState SampShadowMaskSampler : register(s1); - -Texture2D TexBaseSampler : register(t0); -Texture2D TexShadowMaskSampler : register(t1); +SamplerState SampBaseSampler : register(s0); +SamplerState SampShadowMaskSampler : register(s1); +Texture2D TexBaseSampler : register(t0); +Texture2D TexShadowMaskSampler : register(t1); - -#ifdef VR -struct PerEye +# ifdef VR +struct PerEye { row_major float4x4 ScreenProj; row_major float4x4 PreviousScreenProj; @@ -337,55 +333,55 @@ struct PerEye cbuffer cb0 : register(b0) { - float4 cb0[10]; + float4 cb0[10]; } -#endif // VR +# endif // VR cbuffer PS_cb12 : register(b12) { -#if !defined(VR) - row_major float4x4 ViewMatrix : packoffset(c0); - row_major float4x4 ProjMatrix : packoffset(c4); - row_major float4x4 ViewProjMatrix : packoffset(c8); - row_major float4x4 ViewProjMatrixUnjittered : packoffset(c12); - row_major float4x4 PreviousViewProjMatrixUnjittered : packoffset(c16); - row_major float4x4 InvProjMatrixUnjittered : packoffset(c20); - row_major float4x4 ProjMatrixUnjittered : packoffset(c24); - row_major float4x4 InvViewMatrix : packoffset(c28); - row_major float4x4 InvViewProjMatrix : packoffset(c32); - row_major float4x4 InvProjMatrix : packoffset(c36); - float4 CurrentPosAdjust : packoffset(c40); - float4 PreviousPosAdjust : packoffset(c41); - // notes: FirstPersonY seems 1.0 regardless of third/first person, could be LE legacy stuff - float4 GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW : packoffset(c42); - float4 DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW : packoffset(c43); - float4 DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW : packoffset(c44); -#else +# if !defined(VR) + row_major float4x4 ViewMatrix : packoffset(c0); + row_major float4x4 ProjMatrix : packoffset(c4); + row_major float4x4 ViewProjMatrix : packoffset(c8); + row_major float4x4 ViewProjMatrixUnjittered : packoffset(c12); + row_major float4x4 PreviousViewProjMatrixUnjittered : packoffset(c16); + row_major float4x4 InvProjMatrixUnjittered : packoffset(c20); + row_major float4x4 ProjMatrixUnjittered : packoffset(c24); + row_major float4x4 InvViewMatrix : packoffset(c28); + row_major float4x4 InvViewProjMatrix : packoffset(c32); + row_major float4x4 InvProjMatrix : packoffset(c36); + float4 CurrentPosAdjust : packoffset(c40); + float4 PreviousPosAdjust : packoffset(c41); + // notes: FirstPersonY seems 1.0 regardless of third/first person, could be LE legacy stuff + float4 GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW : packoffset(c42); + float4 DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW : packoffset(c43); + float4 DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW : packoffset(c44); +# else //VR is float4 PerFrame[87]; VR original used for eye position in PerFrame[86].x float4 cb12[87]; -#endif // !VR +# endif // !VR } -cbuffer AlphaTestRefCB : register( -#if !defined(VR) - b11 -#else - b13 -#endif // !VR -) -{ - float AlphaTestRefRS : packoffset(c0); +cbuffer AlphaTestRefCB : register( +# if !defined(VR) + b11 +# else + b13 +# endif // !VR + ) +{ + float AlphaTestRefRS : packoffset(c0); } struct StructuredLight { - float4 color; - float4 positionWS[2]; - float radius; - bool shadow; - float mask; - bool active; + float4 color; + float4 positionWS[2]; + float radius; + bool shadow; + float mask; + bool active; }; StructuredBuffer lights : register(t17); @@ -434,11 +430,12 @@ float3x3 CalculateTBN(float3 N, float3 p, float2 uv) return float3x3(T * invmax, B * invmax, N); } -#if defined(SCREEN_SPACE_SHADOWS) - #include "ScreenSpaceShadows/ShadowsPS.hlsli" -#endif +# if defined(SCREEN_SPACE_SHADOWS) +# include "ScreenSpaceShadows/ShadowsPS.hlsli" +# endif -PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) +PS_OUTPUT main(PS_INPUT input, bool frontFace + : SV_IsFrontFace) { PS_OUTPUT psout; @@ -451,25 +448,22 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) float4 baseColor; if (complex) { baseColor = TexBaseSampler.Sample(SampBaseSampler, float2(input.TexCoord.x, input.TexCoord.y * 0.5)); - } - else - { + } else { baseColor = TexBaseSampler.Sample(SampBaseSampler, input.TexCoord.xy); } -#if defined(RENDER_DEPTH) || defined(DO_ALPHA_TEST) +# if defined(RENDER_DEPTH) || defined(DO_ALPHA_TEST) float diffuseAlpha = input.VertexColor.w * baseColor.w; - if ((diffuseAlpha - AlphaTestRefRS) < 0) - { + if ((diffuseAlpha - AlphaTestRefRS) < 0) { discard; } -#endif // RENDER_DEPTH | DO_ALPHA_TEST +# endif // RENDER_DEPTH | DO_ALPHA_TEST -#if defined(RENDER_DEPTH) +# if defined(RENDER_DEPTH) // Depth psout.PS.xyz = input.Depth.xxx / input.Depth.yyy; psout.PS.w = diffuseAlpha; -#else +# else float4 specColor = complex ? TexBaseSampler.Sample(SampBaseSampler, float2(input.TexCoord.x, 0.5 + input.TexCoord.y * 0.5)) : 1; float4 shadowColor = TexShadowMaskSampler.Load(int3(input.HPosition.xy, 0)); @@ -481,33 +475,34 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) // psout.Albedo.xyz = input.TexCoord.zzz * (diffuseColor * diffuseFraction + ambientColor); // psout.Albedo.w = 1; -#if !defined(VR) +# if !defined(VR) float4 screenPosition = mul(ViewProjMatrixUnjittered, input.WorldPosition); screenPosition.xy = screenPosition.xy / screenPosition.ww; float4 previousScreenPosition = mul(PreviousViewProjMatrixUnjittered, input.PreviousWorldPosition); previousScreenPosition.xy = previousScreenPosition.xy / previousScreenPosition.ww; uint eyeIndex = 0; -#else +# else float stereoUV = input.HPosition.x * cb0[2].xy + cb0[2].zw; stereoUV = stereoUV * cb12[86].x; uint eyeIndex = (stereoUV >= 0.5) ? 1 : 0; uint eyeOffset = eyeIndex; uint bitmask; - bitmask = ((~(-1 << 1)) << 2) & 0xffffffff; eyeOffset = (((uint)eyeOffset<< 2) & bitmask) | ((uint)0 & ~bitmask); + bitmask = ((~(-1 << 1)) << 2) & 0xffffffff; + eyeOffset = (((uint)eyeOffset << 2) & bitmask) | ((uint)0 & ~bitmask); float3 screenPosition; - screenPosition.x = dot(cb12[eyeOffset+24].xyzw, input.WorldPosition); - screenPosition.y = dot(cb12[eyeOffset+25].xyzw, input.WorldPosition); - screenPosition.z = dot(cb12[eyeOffset+27].xyzw, input.WorldPosition); + screenPosition.x = dot(cb12[eyeOffset + 24].xyzw, input.WorldPosition); + screenPosition.y = dot(cb12[eyeOffset + 25].xyzw, input.WorldPosition); + screenPosition.z = dot(cb12[eyeOffset + 27].xyzw, input.WorldPosition); screenPosition.xy = screenPosition.xy / screenPosition.zz; float3 previousScreenPosition; - previousScreenPosition.x = dot(cb12[eyeOffset+32].xyzw, input.PreviousWorldPosition); - previousScreenPosition.y = dot(cb12[eyeOffset+33].xyzw, input.PreviousWorldPosition); - previousScreenPosition.z = dot(cb12[eyeOffset+35].xyzw, input.PreviousWorldPosition); + previousScreenPosition.x = dot(cb12[eyeOffset + 32].xyzw, input.PreviousWorldPosition); + previousScreenPosition.y = dot(cb12[eyeOffset + 33].xyzw, input.PreviousWorldPosition); + previousScreenPosition.z = dot(cb12[eyeOffset + 35].xyzw, input.PreviousWorldPosition); previousScreenPosition.xy = previousScreenPosition.xy / previousScreenPosition.zz; -#endif // !VR +# endif // !VR float2 screenMotionVector = float2(-0.5, 0.5) * (screenPosition.xy - previousScreenPosition.xy); @@ -520,42 +515,41 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) psout.Normal.xy = float2(0.5, 0.5) + normal.xy / normalScale; psout.Normal.zw = float2(0, 0); -#if !defined(VR) +# if !defined(VR) float3 viewDirection = normalize(input.ViewDirectionVec); -#else +# else float3 viewDirection = normalize(-input.WorldPosition.xyz); -#endif // !VR +# endif // !VR float3 worldNormal = normalize(input.VertexNormal); // Swaps direction of the backfaces otherwise they seem to get lit from the wrong direction. - if (!frontFace) worldNormal.xyz = -worldNormal.xyz; + if (!frontFace) + worldNormal.xyz = -worldNormal.xyz; if (complex) { float3 normalColor = float4(TransformNormal(specColor.xyz), 1); // Inverting x as well as y seems to look more correct. normalColor.xy = -normalColor.xy; - // world-space -> tangent-space -> world-space. + // world-space -> tangent-space -> world-space. // This is because we don't have pre-computed tangents. -#if !defined(VR) +# if !defined(VR) worldNormal.xyz = normalize(mul(normalColor.xyz, CalculateTBN(worldNormal.xyz, -viewDirection, input.TexCoord.xy))); -#else +# else worldNormal.xyz = normalize(mul(normalColor.xyz, CalculateTBN(worldNormal.xyz, input.WorldPosition.xyz, input.TexCoord.xy))); -#endif // !VR +# endif // !VR } float3 dirLightColor = DirLightColor.xyz; - if (EnableDirLightFix) - { + if (EnableDirLightFix) { dirLightColor *= SunlightScale; } dirLightColor *= shadowColor.x; -#if defined(SCREEN_SPACE_SHADOWS) +# if defined(SCREEN_SPACE_SHADOWS) float dirLightSShadow = PrepassScreenSpaceShadows(input.WorldPosition); dirLightColor *= dirLightSShadow; -#endif // !SCREEN_SPACE_SHADOWS - +# endif // !SCREEN_SPACE_SHADOWS float3 diffuseColor = 0; float3 specularColor = 0; @@ -586,8 +580,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) if (EnablePointLights) { uint light_count, dummy; lights.GetDimensions(light_count, dummy); - for (uint light_index = 0; light_index < light_count; light_index++) - { + for (uint light_index = 0; light_index < light_count; light_index++) { StructuredLight light = lights[light_index]; if (light.active) { float3 lightDirection = light.positionWS[eyeIndex].xyz - input.WorldPosition.xyz; @@ -636,7 +629,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) psout.Albedo.xyz = color; psout.Albedo.w = 1; -#endif // RENDER_DEPTH +# endif // RENDER_DEPTH return psout; } -#endif // PSHADER \ No newline at end of file +#endif // PSHADER \ No newline at end of file diff --git a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/FilterCS.hlsl b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/FilterCS.hlsl index 1fe66ed28..46b711fe3 100644 --- a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/FilterCS.hlsl +++ b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/FilterCS.hlsl @@ -32,51 +32,50 @@ RWTexture2D OcclusionRW : register(u0); SamplerState LinearSampler : register(s0); Texture2D DepthTexture : register(t0); -Texture2D OcclusionTexture: register(t1); +Texture2D OcclusionTexture : register(t1); cbuffer PerFrame : register(b0) { - float2 BufferDim; - float2 RcpBufferDim; - float4x4 ProjMatrix; - float4x4 InvProjMatrix; - float4 DynamicRes; - float4 InvDirLightDirectionVS; - float ShadowDistance; - uint MaxSamples; - float FarDistanceScale; - float FarThicknessScale; - float FarHardness; - float NearDistance; - float NearThickness; - float NearHardness; - float BlurRadius; - float BlurDropoff; + float2 BufferDim; + float2 RcpBufferDim; + float4x4 ProjMatrix; + float4x4 InvProjMatrix; + float4 DynamicRes; + float4 InvDirLightDirectionVS; + float ShadowDistance; + uint MaxSamples; + float FarDistanceScale; + float FarThicknessScale; + float FarHardness; + float NearDistance; + float NearThickness; + float NearHardness; + float BlurRadius; + float BlurDropoff; }; float GetDepth(float2 uv) { - return DepthTexture.SampleLevel(LinearSampler, uv, 0).r; + return DepthTexture.SampleLevel(LinearSampler, uv, 0).r; } // Inverse project UV + raw depth into the view space. float3 InverseProjectUVZ(float2 uv, float z) { - uv.y = 1 - uv.y; - float4 cp = float4(float3(uv, z) * 2 - 1, 1); - float4 vp = mul(InvProjMatrix, cp); - return float3(vp.xy, vp.z) / vp.w; + uv.y = 1 - uv.y; + float4 cp = float4(float3(uv, z) * 2 - 1, 1); + float4 vp = mul(InvProjMatrix, cp); + return float3(vp.xy, vp.z) / vp.w; } float3 InverseProjectUV(float2 uv) { - return InverseProjectUVZ(uv, GetDepth(uv)); + return InverseProjectUVZ(uv, GetDepth(uv)); } #define cKernelSize 12 -static const float BlurWeights[cKernelSize] = -{ +static const float BlurWeights[cKernelSize] = { 0.057424882f, 0.058107773f, 0.061460144f, @@ -90,65 +89,62 @@ static const float BlurWeights[cKernelSize] = 0.058107773f, 0.057424882f }; - -static const float2 BlurOffsets[cKernelSize] = -{ - float2(-6.0f , -6.0f ), - float2(-5.0f , -5.0f ), - float2(-4.0f , -4.0f ), - float2(-3.0f , -3.0f ), - float2(-2.0f , -2.0f ), - float2(-1.0f , -1.0f ), - float2( 1.0f , 1.0f ), - float2( 2.0f , 2.0f ), - float2( 3.0f , 3.0f ), - float2( 4.0f , 4.0f ), - float2( 5.0f , 5.0f ), - float2( 6.0f , 6.0f ) + +static const float2 BlurOffsets[cKernelSize] = { + float2(-6.0f, -6.0f), + float2(-5.0f, -5.0f), + float2(-4.0f, -4.0f), + float2(-3.0f, -3.0f), + float2(-2.0f, -2.0f), + float2(-1.0f, -1.0f), + float2(1.0f, 1.0f), + float2(2.0f, 2.0f), + float2(3.0f, 3.0f), + float2(4.0f, 4.0f), + float2(5.0f, 5.0f), + float2(6.0f, 6.0f) }; -[numthreads( 32, 32, 1 )] -void main( uint3 DTid : SV_DispatchThreadID ) -{ +[numthreads(32, 32, 1)] void main(uint3 DTid + : SV_DispatchThreadID) { #if defined(HORIZONTAL) - float2 OffsetMask = float2(1.0f, 0.0f); + float2 OffsetMask = float2(1.0f, 0.0f); #elif defined(VERTICAL) - float2 OffsetMask = float2(0.0f, 1.0f); + float2 OffsetMask = float2(0.0f, 1.0f); #else - #error "Must define an axis!" +# error "Must define an axis!" #endif - float2 TexCoord = (DTid.xy + 0.5) * RcpBufferDim; + float2 TexCoord = (DTid.xy + 0.5) * RcpBufferDim; - float startDepth = GetDepth(TexCoord * 2); - if (startDepth >= 1) - return; + float startDepth = GetDepth(TexCoord * 2); + if (startDepth >= 1) + return; - float WeightSum = 0.114725602f; + float WeightSum = 0.114725602f; float color1 = OcclusionTexture.SampleLevel(LinearSampler, TexCoord * 2, 0).r * WeightSum; - float depth1 = InverseProjectUVZ(TexCoord * 2, startDepth).z; + float depth1 = InverseProjectUVZ(TexCoord * 2, startDepth).z; - float depthDrop = depth1 * BlurDropoff; + float depthDrop = depth1 * BlurDropoff; - [unroll] - for (int i = 0; i < cKernelSize; i++) - { + [unroll] for (int i = 0; i < cKernelSize; i++) + { #if defined(HORIZONTAL) - float2 uv = TexCoord + (BlurOffsets[i] * OffsetMask * RcpBufferDim) * BlurRadius; + float2 uv = TexCoord + (BlurOffsets[i] * OffsetMask * RcpBufferDim) * BlurRadius; #elif defined(VERTICAL) - float2 uv = TexCoord + (BlurOffsets[i] * OffsetMask * RcpBufferDim / 2) * BlurRadius; + float2 uv = TexCoord + (BlurOffsets[i] * OffsetMask * RcpBufferDim / 2) * BlurRadius; #endif - float4 color2 = OcclusionTexture.SampleLevel(LinearSampler, uv * 2, 0).r; - float depth2 = InverseProjectUV(uv * 2).z; + float4 color2 = OcclusionTexture.SampleLevel(LinearSampler, uv * 2, 0).r; + float depth2 = InverseProjectUV(uv * 2).z; - // Depth-awareness - float awareness = saturate(depthDrop - abs(depth1 - depth2)); + // Depth-awareness + float awareness = saturate(depthDrop - abs(depth1 - depth2)); - color1 += BlurWeights[i] * color2 * awareness; - WeightSum += BlurWeights[i] * awareness; - } - color1 /= WeightSum; - OcclusionRW[DTid.xy] = color1; + color1 += BlurWeights[i] * color2 * awareness; + WeightSum += BlurWeights[i] * awareness; + } + color1 /= WeightSum; + OcclusionRW[DTid.xy] = color1; } \ No newline at end of file diff --git a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlsl b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlsl index e89e4cf20..9942bfb56 100644 --- a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlsl +++ b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlsl @@ -7,144 +7,142 @@ Texture2D ShadowTexture : register(t1); cbuffer PerFrame : register(b0) { - float2 BufferDim; - float2 RcpBufferDim; - float4x4 ProjMatrix; - float4x4 InvProjMatrix; - float4 DynamicRes; - float4 InvDirLightDirectionVS; - float ShadowDistance; - uint MaxSamples; - float FarDistanceScale; - float FarThicknessScale; - float FarHardness; - float NearDistance; - float NearThickness; - float NearHardness; - float BlurRadius; - float BlurDropoff; + float2 BufferDim; + float2 RcpBufferDim; + float4x4 ProjMatrix; + float4x4 InvProjMatrix; + float4 DynamicRes; + float4 InvDirLightDirectionVS; + float ShadowDistance; + uint MaxSamples; + float FarDistanceScale; + float FarThicknessScale; + float FarHardness; + float NearDistance; + float NearThickness; + float NearHardness; + float BlurRadius; + float BlurDropoff; }; -bool IsSaturated(float value) { return value == saturate(value); } +bool IsSaturated(float value) { return value == saturate(value); } bool IsSaturated(float2 value) { return IsSaturated(value.x) && IsSaturated(value.y); } // Get a raw depth from the depth buffer. float GetDepth(float2 uv) { - // effects like screen space shadows, can get artefacts if a point sampler is used - return DepthTexture.SampleLevel(LinearSampler, uv * DynamicRes.xy, 0).r; + // effects like screen space shadows, can get artefacts if a point sampler is used + return DepthTexture.SampleLevel(LinearSampler, uv * DynamicRes.xy, 0).r; } float2 ViewToUV(float3 x, bool is_position = true) { - float4 uv = mul(ProjMatrix, float4(x, (float)is_position)); - return (uv.xy / uv.w) * float2(0.5f, -0.5f) + 0.5f; + float4 uv = mul(ProjMatrix, float4(x, (float)is_position)); + return (uv.xy / uv.w) * float2(0.5f, -0.5f) + 0.5f; } // Inverse project UV + raw depth into the view space. float3 InverseProjectUVZ(float2 uv, float z) { - uv.y = 1 - uv.y; - float4 cp = float4(float3(uv, z) * 2 - 1, 1); - float4 vp = mul(InvProjMatrix, cp); - return float3(vp.xy, vp.z) / vp.w; + uv.y = 1 - uv.y; + float4 cp = float4(float3(uv, z) * 2 - 1, 1); + float4 vp = mul(InvProjMatrix, cp); + return float3(vp.xy, vp.z) / vp.w; } float3 InverseProjectUV(float2 uv) { - return InverseProjectUVZ(uv, GetDepth(uv)); + return InverseProjectUVZ(uv, GetDepth(uv)); } // https://www.shadertoy.com/view/Xt23zV float smoothbumpstep(float edge0, float edge1, float x) { - x = 1.0-abs(clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0)-.5)* 2.0; - return x * x * (3.0 - x - x); + x = 1.0 - abs(clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0) - .5) * 2.0; + return x * x * (3.0 - x - x); } // Derived from the interleaved gradient function from Jimenez 2014 http://goo.gl/eomGso float InterleavedGradientNoise(float2 uv) { - float3 magic = float3(0.06711056f, 0.00583715f, 52.9829189f); - return frac(magic.z * frac(dot(uv, magic.xy))); + float3 magic = float3(0.06711056f, 0.00583715f, 52.9829189f); + return frac(magic.z * frac(dot(uv, magic.xy))); } float ScreenSpaceShadowsUV(float2 texcoord, float3 lightDirectionVS) { - // Ignore the sky - float startDepth = GetDepth(texcoord); - if (startDepth >= 1) - return 1; + // Ignore the sky + float startDepth = GetDepth(texcoord); + if (startDepth >= 1) + return 1; - // Compute ray position in view-space - float3 rayPos = InverseProjectUVZ(texcoord, startDepth); - - // Blends effect variables between near, mid and far field - float blendFactorFar = smoothstep(ShadowDistance / 3, ShadowDistance / 2, rayPos.z); - float blendFactorMid = smoothbumpstep(0, ShadowDistance / 2, rayPos.z); + // Compute ray position in view-space + float3 rayPos = InverseProjectUVZ(texcoord, startDepth); - // Max shadow length, longer shadows are less accurate - float maxDistance = lerp(NearDistance, rayPos.z * FarDistanceScale, blendFactorFar); + // Blends effect variables between near, mid and far field + float blendFactorFar = smoothstep(ShadowDistance / 3, ShadowDistance / 2, rayPos.z); + float blendFactorMid = smoothbumpstep(0, ShadowDistance / 2, rayPos.z); - // Max ray steps, affects quality and performance - uint maxSteps = max(1, (uint)((float)MaxSamples * (1 - blendFactorMid))); + // Max shadow length, longer shadows are less accurate + float maxDistance = lerp(NearDistance, rayPos.z * FarDistanceScale, blendFactorFar); - // How far to move each sample each step - float stepLength = maxDistance / (float)maxSteps; + // Max ray steps, affects quality and performance + uint maxSteps = max(1, (uint)((float)MaxSamples * (1 - blendFactorMid))); - // Compute ray step - float3 rayStep = lightDirectionVS * stepLength; + // How far to move each sample each step + float stepLength = maxDistance / (float)maxSteps; - // Offset starting position with interleaved gradient noise - float offset = InterleavedGradientNoise(texcoord * BufferDim); - rayPos += rayStep * offset; + // Compute ray step + float3 rayStep = lightDirectionVS * stepLength; - float thickness = lerp(NearThickness, rayPos.z * FarThicknessScale, blendFactorFar); + // Offset starting position with interleaved gradient noise + float offset = InterleavedGradientNoise(texcoord * BufferDim); + rayPos += rayStep * offset; - // Accumulate samples - float shadow = 0.0f; - uint samples = 0; + float thickness = lerp(NearThickness, rayPos.z * FarThicknessScale, blendFactorFar); - float2 rayUV = 0.0f; - for (uint i = 0; i < maxSteps; i++) - { - samples++; + // Accumulate samples + float shadow = 0.0f; + uint samples = 0; - // Step the ray - rayPos += rayStep; - rayUV = ViewToUV(rayPos); + float2 rayUV = 0.0f; + for (uint i = 0; i < maxSteps; i++) { + samples++; - // Ensure the UV coordinates are inside the screen - if (!IsSaturated(rayUV)) - break; + // Step the ray + rayPos += rayStep; + rayUV = ViewToUV(rayPos); - // Compute the difference between the ray's and the camera's depth - float rayDepth = InverseProjectUV(rayUV).z; + // Ensure the UV coordinates are inside the screen + if (!IsSaturated(rayUV)) + break; - // Difference between the current ray distance and the marched light - float depthDelta = rayPos.z - rayDepth; + // Compute the difference between the ray's and the camera's depth + float rayDepth = InverseProjectUV(rayUV).z; - // Distant shadows simulate real shadows whereas near shadows are only intended for small objects - float rayShadow = depthDelta / thickness; + // Difference between the current ray distance and the marched light + float depthDelta = rayPos.z - rayDepth; - // Check if the depth difference is considered a shadow - if (rayShadow > 0.0f && rayShadow <= 1.0f) - shadow += rayShadow; - } + // Distant shadows simulate real shadows whereas near shadows are only intended for small objects + float rayShadow = depthDelta / thickness; - // Average samples - shadow /= samples; + // Check if the depth difference is considered a shadow + if (rayShadow > 0.0f && rayShadow <= 1.0f) + shadow += rayShadow; + } - // Intensity and sharpness of shadows - shadow *= lerp(NearHardness, FarHardness, blendFactorFar); + // Average samples + shadow /= samples; - // Convert to visibility - return 1 - saturate(shadow); + // Intensity and sharpness of shadows + shadow *= lerp(NearHardness, FarHardness, blendFactorFar); + + // Convert to visibility + return 1 - saturate(shadow); } -[numthreads( 32, 32, 1 )] -void main( uint3 DTid : SV_DispatchThreadID ) -{ - float2 TexCoord = (DTid.xy + 0.5) * RcpBufferDim * DynamicRes.zw; - OcclusionRW[DTid.xy] = ScreenSpaceShadowsUV(TexCoord, InvDirLightDirectionVS); +[numthreads(32, 32, 1)] void main(uint3 DTid + : SV_DispatchThreadID) { + float2 TexCoord = (DTid.xy + 0.5) * RcpBufferDim * DynamicRes.zw; + OcclusionRW[DTid.xy] = ScreenSpaceShadowsUV(TexCoord, InvDirLightDirectionVS); } \ No newline at end of file diff --git a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ShadowsPS.hlsli b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ShadowsPS.hlsli index 07311e3d5..21e2c8ea0 100644 --- a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ShadowsPS.hlsli +++ b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ShadowsPS.hlsli @@ -1,45 +1,45 @@ -cbuffer SSSData : register(b5) +cbuffer SSSData : register(b5) { - bool EnableSSS; - uint FrameCount; + bool EnableSSS; + uint FrameCount; }; -Texture2D TexDepthSampler : register(t20); -Texture2D TexOcclusionSampler : register(t21); +Texture2D TexDepthSampler : register(t20); +Texture2D TexOcclusionSampler : register(t21); #if defined(DEFSHADOW) - #define LinearSampler SampShadowMaskSampler +# define LinearSampler SampShadowMaskSampler #else - SamplerState LinearSampler : register(s14); +SamplerState LinearSampler : register(s14); #endif float3 WorldToView(float3 x, bool is_position = true) { - return mul(ViewMatrix, float4(x, (float)is_position)).xyz; + return mul(ViewMatrix, float4(x, (float)is_position)).xyz; } float2 ViewToUV(float3 x, bool is_position = true) { - float4 uv = mul(ProjMatrix, float4(x, (float)is_position)); - return (uv.xy / uv.w) * float2(0.5f, -0.5f) + 0.5f; + float4 uv = mul(ProjMatrix, float4(x, (float)is_position)); + return (uv.xy / uv.w) * float2(0.5f, -0.5f) + 0.5f; } float2 GetDynamicResolutionAdjustedScreenPosition(float2 uv) { - return uv * DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW.xy; + return uv * DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW.xy; } float PrepassScreenSpaceShadows(float3 positionWS) { #if defined(EYE) - return 1; + return 1; #else - if (EnableSSS){ - float2 texCoord = ViewToUV(WorldToView(positionWS)); - float2 coords = GetDynamicResolutionAdjustedScreenPosition(texCoord) / 2; - float shadow = TexOcclusionSampler.SampleLevel(LinearSampler, coords, 0); - return shadow; - } - return 1; + if (EnableSSS) { + float2 texCoord = ViewToUV(WorldToView(positionWS)); + float2 coords = GetDynamicResolutionAdjustedScreenPosition(texCoord) / 2; + float shadow = TexOcclusionSampler.SampleLevel(LinearSampler, coords, 0); + return shadow; + } + return 1; #endif } \ No newline at end of file diff --git a/features/Tree LOD Lighting/Shaders/DistantTree.hlsl b/features/Tree LOD Lighting/Shaders/DistantTree.hlsl index d622c7778..8d7cb2226 100644 --- a/features/Tree LOD Lighting/Shaders/DistantTree.hlsl +++ b/features/Tree LOD Lighting/Shaders/DistantTree.hlsl @@ -1,54 +1,54 @@ cbuffer PerFrame : register(b3) { - float4 EyePosition; - row_major float3x4 DirectionalAmbient; - float4 DirLightColor; - float4 DirLightDirection; - float DirLightScale; - bool ComplexAtlasTexture; - bool EnableComplexTreeLOD; - bool EnableDirLightFix; - float SubsurfaceScatteringAmount; - float FogDimmerAmount; + float4 EyePosition; + row_major float3x4 DirectionalAmbient; + float4 DirLightColor; + float4 DirLightDirection; + float DirLightScale; + bool ComplexAtlasTexture; + bool EnableComplexTreeLOD; + bool EnableDirLightFix; + float SubsurfaceScatteringAmount; + float FogDimmerAmount; float pad0; float pad1; } struct VS_INPUT { - float3 Position : POSITION0; - float2 TexCoord0 : TEXCOORD0; - float4 InstanceData1 : TEXCOORD4; - float4 InstanceData2 : TEXCOORD5; - float4 InstanceData3 : TEXCOORD6; // Unused - float4 InstanceData4 : TEXCOORD7; // Unused + float3 Position : POSITION0; + float2 TexCoord0 : TEXCOORD0; + float4 InstanceData1 : TEXCOORD4; + float4 InstanceData2 : TEXCOORD5; + float4 InstanceData3 : TEXCOORD6; // Unused + float4 InstanceData4 : TEXCOORD7; // Unused }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; - float3 TexCoord : TEXCOORD0; + float4 Position : SV_POSITION0; + float3 TexCoord : TEXCOORD0; #if defined(RENDER_DEPTH) - float4 Depth : TEXCOORD3; + float4 Depth : TEXCOORD3; #else - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; - float3 ViewDirectionVec : POSITION3; + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; + float3 ViewDirectionVec : POSITION3; #endif }; #ifdef VSHADER -cbuffer PerTechnique : register(b0) +cbuffer PerTechnique : register(b0) { - float4 FogParam : packoffset(c0); + float4 FogParam : packoffset(c0); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float4x4 WorldViewProj : packoffset(c0); - row_major float4x4 World : packoffset(c4); - row_major float4x4 PreviousWorld : packoffset(c8); + row_major float4x4 WorldViewProj : packoffset(c0); + row_major float4x4 World : packoffset(c4); + row_major float4x4 PreviousWorld : packoffset(c8); }; VS_OUTPUT main(VS_INPUT input) @@ -63,14 +63,14 @@ VS_OUTPUT main(VS_INPUT input) float4 finalModelPosition = float4(input.InstanceData1.xyz + adjustedModelPosition.xyz, 1.0); float4 viewPosition = mul(WorldViewProj, finalModelPosition); -#ifdef RENDER_DEPTH +# ifdef RENDER_DEPTH vsout.Depth.xy = viewPosition.zw; vsout.Depth.zw = input.InstanceData2.zw; -#else +# else vsout.WorldPosition = mul(World, finalModelPosition); vsout.PreviousWorldPosition = mul(PreviousWorld, finalModelPosition); vsout.ViewDirectionVec.xyz = EyePosition.xyz - vsout.WorldPosition.xyz; -#endif +# endif vsout.Position = viewPosition; vsout.TexCoord = float3(input.TexCoord0.xy, FogParam.z); @@ -83,42 +83,42 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { - float4 Albedo : SV_Target0; + float4 Albedo : SV_Target0; #if !defined(RENDER_DEPTH) - float2 MotionVector : SV_Target1; - float4 Normal : SV_Target2; + float2 MotionVector : SV_Target1; + float4 Normal : SV_Target2; #endif }; #ifdef PSHADER -SamplerState SampDiffuse : register(s0); +SamplerState SampDiffuse : register(s0); -Texture2D TexDiffuse : register(t0); +Texture2D TexDiffuse : register(t0); -cbuffer AlphaTestRefCB : register(b11) +cbuffer AlphaTestRefCB : register(b11) { - float AlphaTestRefRS : packoffset(c0); + float AlphaTestRefRS : packoffset(c0); } cbuffer PerFrame : register(b12) { - row_major float4x4 ViewMatrix : packoffset(c0); - row_major float4x4 ProjMatrix : packoffset(c4); - row_major float4x4 ViewProjMatrix : packoffset(c8); - row_major float4x4 ViewProjMatrixUnjittered : packoffset(c12); - row_major float4x4 PreviousViewProjMatrixUnjittered : packoffset(c16); - row_major float4x4 InvProjMatrixUnjittered : packoffset(c20); - row_major float4x4 ProjMatrixUnjittered : packoffset(c24); - row_major float4x4 InvViewMatrix : packoffset(c28); - row_major float4x4 InvViewProjMatrix : packoffset(c32); - row_major float4x4 InvProjMatrix : packoffset(c36); - float4 CurrentPosAdjust : packoffset(c40); - float4 PreviousPosAdjust : packoffset(c41); - // notes: FirstPersonY seems 1.0 regardless of third/first person, could be LE legacy stuff - float4 GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW : packoffset(c42); - float4 DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW : packoffset(c43); - float4 DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW : packoffset(c44); + row_major float4x4 ViewMatrix : packoffset(c0); + row_major float4x4 ProjMatrix : packoffset(c4); + row_major float4x4 ViewProjMatrix : packoffset(c8); + row_major float4x4 ViewProjMatrixUnjittered : packoffset(c12); + row_major float4x4 PreviousViewProjMatrixUnjittered : packoffset(c16); + row_major float4x4 InvProjMatrixUnjittered : packoffset(c20); + row_major float4x4 ProjMatrixUnjittered : packoffset(c24); + row_major float4x4 InvViewMatrix : packoffset(c28); + row_major float4x4 InvViewProjMatrix : packoffset(c32); + row_major float4x4 InvProjMatrix : packoffset(c36); + float4 CurrentPosAdjust : packoffset(c40); + float4 PreviousPosAdjust : packoffset(c41); + // notes: FirstPersonY seems 1.0 regardless of third/first person, could be LE legacy stuff + float4 GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW : packoffset(c42); + float4 DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW : packoffset(c43); + float4 DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW : packoffset(c44); } cbuffer PerTechnique : register(b0) { @@ -126,8 +126,7 @@ cbuffer PerTechnique : register(b0) float4 AmbientColor : packoffset(c1); }; -const static float DepthOffsets[16] = -{ +const static float DepthOffsets[16] = { 0.003921568, 0.533333361, 0.133333340, @@ -181,47 +180,45 @@ float3x3 CalculateTBN(float3 N, float3 p, float2 uv) return float3x3(T * invmax, B * invmax, N); } -Texture2D TexShadowMaskSampler : register(t17); +Texture2D TexShadowMaskSampler : register(t17); -#if defined(SCREEN_SPACE_SHADOWS) - #include "ScreenSpaceShadows/ShadowsPS.hlsli" -#endif +# if defined(SCREEN_SPACE_SHADOWS) +# include "ScreenSpaceShadows/ShadowsPS.hlsli" +# endif -PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) +PS_OUTPUT main(PS_INPUT input, bool frontFace + : SV_IsFrontFace) { PS_OUTPUT psout; -#if defined(RENDER_DEPTH) +# if defined(RENDER_DEPTH) uint2 temp = uint2(input.Position.xy); uint index = ((temp.x << 2) & 12) | (temp.y & 3); float depthOffset = 0.5 - DepthOffsets[index]; float depthModifier = (input.Depth.w * depthOffset) + input.Depth.z - 0.5; - if (depthModifier < 0) - { + if (depthModifier < 0) { discard; } float alpha = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy).w; - if ((alpha - AlphaTestRefRS) < 0) - { + if ((alpha - AlphaTestRefRS) < 0) { discard; } psout.Albedo.xyz = input.Depth.xxx / input.Depth.yyy; psout.Albedo.w = 0; -#else +# else float4 baseColor = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy); -#if defined(DO_ALPHA_TEST) - if ((baseColor.w - AlphaTestRefRS) < 0) - { +# if defined(DO_ALPHA_TEST) + if ((baseColor.w - AlphaTestRefRS) < 0) { discard; } -#endif +# endif float4 screenPosition = mul(ViewProjMatrixUnjittered, input.WorldPosition); screenPosition.xy = screenPosition.xy / screenPosition.ww; @@ -236,7 +233,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) float3 ddx = ddx_coarse(input.WorldPosition); float3 ddy = ddy_coarse(input.WorldPosition); float3 normal = normalize(cross(ddx, ddy)); - + float3 viewDirection = normalize(input.ViewDirectionVec); float3 worldNormal = normal; @@ -245,28 +242,27 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) normalColor = TransformNormal(normalColor); // Increases the strength of the normal to simulate more advanced lighting. normalColor.xy *= 2 + (8 * (1 - input.TexCoord.z)); - normalColor = normalize(normalColor); + normalColor = normalize(normalColor); // Inverting x as well as y seems to look more correct. normalColor.xy = -normalColor.xy; - // world-space -> tangent-space -> world-space. + // world-space -> tangent-space -> world-space. // This is because we don't have pre-computed tangents. worldNormal.xyz = normalize(mul(normalColor.xyz, CalculateTBN(worldNormal.xyz, -viewDirection, input.TexCoord.xy))); } float3 dirLightColor = DirLightColor.xyz; - if (EnableDirLightFix) - { + if (EnableDirLightFix) { dirLightColor *= DirLightScale; } float3 nsDirLightColor = dirLightColor; -#if defined(SCREEN_SPACE_SHADOWS) +# if defined(SCREEN_SPACE_SHADOWS) float dirLightSShadow = PrepassScreenSpaceShadows(input.WorldPosition); shadowColor *= dirLightSShadow; -#endif - +# endif + dirLightColor *= min(lerp(1, input.TexCoord.zzz, FogDimmerAmount), min(0.5, shadowColor)); float3 diffuseColor = 0; @@ -292,7 +288,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) float3 color = diffuseColor * baseColor.xyz; psout.Albedo.xyz = color; psout.Albedo.w = 1; -#endif +# endif return psout; } diff --git a/features/Water Blending/Shaders/WaterBlending/WaterBlending.hlsli b/features/Water Blending/Shaders/WaterBlending/WaterBlending.hlsli index c8dc49a2b..6d760806e 100644 --- a/features/Water Blending/Shaders/WaterBlending/WaterBlending.hlsli +++ b/features/Water Blending/Shaders/WaterBlending/WaterBlending.hlsli @@ -11,7 +11,7 @@ struct PerPassWaterBlending }; #if defined(WATER) -Texture2D SharedDepthTex : register(t31); +Texture2D SharedDepthTex : register(t31); #endif -StructuredBuffer perPassWaterBlending: register(t32); \ No newline at end of file +StructuredBuffer perPassWaterBlending : register(t32); \ No newline at end of file diff --git a/package/Shaders/BloodSplatter.hlsl b/package/Shaders/BloodSplatter.hlsl index b224a7967..31fed90de 100644 --- a/package/Shaders/BloodSplatter.hlsl +++ b/package/Shaders/BloodSplatter.hlsl @@ -1,25 +1,25 @@ struct VS_INPUT { - float4 Position : POSITION0; - float2 TexCoord : TEXCOORD0; + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD0; }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; - float3 TexCoordColor : TEXCOORD0; + float4 Position : SV_POSITION0; + float3 TexCoordColor : TEXCOORD0; #if defined(SPLATTER) - float2 TexCoordAlpha : TEXCOORD1; + float2 TexCoordAlpha : TEXCOORD1; #endif }; #ifdef VSHADER -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float4x4 WorldViewProj : packoffset(c0); - float4 LightLoc : packoffset(c4); - float Ctrl : packoffset(c5); // fBloodSplatterFlareOffsetScale + row_major float4x4 WorldViewProj : packoffset(c0); + float4 LightLoc : packoffset(c4); + float Ctrl : packoffset(c5); // fBloodSplatterFlareOffsetScale }; VS_OUTPUT main(VS_INPUT input) @@ -29,11 +29,11 @@ VS_OUTPUT main(VS_INPUT input) float4 projectedPosition = mul(WorldViewProj, float4(input.Position.xy, 0.0, 1.0)); float2 lightOffset = (-LightLoc.xy + projectedPosition.xy) * LightLoc.ww; -#if defined(SPLATTER) +# if defined(SPLATTER) vsout.TexCoordAlpha = -(lightOffset.xy * float2(-0.5, 0.5)) + input.TexCoord; -#elif defined(FLARE) +# elif defined(FLARE) projectedPosition.xy += lightOffset * Ctrl.xx; -#endif +# endif vsout.Position = projectedPosition; vsout.TexCoordColor = float3(input.TexCoord, input.Position.z); @@ -46,30 +46,30 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { - float4 Color : SV_Target0; + float4 Color : SV_Target0; }; #ifdef PSHADER -SamplerState SampBloodColor : register(s0); -SamplerState SampBloodAlpha : register(s1); -SamplerState SampFlareColor : register(s2); -SamplerState SampFlareHDR : register(s3); +SamplerState SampBloodColor : register(s0); +SamplerState SampBloodAlpha : register(s1); +SamplerState SampFlareColor : register(s2); +SamplerState SampFlareHDR : register(s3); -Texture2D TexBloodColor : register(t0); -Texture2D TexBloodAlpha : register(t1); -Texture2D TexFlareColor : register(t2); -Texture2D TexFlareHDR : register(t3); +Texture2D TexBloodColor : register(t0); +Texture2D TexBloodAlpha : register(t1); +Texture2D TexFlareColor : register(t2); +Texture2D TexFlareHDR : register(t3); -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - float Alpha : packoffset(c0); + float Alpha : packoffset(c0); }; PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; -#if defined(SPLATTER) +# if defined(SPLATTER) float3 bloodAplha = TexBloodAlpha.Sample(SampBloodAlpha, input.TexCoordAlpha.xy).xyz; float4 bloodColor = TexBloodColor.Sample(SampBloodColor, input.TexCoordColor.xy).xyzw; @@ -78,12 +78,12 @@ PS_OUTPUT main(PS_INPUT input) float3 adjustedBloodAlpha = colorMul * (-adjustedBloodColor.xyz + bloodAplha); psout.Color = float4(adjustedBloodAlpha + adjustedBloodColor, 1.0); -#elif defined(FLARE) +# elif defined(FLARE) float flareMult = TexFlareColor.Sample(SampFlareColor, input.TexCoordColor.xy).x; float4 colorHDR = TexFlareHDR.Sample(SampFlareHDR, input.TexCoordColor.xy).xyzw; psout.Color = (colorHDR * flareMult) * Alpha; -#endif +# endif return psout; } diff --git a/package/Shaders/Common/Color.hlsl b/package/Shaders/Common/Color.hlsl index 4ef5aa458..d25ae2032 100644 --- a/package/Shaders/Common/Color.hlsl +++ b/package/Shaders/Common/Color.hlsl @@ -1,16 +1,16 @@ static float GammaCorrectionValue = 2.2; float RGBToLuminance(float3 color) -{ +{ return dot(color, float3(0.2125, 0.7154, 0.0721)); } float RGBToLuminanceAlternative(float3 color) -{ - return dot(color, float3(0.3, 0.59, 0.11)); +{ + return dot(color, float3(0.3, 0.59, 0.11)); } float RGBToLuminance2(float3 color) -{ +{ return dot(color, float3(0.299, 0.587, 0.114)); } diff --git a/package/Shaders/Common/FrameBuffer.hlsl b/package/Shaders/Common/FrameBuffer.hlsl index 6992c7570..356fd4393 100644 --- a/package/Shaders/Common/FrameBuffer.hlsl +++ b/package/Shaders/Common/FrameBuffer.hlsl @@ -1,20 +1,20 @@ -cbuffer PerFrame : register(b12) +cbuffer PerFrame : register(b12) { - row_major float4x4 CameraView : packoffset(c0); - row_major float4x4 CameraProj : packoffset(c4); - row_major float4x4 CameraViewProj : packoffset(c8); - row_major float4x4 CameraViewProjUnjittered : packoffset(c12); + row_major float4x4 CameraView : packoffset(c0); + row_major float4x4 CameraProj : packoffset(c4); + row_major float4x4 CameraViewProj : packoffset(c8); + row_major float4x4 CameraViewProjUnjittered : packoffset(c12); row_major float4x4 CameraPreviousViewProjUnjittered : packoffset(c16); - row_major float4x4 CameraProjUnjittered : packoffset(c20); - row_major float4x4 CameraProjUnjitteredInverse : packoffset(c24); - row_major float4x4 CameraViewInverse : packoffset(c28); - row_major float4x4 CameraViewProjInverse : packoffset(c32); - row_major float4x4 CameraProjInverse : packoffset(c36); - float4 CameraPosAdjust : packoffset(c40); - float4 CameraPreviousPosAdjust : packoffset(c41); // fDRClampOffset in w - float4 FrameParams : packoffset(c42); // inverse fGamma in x, some flags in yzw - float4 DynamicResolutionParams1 : packoffset(c43); // fDynamicResolutionWidthRatio in x, fDynamicResolutionHeightRatio in y, fDynamicResolutionPreviousWidthRatio in z, fDynamicResolutionPreviousHeightRatio in w - float4 DynamicResolutionParams2 : packoffset(c44); // inverse fDynamicResolutionWidthRatio in x, inverse fDynamicResolutionHeightRatio in y, fDynamicResolutionWidthRatio - fDRClampOffset in z, fDynamicResolutionPreviousWidthRatio - fDRClampOffset in w + row_major float4x4 CameraProjUnjittered : packoffset(c20); + row_major float4x4 CameraProjUnjitteredInverse : packoffset(c24); + row_major float4x4 CameraViewInverse : packoffset(c28); + row_major float4x4 CameraViewProjInverse : packoffset(c32); + row_major float4x4 CameraProjInverse : packoffset(c36); + float4 CameraPosAdjust : packoffset(c40); + float4 CameraPreviousPosAdjust : packoffset(c41); // fDRClampOffset in w + float4 FrameParams : packoffset(c42); // inverse fGamma in x, some flags in yzw + float4 DynamicResolutionParams1 : packoffset(c43); // fDynamicResolutionWidthRatio in x, fDynamicResolutionHeightRatio in y, fDynamicResolutionPreviousWidthRatio in z, fDynamicResolutionPreviousHeightRatio in w + float4 DynamicResolutionParams2 : packoffset(c44); // inverse fDynamicResolutionWidthRatio in x, inverse fDynamicResolutionHeightRatio in y, fDynamicResolutionWidthRatio - fDRClampOffset in z, fDynamicResolutionPreviousWidthRatio - fDRClampOffset in w } float2 GetDynamicResolutionAdjustedScreenPosition(float2 screenPosition) diff --git a/package/Shaders/DistantTree.hlsl b/package/Shaders/DistantTree.hlsl index 5089b6fa5..ec8351556 100644 --- a/package/Shaders/DistantTree.hlsl +++ b/package/Shaders/DistantTree.hlsl @@ -1,37 +1,37 @@ struct VS_INPUT { - float3 Position : POSITION0; - float2 TexCoord0 : TEXCOORD0; - float4 InstanceData1 : TEXCOORD4; - float4 InstanceData2 : TEXCOORD5; - float4 InstanceData3 : TEXCOORD6; - float4 InstanceData4 : TEXCOORD7; + float3 Position : POSITION0; + float2 TexCoord0 : TEXCOORD0; + float4 InstanceData1 : TEXCOORD4; + float4 InstanceData2 : TEXCOORD5; + float4 InstanceData3 : TEXCOORD6; + float4 InstanceData4 : TEXCOORD7; }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; - float3 TexCoord : TEXCOORD0; + float4 Position : SV_POSITION0; + float3 TexCoord : TEXCOORD0; #if defined(RENDER_DEPTH) - float4 Depth : TEXCOORD3; + float4 Depth : TEXCOORD3; #else - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; #endif }; #ifdef VSHADER -cbuffer PerTechnique : register(b0) +cbuffer PerTechnique : register(b0) { - float4 FogParam : packoffset(c0); + float4 FogParam : packoffset(c0); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float4x4 WorldViewProj : packoffset(c0); - row_major float4x4 World : packoffset(c4); - row_major float4x4 PreviousWorld : packoffset(c8); + row_major float4x4 WorldViewProj : packoffset(c0); + row_major float4x4 World : packoffset(c4); + row_major float4x4 PreviousWorld : packoffset(c8); }; VS_OUTPUT main(VS_INPUT input) @@ -46,13 +46,13 @@ VS_OUTPUT main(VS_INPUT input) float4 finalModelPosition = float4(input.InstanceData1.xyz + adjustedModelPosition.xyz, 1.0); float4 viewPosition = mul(WorldViewProj, finalModelPosition); -#ifdef RENDER_DEPTH +# ifdef RENDER_DEPTH vsout.Depth.xy = viewPosition.zw; vsout.Depth.zw = input.InstanceData2.zw; -#else +# else vsout.WorldPosition = mul(World, finalModelPosition); vsout.PreviousWorldPosition = mul(PreviousWorld, finalModelPosition); -#endif +# endif vsout.Position = viewPosition; vsout.TexCoord = float3(input.TexCoord0.xy, FogParam.z); @@ -65,29 +65,29 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { - float4 Albedo : SV_Target0; + float4 Albedo : SV_Target0; #if !defined(RENDER_DEPTH) - float2 MotionVector : SV_Target1; - float4 Normal : SV_Target2; + float2 MotionVector : SV_Target1; + float4 Normal : SV_Target2; #endif }; #ifdef PSHADER -SamplerState SampDiffuse : register(s0); +SamplerState SampDiffuse : register(s0); -Texture2D TexDiffuse : register(t0); +Texture2D TexDiffuse : register(t0); -cbuffer AlphaTestRefCB : register(b11) +cbuffer AlphaTestRefCB : register(b11) { - float AlphaTestRefRS : packoffset(c0); + float AlphaTestRefRS : packoffset(c0); } -cbuffer PerFrame : register(b12) +cbuffer PerFrame : register(b12) { - float4 UnknownPerFrame1[12] : packoffset(c0); - row_major float4x4 ScreenProj : packoffset(c12); - row_major float4x4 PreviousScreenProj : packoffset(c16); + float4 UnknownPerFrame1[12] : packoffset(c0); + row_major float4x4 ScreenProj : packoffset(c12); + row_major float4x4 PreviousScreenProj : packoffset(c16); } cbuffer PerTechnique : register(b0) @@ -96,8 +96,7 @@ cbuffer PerTechnique : register(b0) float4 AmbientColor : packoffset(c1); }; -const static float DepthOffsets[16] = -{ +const static float DepthOffsets[16] = { 0.003921568, 0.533333361, 0.133333340, @@ -120,36 +119,33 @@ PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; -#if defined(RENDER_DEPTH) +# if defined(RENDER_DEPTH) uint2 temp = uint2(input.Position.xy); uint index = ((temp.x << 2) & 12) | (temp.y & 3); float depthOffset = 0.5 - DepthOffsets[index]; float depthModifier = (input.Depth.w * depthOffset) + input.Depth.z - 0.5; - if (depthModifier < 0) - { + if (depthModifier < 0) { discard; } float alpha = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy).w; - if ((alpha - AlphaTestRefRS) < 0) - { + if ((alpha - AlphaTestRefRS) < 0) { discard; } psout.Albedo.xyz = input.Depth.xxx / input.Depth.yyy; psout.Albedo.w = 0; -#else +# else float4 baseColor = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy); -#if defined(DO_ALPHA_TEST) - if ((baseColor.w - AlphaTestRefRS) < 0) - { +# if defined(DO_ALPHA_TEST) + if ((baseColor.w - AlphaTestRefRS) < 0) { discard; } -#endif +# endif psout.Albedo = float4((input.TexCoord.zzz * DiffuseColor.xyz + AmbientColor.xyz) * baseColor.xyz, 1.0); @@ -162,7 +158,7 @@ PS_OUTPUT main(PS_INPUT input) psout.MotionVector = screenMotionVector; psout.Normal = float4(0.5, 0.5, 0, 0); -#endif +# endif return psout; } diff --git a/package/Shaders/Effect.hlsl b/package/Shaders/Effect.hlsl index 3e455a6c7..d37ff13ae 100644 --- a/package/Shaders/Effect.hlsl +++ b/package/Shaders/Effect.hlsl @@ -1,131 +1,131 @@ struct VS_INPUT { - float4 Position : POSITION0; + float4 Position : POSITION0; #if defined(TEXCOORD) -#if defined(STRIP_PARTICLES) - float3 -#else +# if defined(STRIP_PARTICLES) + float3 +# else float2 -#endif - TexCoord0 : TEXCOORD0; +# endif + TexCoord0 : TEXCOORD0; #endif #if defined(NORMALS) || defined(MOTIONVECTORS_NORMALS) - float4 Normal : NORMAL0; + float4 Normal : NORMAL0; #endif #if defined(BINORMAL_TANGENT) - float4 Bitangent : BINORMAL0; + float4 Bitangent : BINORMAL0; #endif #if defined(VC) - float4 Color : COLOR0; + float4 Color : COLOR0; #endif #if defined(SKINNED) - float4 BoneWeights : BLENDWEIGHT0; - float4 BoneIndices : BLENDINDICES0; + float4 BoneWeights : BLENDWEIGHT0; + float4 BoneIndices : BLENDINDICES0; #endif }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; - float4 TexCoord0 : TEXCOORD0; + float4 Position : SV_POSITION0; + float4 TexCoord0 : TEXCOORD0; #if defined(VC) - float4 Color : COLOR0; + float4 Color : COLOR0; #endif #if !defined(MOTIONVECTORS_NORMALS) - float4 FogParam : COLOR1; + float4 FogParam : COLOR1; #endif #if defined(MOTIONVECTORS_NORMALS) && defined(MEMBRANE) && !defined(SKINNED) && defined(NORMALS) - float3 ScreenSpaceNormal : TEXCOORD1; + float3 ScreenSpaceNormal : TEXCOORD1; #elif (defined(MEMBRANE) && (defined(SKINNED) || defined(NORMALS))) || (defined(PROJECTED_UV) && defined(NORMALS)) - float3 TBN0 : TEXCOORD1; + float3 TBN0 : TEXCOORD1; #endif #if defined(MEMBRANE) && (defined(SKINNED) || defined(NORMALS)) - float FogAlpha : TEXCOORD5; + float FogAlpha : TEXCOORD5; #endif #if (defined(MEMBRANE) && defined(SKINNED) && !defined(NORMALS)) || (defined(PROJECTED_UV) && defined(NORMALS) && !defined(MEMBRANE)) - float3 TBN1 : TEXCOORD2; + float3 TBN1 : TEXCOORD2; #endif #if (defined(MEMBRANE) && defined(SKINNED) && !defined(NORMALS)) - float3 TBN2 : TEXCOORD3; + float3 TBN2 : TEXCOORD3; #endif #if defined(MEMBRANE) - float4 ViewVector : TEXCOORD4; + float4 ViewVector : TEXCOORD4; #endif #if defined(LIGHTING) - float3 MSPosition : TEXCOORD6; + float3 MSPosition : TEXCOORD6; #endif #if !(defined(MEMBRANE) && (defined(SKINNED) || defined(NORMALS))) - float FogAlpha : TEXCOORD5; + float FogAlpha : TEXCOORD5; #endif #if defined(MOTIONVECTORS_NORMALS) -#if !(defined(MEMBRANE) && (defined(SKINNED) || defined(NORMALS))) - float3 ScreenSpaceNormal : TEXCOORD7; -#endif - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; -#if (defined(MEMBRANE) && defined(SKINNED) && !defined(NORMALS)) - float3 ScreenSpaceNormal : TEXCOORD7; -#endif +# if !(defined(MEMBRANE) && (defined(SKINNED) || defined(NORMALS))) + float3 ScreenSpaceNormal : TEXCOORD7; +# endif + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; +# if (defined(MEMBRANE) && defined(SKINNED) && !defined(NORMALS)) + float3 ScreenSpaceNormal : TEXCOORD7; +# endif #endif }; #ifdef VSHADER -cbuffer PerFrame : register(b12) +cbuffer PerFrame : register(b12) { - row_major float4x3 ScreenProj : packoffset(c0); - row_major float4x4 ViewProj : packoffset(c8); -#if defined (SKINNED) - float3 BonesPivot : packoffset(c40); -#if defined(MOTIONVECTORS_NORMALS) - float3 PreviousBonesPivot : packoffset(c41); -#endif -#endif + row_major float4x3 ScreenProj : packoffset(c0); + row_major float4x4 ViewProj : packoffset(c8); +# if defined(SKINNED) + float3 BonesPivot : packoffset(c40); +# if defined(MOTIONVECTORS_NORMALS) + float3 PreviousBonesPivot : packoffset(c41); +# endif +# endif }; -cbuffer PerTechnique : register(b0) +cbuffer PerTechnique : register(b0) { - float4 FogParam : packoffset(c0); - float4 FogNearColor : packoffset(c1); - float4 FogFarColor : packoffset(c2); + float4 FogParam : packoffset(c0); + float4 FogNearColor : packoffset(c1); + float4 FogFarColor : packoffset(c2); }; -cbuffer PerMaterial : register(b1) +cbuffer PerMaterial : register(b1) { - float4 TexcoordOffset : packoffset(c0); - float4 SoftMateralVSParams : packoffset(c1); - float4 FalloffData : packoffset(c2); + float4 TexcoordOffset : packoffset(c0); + float4 SoftMateralVSParams : packoffset(c1); + float4 FalloffData : packoffset(c2); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float3x4 World : packoffset(c0); - row_major float3x4 PreviousWorld : packoffset(c3); - float4 MatProj[3] : packoffset(c6); - float4 EyePosition : packoffset(c12); - float4 PosAdjust : packoffset(c13); - float4 TexcoordOffsetMembrane : packoffset(c14); + row_major float3x4 World : packoffset(c0); + row_major float3x4 PreviousWorld : packoffset(c3); + float4 MatProj[3] : packoffset(c6); + float4 EyePosition : packoffset(c12); + float4 PosAdjust : packoffset(c13); + float4 TexcoordOffsetMembrane : packoffset(c14); } -cbuffer IndexedTexcoordBuffer : register(b11) +cbuffer IndexedTexcoordBuffer : register(b11) { - float4 IndexedTexCoord[128] : packoffset(c0); + float4 IndexedTexCoord[128] : packoffset(c0); } -#if defined (SKINNED) -#if defined(MOTIONVECTORS_NORMALS) -cbuffer PreviousBonesBuffer : register(b9) +# if defined(SKINNED) +# if defined(MOTIONVECTORS_NORMALS) +cbuffer PreviousBonesBuffer : register(b9) { - float4 PreviousBones[240] : packoffset(c0); + float4 PreviousBones[240] : packoffset(c0); } -#endif +# endif -cbuffer BonesBuffer : register(b10) +cbuffer BonesBuffer : register(b10) { - float4 Bones[240] : packoffset(c0); + float4 Bones[240] : packoffset(c0); } -#endif +# endif -#if defined (SKINNED) +# if defined(SKINNED) float3x4 GetBoneTransformMatrix(float4 bones[240], int4 actualIndices, float3 pivot, float4 weights) { float3x4 pivotMatrix = transpose(float4x3(0.0.xxx, 0.0.xxx, 0.0.xxx, pivot)); @@ -154,8 +154,7 @@ float3x4 GetBoneTransformMatrix(float4 bones[240], int4 actualIndices, float3 pi float3x3 GetBoneRSMatrix(float4 bones[240], int4 actualIndices, float4 weights) { float3x3 result; - for (int rowIndex = 0; rowIndex < 3; ++rowIndex) - { + for (int rowIndex = 0; rowIndex < 3; ++rowIndex) { result[rowIndex] = weights.xxx * bones[actualIndices.x + rowIndex].xyz + weights.yyy * bones[actualIndices.y + rowIndex].xyz + weights.zzz * bones[actualIndices.z + rowIndex].xyz + @@ -163,12 +162,12 @@ float3x3 GetBoneRSMatrix(float4 bones[240], int4 actualIndices, float4 weights) } return result; } -#endif +# endif -#define M_HALFPI 1.57079637; -#define M_PI 3.141593 +# define M_HALFPI 1.57079637; +# define M_PI 3.141593 -#if defined(PROJECTED_UV) +# if defined(PROJECTED_UV) float GetProjectedU(float3 worldPosition, float4 texCoordOffset) { float projUvTmp = min(abs(worldPosition.x), abs(worldPosition.y)) * @@ -181,29 +180,22 @@ float GetProjectedU(float3 worldPosition, float4 texCoordOffset) -0.330299497) + 0.999866009; float projUvTmp5; - if (abs(worldPosition.x) > abs(worldPosition.y)) - { + if (abs(worldPosition.x) > abs(worldPosition.y)) { projUvTmp5 = projUvTmp * projUvTmp2 * -2 + M_HALFPI; - } - else - { + } else { projUvTmp5 = 0; } float projUvTmp6 = projUvTmp * projUvTmp2 + projUvTmp5; float projUvTmp7; - if (worldPosition.y < -worldPosition.y) - { + if (worldPosition.y < -worldPosition.y) { projUvTmp7 = -M_PI; - } - else - { + } else { projUvTmp7 = 0; } float projUvTmp4 = projUvTmp6 + projUvTmp7; float minCoord = min(worldPosition.x, worldPosition.y); float maxCoord = max(worldPosition.x, worldPosition.y); - if (minCoord < -minCoord && maxCoord >= -maxCoord) - { + if (minCoord < -minCoord && maxCoord >= -maxCoord) { projUvTmp4 = -projUvTmp4; } return abs(0.318309158 * projUvTmp4) * texCoordOffset.w + texCoordOffset.y; @@ -213,7 +205,7 @@ float GetProjectedV(float3 worldPosition) { return (-PosAdjust.x + (PosAdjust.z + worldPosition.z)) / PosAdjust.y; } -#endif +# endif VS_OUTPUT main(VS_INPUT input) { @@ -225,246 +217,246 @@ VS_OUTPUT main(VS_INPUT input) precise float3x3 world3x3 = transpose(float3x3(transpose(World)[0], transpose(World)[1], transpose(World)[2])); -#if defined(SKY_OBJECT) +# if defined(SKY_OBJECT) float4x4 viewProj = float4x4(ViewProj[0], ViewProj[1], ViewProj[3], ViewProj[3]); -#else +# else float4x4 viewProj = ViewProj; -#endif - -#if defined (SKINNED) +# endif + +# if defined(SKINNED) precise int4 actualIndices = 765.01.xxxx * input.BoneIndices.xyzw; -#if defined(MOTIONVECTORS_NORMALS) +# if defined(MOTIONVECTORS_NORMALS) float3x4 previousBoneTransformMatrix = GetBoneTransformMatrix(PreviousBones, actualIndices, PreviousBonesPivot, input.BoneWeights); precise float4 previousWorldPosition = float4(mul(inputPosition, transpose(previousBoneTransformMatrix)), 1); -#endif +# endif float3x4 boneTransformMatrix = GetBoneTransformMatrix(Bones, actualIndices, BonesPivot, input.BoneWeights); precise float4 worldPosition = float4(mul(inputPosition, transpose(boneTransformMatrix)), 1); float4 viewPos = mul(viewProj, worldPosition); -#else +# else precise float4 worldPosition = float4(mul(World, inputPosition), 1); precise float4 previousWorldPosition = float4(mul(PreviousWorld, inputPosition), 1); precise float4x4 modelView = mul(viewProj, world4x4); float4 viewPos = mul(modelView, inputPosition); -#endif +# endif vsout.Position = viewPos; -#if defined(SKINNED) +# if defined(SKINNED) float3x3 boneRSMatrix = GetBoneRSMatrix(Bones, actualIndices, input.BoneWeights); float3x3 boneRSMatrixTr = transpose(boneRSMatrix); -#endif +# endif -#if defined(NORMALS) || defined(MOTIONVECTORS_NORMALS) +# if defined(NORMALS) || defined(MOTIONVECTORS_NORMALS) float3 normal = input.Normal.xyz * 2 - 1; -#if defined(SKINNED) +# if defined(SKINNED) float3 worldNormal = normalize(mul(normal, boneRSMatrixTr)); -#else +# else float3 worldNormal = normalize(mul(world3x3, normal)); -#endif -#endif +# endif +# endif -#if defined(VC) +# if defined(VC) vsout.Color = input.Color; -#endif - -#if !defined(MOTIONVECTORS_NORMALS) +# endif + +# if !defined(MOTIONVECTORS_NORMALS) float fogColorParam = min(FogParam.w, exp2(FogParam.z * log2(saturate(length(viewPos.xyz) * FogParam.y - FogParam.x)))); vsout.FogParam.xyz = lerp(FogNearColor.xyz, FogFarColor.xyz, fogColorParam); vsout.FogParam.w = fogColorParam; -#endif +# endif float4 texCoord = float4(0, 0, 1, 0); - -#if defined (MEMBRANE) + +# if defined(MEMBRANE) float4 texCoordOffset = TexcoordOffsetMembrane; -#else +# else float4 texCoordOffset = TexcoordOffset; -#endif +# endif -#if defined(TEXCOORD_INDEX) -#if defined(NORMALS) +# if defined(TEXCOORD_INDEX) +# if defined(NORMALS) uint index = input.TexCoord0.z; -#else +# else uint index = input.Position.w; -#endif -#endif - -#if defined (PROJECTED_UV) -#if defined(NORMALS) && !defined(MEMBRANE) +# endif +# endif + +# if defined(PROJECTED_UV) +# if defined(NORMALS) && !defined(MEMBRANE) texCoord.x = dot(MatProj[0].xyz, inputPosition.xyz); -#else +# else texCoord.x = GetProjectedU(worldPosition.xyz, texCoordOffset); -#endif -#else -#if defined(TEXTURE) +# endif +# else +# if defined(TEXTURE) float u = input.TexCoord0.x; -#if defined(TEXCOORD_INDEX) +# if defined(TEXCOORD_INDEX) u = IndexedTexCoord[index].y * u + IndexedTexCoord[index].x; -#endif +# endif texCoord.x = u * texCoordOffset.z + texCoordOffset.x; -#endif -#endif -#if defined (PROJECTED_UV) -#if defined(NORMALS) && !defined(MEMBRANE) +# endif +# endif +# if defined(PROJECTED_UV) +# if defined(NORMALS) && !defined(MEMBRANE) texCoord.y = dot(MatProj[1].xyz, inputPosition.xyz); -#else +# else texCoord.y = GetProjectedV(worldPosition.xyz); -#endif -#else -#if defined(TEXTURE) +# endif +# else +# if defined(TEXTURE) float v = input.TexCoord0.y; -#if defined(TEXCOORD_INDEX) +# if defined(TEXCOORD_INDEX) v = IndexedTexCoord[index].w * v + IndexedTexCoord[index].z; -#endif +# endif texCoord.y = v * texCoordOffset.w + texCoordOffset.y; -#endif -#endif -#if defined(PROJECTED_UV) && !defined(NORMALS) +# endif +# endif +# if defined(PROJECTED_UV) && !defined(NORMALS) texCoord.w = input.TexCoord0.y; -#elif defined(SOFT) +# elif defined(SOFT) texCoord.w = viewPos.w / SoftMateralVSParams.x; -#elif defined(MEMBRANE) && !defined(NORMALS) +# elif defined(MEMBRANE) && !defined(NORMALS) texCoord.w = input.TexCoord0.y; -#endif -#if defined(PROJECTED_UV) && !defined(NORMALS) +# endif +# if defined(PROJECTED_UV) && !defined(NORMALS) texCoord.z = input.TexCoord0.x; -#elif defined(FALLOFF) +# elif defined(FALLOFF) float3 inverseWorldDirection = normalize(-worldPosition.xyz); float WdotN = dot(worldNormal, inverseWorldDirection); float falloff = saturate((-FalloffData.x + abs(WdotN)) / (FalloffData.y - FalloffData.x)); float falloffParam = (falloff * falloff) * (3 - falloff * 2); texCoord.z = lerp(FalloffData.z, FalloffData.w, falloffParam); -#elif defined(MEMBRANE) && !defined(NORMALS) +# elif defined(MEMBRANE) && !defined(NORMALS) texCoord.z = input.TexCoord0.x; -#endif +# endif vsout.TexCoord0 = texCoord; float3 eyePosition = 0.0.xxx; -#if defined(MEMBRANE) && defined(TEXTURE) && !defined(SKINNED) +# if defined(MEMBRANE) && defined(TEXTURE) && !defined(SKINNED) eyePosition = EyePosition.xyz; -#endif +# endif float3 viewPosition = inputPosition.xyz; -#if defined(SKINNED) +# if defined(SKINNED) viewPosition = worldPosition.xyz; -#endif +# endif -#if defined(MEMBRANE) -#if defined(SKINNED) -#if defined(NORMALS) +# if defined(MEMBRANE) +# if defined(SKINNED) +# if defined(NORMALS) vsout.TBN0.xyz = worldNormal; -#else +# else float3x3 tbnTr = float3x3(normalize(boneRSMatrixTr[0]), normalize(boneRSMatrixTr[1]), normalize(boneRSMatrixTr[2])); -#if defined(MOTIONVECTORS_NORMALS) +# if defined(MOTIONVECTORS_NORMALS) tbnTr[2] = worldNormal; -#endif +# endif float3x3 tbn = transpose(tbnTr); vsout.TBN0.xyz = tbn[0]; vsout.TBN1.xyz = tbn[1]; vsout.TBN2.xyz = tbn[2]; -#endif -#endif +# endif +# endif vsout.ViewVector.xyz = normalize(eyePosition - viewPosition); vsout.ViewVector.w = 1; -#endif +# endif -#if !defined(SKINNED) && defined(NORMALS) && !(defined(MOTIONVECTORS_NORMALS) && defined(MEMBRANE) && !defined(SKINNED) && defined(NORMALS)) -#if defined(MEMBRANE) +# if !defined(SKINNED) && defined(NORMALS) && !(defined(MOTIONVECTORS_NORMALS) && defined(MEMBRANE) && !defined(SKINNED) && defined(NORMALS)) +# if defined(MEMBRANE) vsout.TBN0.xyz = normal; -#elif defined(PROJECTED_UV) +# elif defined(PROJECTED_UV) vsout.TBN0.xyz = input.Normal.xyz; -#endif -#endif - -#if defined(MOTIONVECTORS_NORMALS) && !(defined(MEMBRANE) && defined(SKINNED) && defined(NORMALS)) -#if defined(SKINNED) && !defined(MEMBRANE) +# endif +# endif + +# if defined(MOTIONVECTORS_NORMALS) && !(defined(MEMBRANE) && defined(SKINNED) && defined(NORMALS)) +# if defined(SKINNED) && !defined(MEMBRANE) float3 screenSpaceNormal = normal; -#elif defined(FALLOFF) || (defined(SKINNED) && defined(MEMBRANE)) +# elif defined(FALLOFF) || (defined(SKINNED) && defined(MEMBRANE)) float3 screenSpaceNormal = worldNormal; -#else +# else float4x3 modelScreen = mul(ScreenProj, world3x3); float3 screenSpaceNormal = normalize(mul(modelScreen, normal)).xyz; -#endif +# endif vsout.ScreenSpaceNormal = screenSpaceNormal; -#endif +# endif -#if defined(LIGHTING) +# if defined(LIGHTING) vsout.MSPosition = viewPosition; -#endif +# endif vsout.FogAlpha.x = FogNearColor.w; -#if defined(PROJECTED_UV) && defined(NORMALS) && !defined(MEMBRANE) +# if defined(PROJECTED_UV) && defined(NORMALS) && !defined(MEMBRANE) vsout.TBN1.xyz = MatProj[2].xyz; -#endif - -#if defined(MOTIONVECTORS_NORMALS) +# endif + +# if defined(MOTIONVECTORS_NORMALS) vsout.WorldPosition = worldPosition; vsout.PreviousWorldPosition = previousWorldPosition; -#endif +# endif return vsout; } #endif typedef VS_OUTPUT PS_INPUT; -SamplerState SampBaseSampler : register(s0); +SamplerState SampBaseSampler : register(s0); -Texture2D TexBaseSampler : register(t0); +Texture2D TexBaseSampler : register(t0); struct PS_OUTPUT { - float4 Color : SV_Target0; + float4 Color : SV_Target0; #if defined(MOTIONVECTORS_NORMALS) - float2 MotionVectors : SV_Target1; - float4 ScreenSpaceNormals : SV_Target2; + float2 MotionVectors : SV_Target1; + float4 ScreenSpaceNormals : SV_Target2; #else - float4 Normal : SV_Target1; - float4 Color2 : SV_Target2; + float4 Normal : SV_Target1; + float4 Color2 : SV_Target2; #endif }; #ifdef PSHADER -cbuffer PerFrame : register(b12) +cbuffer PerFrame : register(b12) { - row_major float4x4 ScreenProj : packoffset(c12); - row_major float4x4 PreviousScreenProj : packoffset(c16); + row_major float4x4 ScreenProj : packoffset(c12); + row_major float4x4 PreviousScreenProj : packoffset(c16); }; -cbuffer AlphaTestRefBuffer : register(b11) +cbuffer AlphaTestRefBuffer : register(b11) { - float AlphaTestRef : packoffset(c0); + float AlphaTestRef : packoffset(c0); } -cbuffer PerMaterial : register(b1) +cbuffer PerMaterial : register(b1) { - float4 BaseColor : packoffset(c0); - float4 LightingInfluence : packoffset(c2); + float4 BaseColor : packoffset(c0); + float4 LightingInfluence : packoffset(c2); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - float4 PLightPositionX : packoffset(c0); - float4 PLightPositionY : packoffset(c1); - float4 PLightPositionZ : packoffset(c2); - float4 PLightingRadiusInverseSquared : packoffset(c3); - float4 PLightColorR : packoffset(c4); - float4 PLightColorG : packoffset(c5); - float4 PLightColorB : packoffset(c6); - float4 DLightColor : packoffset(c7); - float4 PropertyColor : packoffset(c8); + float4 PLightPositionX : packoffset(c0); + float4 PLightPositionY : packoffset(c1); + float4 PLightPositionZ : packoffset(c2); + float4 PLightingRadiusInverseSquared : packoffset(c3); + float4 PLightColorR : packoffset(c4); + float4 PLightColorG : packoffset(c5); + float4 PLightColorB : packoffset(c6); + float4 DLightColor : packoffset(c7); + float4 PropertyColor : packoffset(c8); }; -#if defined(LIGHTING) +# if defined(LIGHTING) float3 GetLightingColor(float3 msPosition) { float4 lightDistX = PLightPositionX - msPosition.xxxx; @@ -484,59 +476,57 @@ float3 GetLightingColor(float3 msPosition) return color; } -#endif +# endif PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; float4 baseColorMul = BaseColor; -#if defined(VC) +# if defined(VC) baseColorMul *= input.Color; -#endif +# endif float4 baseColor = float4(1, 1, 1, 1); -#if defined(TEXTURE) +# if defined(TEXTURE) baseColor *= TexBaseSampler.Sample(SampBaseSampler, input.TexCoord0.xy); -#endif +# endif baseColor.w *= input.TexCoord0.z; baseColor *= baseColorMul; -#if !defined (MOTIONVECTORS_NORMALS) - if (PropertyColor.w * baseColor.w - AlphaTestRef < 0) - { +# if !defined(MOTIONVECTORS_NORMALS) + if (PropertyColor.w * baseColor.w - AlphaTestRef < 0) { discard; } -#endif +# endif float3 propertyColor = PropertyColor.xyz; -#if defined(LIGHTING) +# if defined(LIGHTING) propertyColor = GetLightingColor(input.MSPosition); -#endif +# endif float3 lightColor = lerp(baseColor.xyz, propertyColor * baseColor.xyz, LightingInfluence.xxx); -#if !defined (MOTIONVECTORS_NORMALS) -#if defined(ADDBLEND) +# if !defined(MOTIONVECTORS_NORMALS) +# if defined(ADDBLEND) float3 blendedColor = lightColor * (1 - input.FogParam.www); -#elif defined(MULTBLEND) +# elif defined(MULTBLEND) float3 blendedColor = lerp(lightColor, 1.0.xxx, saturate(1.5 * input.FogParam.w).xxx); -#else +# else float3 blendedColor = lerp(lightColor, input.FogParam.xyz, input.FogParam.www); -#endif -#else +# endif +# else float3 blendedColor = lightColor.xyz; -#endif - +# endif + float4 finalColor = float4(blendedColor, PropertyColor.w * baseColor.w); -#if !defined(MULTBLEND) +# if !defined(MULTBLEND) finalColor *= float4(input.FogAlpha.xxx, 1); -#endif - psout.Color = finalColor; +# endif + psout.Color = finalColor; - -#if defined (MOTIONVECTORS_NORMALS) +# if defined(MOTIONVECTORS_NORMALS) float4 screenPosition = mul(ScreenProj, input.WorldPosition); screenPosition.xy = screenPosition.xy / screenPosition.ww; float4 previousScreenPosition = mul(PreviousScreenProj, input.PreviousWorldPosition); @@ -550,12 +540,12 @@ PS_OUTPUT main(PS_INPUT input) screenSpaceNormal.xy /= screenSpaceNormal.zz; psout.ScreenSpaceNormals.xy = screenSpaceNormal.xy + 0.5.xx; psout.ScreenSpaceNormals.zw = 0.0.xx; -#else +# else psout.Normal.xyz = float3(1, 0, 0); psout.Normal.w = finalColor.w; psout.Color2 = finalColor; -#endif +# endif return psout; } diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 89bc669cc..e223e7d35 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -1,126 +1,126 @@ #if (defined(TREE_ANIM) || defined(LANDSCAPE)) && !defined(VC) -#define VC +# define VC #endif #if defined(SPECULAR) || defined(AMBIENT_SPECULAR) || defined(ENVMAP) || defined(RIM_LIGHTING) || defined(PARALLAX) || defined(MULTI_LAYER_PARALLAX) || defined(FACEGEN) || defined(FACEGEN_RGB_TINT) || defined(SNOW_FLAG) || defined(EYE) || defined(PBR) -#define HAS_VIEW_VECTOR +# define HAS_VIEW_VECTOR #endif struct VS_INPUT { - float4 Position : POSITION0; - float2 TexCoord0 : TEXCOORD0; + float4 Position : POSITION0; + float2 TexCoord0 : TEXCOORD0; #if !defined(MODELSPACENORMALS) - float4 Normal : NORMAL0; - float4 Bitangent : BINORMAL0; + float4 Normal : NORMAL0; + float4 Bitangent : BINORMAL0; #endif - + #if defined(VC) - float4 Color : COLOR0; -#if defined(LANDSCAPE) - float4 LandBlendWeights1 : TEXCOORD2; - float4 LandBlendWeights2 : TEXCOORD3; -#endif + float4 Color : COLOR0; +# if defined(LANDSCAPE) + float4 LandBlendWeights1 : TEXCOORD2; + float4 LandBlendWeights2 : TEXCOORD3; +# endif #endif #if defined(SKINNED) - float4 BoneWeights : BLENDWEIGHT0; - float4 BoneIndices : BLENDINDICES0; + float4 BoneWeights : BLENDWEIGHT0; + float4 BoneIndices : BLENDINDICES0; #endif #if defined(EYE) - float EyeParameter : TEXCOORD2; + float EyeParameter : TEXCOORD2; #endif }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; -#if (defined (PROJECTED_UV) && !defined(SKINNED)) || defined(LANDSCAPE) + float4 Position : SV_POSITION0; +#if (defined(PROJECTED_UV) && !defined(SKINNED)) || defined(LANDSCAPE) float4 #else - float2 + float2 #endif - TexCoord0 : TEXCOORD0; -#if defined (ENVMAP) + TexCoord0 : TEXCOORD0; +#if defined(ENVMAP) precise #endif - float3 InputPosition : TEXCOORD4; + float3 InputPosition : TEXCOORD4; #if defined(SKINNED) || !defined(MODELSPACENORMALS) - float3 TBN0 : TEXCOORD1; - float3 TBN1 : TEXCOORD2; - float3 TBN2 : TEXCOORD3; + float3 TBN0 : TEXCOORD1; + float3 TBN1 : TEXCOORD2; + float3 TBN2 : TEXCOORD3; #endif #if defined(HAS_VIEW_VECTOR) - float3 ViewVector : TEXCOORD5; + float3 ViewVector : TEXCOORD5; #endif #if defined(EYE) - float3 EyeNormal : TEXCOORD6; + float3 EyeNormal : TEXCOORD6; #elif defined(LANDSCAPE) - float4 LandBlendWeights1 : TEXCOORD6; - float4 LandBlendWeights2 : TEXCOORD7; + float4 LandBlendWeights1 : TEXCOORD6; + float4 LandBlendWeights2 : TEXCOORD7; #elif defined(PROJECTED_UV) && !defined(SKINNED) - float3 TexProj : TEXCOORD7; -#endif - float3 ScreenNormalTransform0 : TEXCOORD8; - float3 ScreenNormalTransform1 : TEXCOORD9; - float3 ScreenNormalTransform2 : TEXCOORD10; - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; - float4 Color : COLOR0; - float4 FogParam : COLOR1; + float3 TexProj : TEXCOORD7; +#endif + float3 ScreenNormalTransform0 : TEXCOORD8; + float3 ScreenNormalTransform1 : TEXCOORD9; + float3 ScreenNormalTransform2 : TEXCOORD10; + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; + float4 Color : COLOR0; + float4 FogParam : COLOR1; }; #ifdef VSHADER -cbuffer PerFrame : register(b12) +cbuffer PerFrame : register(b12) { - row_major float3x3 ScreenProj : packoffset(c0); - row_major float4x4 ViewProj : packoffset(c8); -#if defined (SKINNED) - float3 BonesPivot : packoffset(c40); - float3 PreviousBonesPivot : packoffset(c41); -#endif + row_major float3x3 ScreenProj : packoffset(c0); + row_major float4x4 ViewProj : packoffset(c8); +# if defined(SKINNED) + float3 BonesPivot : packoffset(c40); + float3 PreviousBonesPivot : packoffset(c41); +# endif }; -cbuffer PerTechnique : register(b0) +cbuffer PerTechnique : register(b0) { - float4 HighDetailRange : packoffset(c0); // loaded cells center in xy, size in zw - float4 FogParam : packoffset(c1); - float4 FogNearColor : packoffset(c2); - float4 FogFarColor : packoffset(c3); + float4 HighDetailRange : packoffset(c0); // loaded cells center in xy, size in zw + float4 FogParam : packoffset(c1); + float4 FogNearColor : packoffset(c2); + float4 FogFarColor : packoffset(c3); }; -cbuffer PerMaterial : register(b1) +cbuffer PerMaterial : register(b1) { - float4 LeftEyeCenter : packoffset(c0); - float4 RightEyeCenter : packoffset(c1); - float4 TexcoordOffset : packoffset(c2); + float4 LeftEyeCenter : packoffset(c0); + float4 RightEyeCenter : packoffset(c1); + float4 TexcoordOffset : packoffset(c2); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float3x4 World : packoffset(c0); - row_major float3x4 PreviousWorld : packoffset(c3); - float4 EyePosition : packoffset(c6); - float4 LandBlendParams : packoffset(c7); // offset in xy, gridPosition in yw - float4 TreeParams : packoffset(c8); // wind magnitude in y, amplitude in z, leaf frequency in w - float2 WindTimers : packoffset(c9); - row_major float3x4 TextureProj : packoffset(c10); - float IndexScale : packoffset(c13); - float4 WorldMapOverlayParameters : packoffset(c14); + row_major float3x4 World : packoffset(c0); + row_major float3x4 PreviousWorld : packoffset(c3); + float4 EyePosition : packoffset(c6); + float4 LandBlendParams : packoffset(c7); // offset in xy, gridPosition in yw + float4 TreeParams : packoffset(c8); // wind magnitude in y, amplitude in z, leaf frequency in w + float2 WindTimers : packoffset(c9); + row_major float3x4 TextureProj : packoffset(c10); + float IndexScale : packoffset(c13); + float4 WorldMapOverlayParameters : packoffset(c14); }; -#if defined (SKINNED) -cbuffer PreviousBonesBuffer : register(b9) +# if defined(SKINNED) +cbuffer PreviousBonesBuffer : register(b9) { - float4 PreviousBones[240] : packoffset(c0); + float4 PreviousBones[240] : packoffset(c0); } -cbuffer BonesBuffer : register(b10) +cbuffer BonesBuffer : register(b10) { - float4 Bones[240] : packoffset(c0); + float4 Bones[240] : packoffset(c0); } -#endif +# endif -#if defined (TREE_ANIM) +# if defined(TREE_ANIM) float2 GetTreeShiftVector(float4 position, float4 color) { precise float4 tmp1 = (TreeParams.w * TreeParams.y).xxxx * WindTimers.xxyy; @@ -129,9 +129,9 @@ float2 GetTreeShiftVector(float4 position, float4 color) precise float4 tmp4 = (tmp3 * tmp3) * (3.0.xxxx - 2.0.xxxx * tmp3); return (tmp4.xz + 0.1.xx * tmp4.yw) * (TreeParams.z * color.w).xx; } -#endif +# endif -#if defined (SKINNED) +# if defined(SKINNED) float3x4 GetBoneMatrix(float4 bones[240], int4 actualIndices, float3 pivot, float4 weights) { /*float3x4 result; @@ -172,8 +172,7 @@ float3x4 GetBoneMatrix(float4 bones[240], int4 actualIndices, float3 pivot, floa float3x3 GetBoneRSMatrix(float4 bones[240], int4 actualIndices, float4 weights) { float3x3 result; - for (int rowIndex = 0; rowIndex < 3; ++rowIndex) - { + for (int rowIndex = 0; rowIndex < 3; ++rowIndex) { result[rowIndex] = weights.xxx * bones[actualIndices.x + rowIndex].xyz + weights.yyy * bones[actualIndices.y + rowIndex].xyz + weights.zzz * bones[actualIndices.z + rowIndex].xyz + @@ -181,7 +180,7 @@ float3x3 GetBoneRSMatrix(float4 bones[240], int4 actualIndices, float4 weights) } return result; } -#endif +# endif VS_OUTPUT main(VS_INPUT input) { @@ -189,27 +188,26 @@ VS_OUTPUT main(VS_INPUT input) precise float4 inputPosition = float4(input.Position.xyz, 1.0); -#if defined (LODLANDNOISE) || defined(LODLANDSCAPE) +# if defined(LODLANDNOISE) || defined(LODLANDSCAPE) float4 rawWorldPosition = float4(mul(World, inputPosition), 1); float worldXShift = rawWorldPosition.x - HighDetailRange.x; float worldYShift = rawWorldPosition.y - HighDetailRange.y; - if ((abs(worldXShift) < HighDetailRange.z) && (abs(worldYShift) < HighDetailRange.w)) - { + if ((abs(worldXShift) < HighDetailRange.z) && (abs(worldYShift) < HighDetailRange.w)) { inputPosition.z -= (230 + rawWorldPosition.z / 1e9); } -#endif - +# endif + precise float4 previousInputPosition = inputPosition; - -#if defined(TREE_ANIM) + +# if defined(TREE_ANIM) precise float2 treeShiftVector = GetTreeShiftVector(input.Position, input.Color); float3 normal = -1.0.xxx + 2.0.xxx * input.Normal.xyz; - + inputPosition.xyz += normal.xyz * treeShiftVector.x; previousInputPosition.xyz += normal.xyz * treeShiftVector.y; -#endif +# endif -#if defined (SKINNED) +# if defined(SKINNED) precise int4 actualIndices = 765.01.xxxx * input.BoneIndices.xyzw; float3x4 previousWorldMatrix = @@ -221,68 +219,67 @@ VS_OUTPUT main(VS_INPUT input) precise float4 worldPosition = float4(mul(inputPosition, transpose(worldMatrix)), 1); float4 viewPos = mul(ViewProj, worldPosition); -#else +# else precise float4 previousWorldPosition = float4(mul(PreviousWorld, inputPosition), 1); precise float4 worldPosition = float4(mul(World, inputPosition), 1); precise float4x4 world4x4 = float4x4(World[0], World[1], World[2], float4(0, 0, 0, 1)); precise float4x4 modelView = mul(ViewProj, world4x4); float4 viewPos = mul(modelView, inputPosition); -#endif +# endif -#if defined(OUTLINE) && !defined(MODELSPACENORMALS) +# if defined(OUTLINE) && !defined(MODELSPACENORMALS) float3 normal = normalize(-1.0.xxx + 2.0.xxx * input.Normal.xyz); float outlineShift = min(max(viewPos.z / 150, 1), 50); inputPosition.xyz += outlineShift * normal.xyz; previousInputPosition.xyz += outlineShift * normal.xyz; -#if defined (SKINNED) +# if defined(SKINNED) previousWorldPosition = float4(mul(inputPosition, transpose(previousWorldMatrix)), 1); worldPosition = float4(mul(inputPosition, transpose(worldMatrix)), 1); viewPos = mul(ViewProj, worldPosition); -#else +# else previousWorldPosition = float4(mul(PreviousWorld, inputPosition), 1); worldPosition = float4(mul(World, inputPosition), 1); viewPos = mul(modelView, inputPosition); -#endif -#endif +# endif +# endif vsout.Position = viewPos; -#if defined (LODLANDNOISE) || defined (LODLANDSCAPE) +# if defined(LODLANDNOISE) || defined(LODLANDSCAPE) vsout.Position.z += min(1, 1e-4 * max(0, viewPos.z - 70000)) * 0.5; -#endif - +# endif + float2 uv = input.TexCoord0.xy * TexcoordOffset.zw + TexcoordOffset.xy; -#if defined(LANDSCAPE) - vsout.TexCoord0.zw = (uv * 0.010416667.xx + LandBlendParams.xy) * float2(1,-1) + float2(0,1); -#elif defined (PROJECTED_UV) && !defined(SKINNED) - vsout.TexCoord0.z = mul(TextureProj[0], inputPosition); - vsout.TexCoord0.w = mul(TextureProj[1], inputPosition); -#endif +# if defined(LANDSCAPE) + vsout.TexCoord0.zw = (uv * 0.010416667.xx + LandBlendParams.xy) * float2(1, -1) + float2(0, 1); +# elif defined(PROJECTED_UV) && !defined(SKINNED) + vsout.TexCoord0.z = mul(TextureProj[0], inputPosition); + vsout.TexCoord0.w = mul(TextureProj[1], inputPosition); +# endif vsout.TexCoord0.xy = uv; - -#if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SKINNED) + +# if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SKINNED) vsout.InputPosition.xyz = worldPosition.xyz; -#elif defined (WORLD_MAP) +# elif defined(WORLD_MAP) vsout.InputPosition.xyz = WorldMapOverlayParameters.xyz + worldPosition.xyz; -#else +# else vsout.InputPosition.xyz = inputPosition.xyz; -#endif +# endif -#if defined (SKINNED) +# if defined(SKINNED) float3x3 boneRSMatrix = GetBoneRSMatrix(Bones, actualIndices, input.BoneWeights); -#endif - -#if !defined(MODELSPACENORMALS) +# endif + +# if !defined(MODELSPACENORMALS) float3x3 tbn = float3x3( float3(input.Position.w, input.Normal.w * 2 - 1, input.Bitangent.w * 2 - 1), input.Bitangent.xyz * 2.0.xxx + -1.0.xxx, - input.Normal.xyz * 2.0.xxx + -1.0.xxx - ); + input.Normal.xyz * 2.0.xxx + -1.0.xxx); float3x3 tbnTr = transpose(tbn); -#if defined (SKINNED) +# if defined(SKINNED) float3x3 worldTbnTr = transpose(mul(transpose(tbnTr), transpose(boneRSMatrix))); float3x3 worldTbnTrTr = transpose(worldTbnTr); worldTbnTrTr[0] = normalize(worldTbnTrTr[0]); @@ -292,7 +289,7 @@ VS_OUTPUT main(VS_INPUT input) vsout.TBN0.xyz = worldTbnTr[0]; vsout.TBN1.xyz = worldTbnTr[1]; vsout.TBN2.xyz = worldTbnTr[2]; -#elif defined (ENVMAP) || defined(MULTI_LAYER_PARALLAX) +# elif defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) vsout.TBN0.xyz = mul(tbn, World[0].xyz); vsout.TBN1.xyz = mul(tbn, World[1].xyz); vsout.TBN2.xyz = mul(tbn, World[2].xyz); @@ -304,12 +301,12 @@ VS_OUTPUT main(VS_INPUT input) vsout.TBN0.xyz = tempTbnTr[0]; vsout.TBN1.xyz = tempTbnTr[1]; vsout.TBN2.xyz = tempTbnTr[2]; -#else +# else vsout.TBN0.xyz = tbnTr[0]; vsout.TBN1.xyz = tbnTr[1]; vsout.TBN2.xyz = tbnTr[2]; -#endif -#elif defined (SKINNED) +# endif +# elif defined(SKINNED) float3x3 boneRSMatrixTr = transpose(boneRSMatrix); float3x3 worldTbnTr = transpose(float3x3(normalize(boneRSMatrixTr[0]), normalize(boneRSMatrixTr[1]), normalize(boneRSMatrixTr[2]))); @@ -317,67 +314,67 @@ VS_OUTPUT main(VS_INPUT input) vsout.TBN0.xyz = worldTbnTr[0]; vsout.TBN1.xyz = worldTbnTr[1]; vsout.TBN2.xyz = worldTbnTr[2]; -#endif - -#if defined(LANDSCAPE) +# endif + +# if defined(LANDSCAPE) vsout.LandBlendWeights1 = input.LandBlendWeights1; - + float2 gridOffset = LandBlendParams.zw - input.Position.xy; - vsout.LandBlendWeights2.w = 1 - saturate(0.000375600968 * (9625.59961 - length(gridOffset))); + vsout.LandBlendWeights2.w = 1 - saturate(0.000375600968 * (9625.59961 - length(gridOffset))); vsout.LandBlendWeights2.xyz = input.LandBlendWeights2.xyz; -#elif defined(PROJECTED_UV) && !defined(SKINNED) +# elif defined(PROJECTED_UV) && !defined(SKINNED) vsout.TexProj = TextureProj[2].xyz; -#endif - -#if defined (HAS_VIEW_VECTOR) -#if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SKINNED) +# endif + +# if defined(HAS_VIEW_VECTOR) +# if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SKINNED) vsout.ViewVector = EyePosition.xyz - worldPosition.xyz; -#else +# else vsout.ViewVector = EyePosition.xyz - input.Position.xyz; -#endif -#endif +# endif +# endif -#if defined (EYE) +# if defined(EYE) precise float4 modelEyeCenter = float4(LeftEyeCenter.xyz + input.EyeParameter.xxx * (RightEyeCenter.xyz - LeftEyeCenter.xyz), 1); vsout.EyeNormal.xyz = normalize(worldPosition.xyz - mul(modelEyeCenter, transpose(worldMatrix))); -#endif - -#if defined (SKINNED) +# endif + +# if defined(SKINNED) float3x3 ScreenNormalTransform = mul(ScreenProj, worldTbnTr); vsout.ScreenNormalTransform0.xyz = ScreenNormalTransform[0]; vsout.ScreenNormalTransform1.xyz = ScreenNormalTransform[1]; vsout.ScreenNormalTransform2.xyz = ScreenNormalTransform[2]; -#else +# else float3x4 transMat = mul(ScreenProj, World); - -#if defined(MODELSPACENORMALS) + +# if defined(MODELSPACENORMALS) vsout.ScreenNormalTransform0.xyz = transMat[0].xyz; vsout.ScreenNormalTransform1.xyz = transMat[1].xyz; vsout.ScreenNormalTransform2.xyz = transMat[2].xyz; -#else +# else vsout.ScreenNormalTransform0.xyz = mul(transMat[0].xyz, transpose(tbn)); vsout.ScreenNormalTransform1.xyz = mul(transMat[1].xyz, transpose(tbn)); vsout.ScreenNormalTransform2.xyz = mul(transMat[2].xyz, transpose(tbn)); -#endif -#endif +# endif +# endif vsout.WorldPosition = worldPosition; vsout.PreviousWorldPosition = previousWorldPosition; - -#if defined (VC) + +# if defined(VC) vsout.Color = input.Color; -#else +# else vsout.Color = 1.0.xxxx; -#endif - - float fogColorParam = min(FogParam.w, +# endif + + float fogColorParam = min(FogParam.w, exp2(FogParam.z * log2(saturate(length(viewPos.xyz) * FogParam.y - FogParam.x)))); - vsout.FogParam.xyz = lerp(FogNearColor.xyz, FogFarColor.xyz, fogColorParam); + vsout.FogParam.xyz = lerp(FogNearColor.xyz, FogFarColor.xyz, fogColorParam); vsout.FogParam.w = fogColorParam; - - return vsout; + + return vsout; } #endif @@ -385,33 +382,33 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { - float4 Albedo : SV_Target0; - float4 MotionVectors : SV_Target1; - float4 ScreenSpaceNormals : SV_Target2; -#if defined (SNOW) - float2 SnowParameters : SV_Target3; + float4 Albedo : SV_Target0; + float4 MotionVectors : SV_Target1; + float4 ScreenSpaceNormals : SV_Target2; +#if defined(SNOW) + float2 SnowParameters : SV_Target3; #endif }; #ifdef PSHADER -SamplerState SampTerrainParallaxSampler : register(s1); +SamplerState SampTerrainParallaxSampler : register(s1); -#if defined(LANDSCAPE) +# if defined(LANDSCAPE) -SamplerState SampColorSampler : register(s0); +SamplerState SampColorSampler : register(s0); -#define SampLandColor2Sampler SampColorSampler -#define SampLandColor3Sampler SampColorSampler -#define SampLandColor4Sampler SampColorSampler -#define SampLandColor5Sampler SampColorSampler -#define SampLandColor6Sampler SampColorSampler -#define SampNormalSampler SampColorSampler -#define SampLandNormal2Sampler SampColorSampler -#define SampLandNormal3Sampler SampColorSampler -#define SampLandNormal4Sampler SampColorSampler -#define SampLandNormal5Sampler SampColorSampler -#define SampLandNormal6Sampler SampColorSampler +# define SampLandColor2Sampler SampColorSampler +# define SampLandColor3Sampler SampColorSampler +# define SampLandColor4Sampler SampColorSampler +# define SampLandColor5Sampler SampColorSampler +# define SampLandColor6Sampler SampColorSampler +# define SampNormalSampler SampColorSampler +# define SampLandNormal2Sampler SampColorSampler +# define SampLandNormal3Sampler SampColorSampler +# define SampLandNormal4Sampler SampColorSampler +# define SampLandNormal5Sampler SampColorSampler +# define SampLandNormal6Sampler SampColorSampler // SamplerState SampLandColor2Sampler : register(s1); // SamplerState SampLandColor3Sampler : register(s2); @@ -425,234 +422,233 @@ SamplerState SampColorSampler : register(s0); // SamplerState SampLandNormal5Sampler : register(s11); // SamplerState SampLandNormal6Sampler : register(s12); -#else -SamplerState SampColorSampler : register(s0); +# else +SamplerState SampColorSampler : register(s0); -#define SampNormalSampler SampColorSampler +# define SampNormalSampler SampColorSampler //SamplerState SampNormalSampler : register(s1); -#if defined (MODELSPACENORMALS) && !defined(LODLANDNOISE) -SamplerState SampSpecularSampler : register(s2); -#endif -#if defined (FACEGEN) -SamplerState SampTintSampler : register(s3); -SamplerState SampDetailSampler : register(s4); -#elif defined (PARALLAX) -SamplerState SampParallaxSampler : register(s3); -#elif defined (PROJECTED_UV) && !defined(SPARKLE) -SamplerState SampProjDiffuseSampler : register(s3); -#endif -#if defined (PBR) -SamplerState SampRMAOSampler : register(s6); -#endif -#if (defined (ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SNOW_FLAG) || defined(EYE)) && !defined(FACEGEN) -SamplerState SampEnvSampler : register(s4); -SamplerState SampEnvMaskSampler : register(s5); -#endif -#if defined (GLOWMAP) -SamplerState SampGlowSampler : register(s6); -#endif -#if defined (MULTI_LAYER_PARALLAX) -SamplerState SampLayerSampler : register(s8); -#elif defined (PROJECTED_UV) && !defined(SPARKLE) -SamplerState SampProjNormalSampler : register(s8); -#endif -#if defined (BACK_LIGHTING) -SamplerState SampBackLightSampler : register(s9); -#endif -#if defined (PROJECTED_UV) -SamplerState SampProjDetailSampler : register(s10); -#endif -#if defined (CHARACTER_LIGHT) -SamplerState SampCharacterLightSampler : register(s11); -#elif defined (PROJECTED_UV) -SamplerState SampProjNoiseSampler : register(s11); -#endif -#if defined (SOFT_LIGHTING) || defined(RIM_LIGHTING) -SamplerState SampRimSoftLightSampler : register(s12); -#elif defined (WORLD_MAP) -SamplerState SampWorldMapOverlaySampler : register(s12); -#endif -#if defined(WORLD_MAP) && (defined(LODLANDSCAPE) || defined(LODLANDNOISE)) -SamplerState SampWorldMapOverlaySnowSampler : register(s13); -#endif - -#endif - -#if defined(LOD_LAND_BLEND) -SamplerState SampLandLodBlend1Sampler : register(s13); -SamplerState SampLandLodBlend2Sampler : register(s15); -#elif defined(LODLANDNOISE) -SamplerState SampLandLodNoiseSampler : register(s15); -#endif -#if defined (DEFSHADOW) -SamplerState SampShadowMaskSampler : register(s14); -#endif - -#if defined(LANDSCAPE) - -Texture2D TexColorSampler : register(t0); -Texture2D TexLandColor2Sampler : register(t1); -Texture2D TexLandColor3Sampler : register(t2); -Texture2D TexLandColor4Sampler : register(t3); -Texture2D TexLandColor5Sampler : register(t4); -Texture2D TexLandColor6Sampler : register(t5); -Texture2D TexNormalSampler : register(t7); -Texture2D TexLandNormal2Sampler : register(t8); -Texture2D TexLandNormal3Sampler : register(t9); -Texture2D TexLandNormal4Sampler : register(t10); -Texture2D TexLandNormal5Sampler : register(t11); -Texture2D TexLandNormal6Sampler : register(t12); - -#else - -Texture2D TexColorSampler : register(t0); -Texture2D TexNormalSampler : register(t1); // normal in xyz, glossiness in w if not modelspacenormal - -#if defined (MODELSPACENORMALS) && !defined(LODLANDNOISE) -Texture2D TexSpecularSampler : register(t2); -#endif -#if defined (FACEGEN) -Texture2D TexTintSampler : register(t3); -Texture2D TexDetailSampler : register(t4); -#elif defined (PARALLAX) -Texture2D TexParallaxSampler : register(t3); -#elif defined (PROJECTED_UV) && !defined(SPARKLE) -Texture2D TexProjDiffuseSampler : register(t3); -#endif -#if defined (PBR) -Texture2D TexRMAOSampler : register(t6); -#endif -#if (defined (ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SNOW_FLAG) || defined(EYE)) && !defined(FACEGEN) -TextureCube TexEnvSampler : register(t4); -Texture2D TexEnvMaskSampler : register(t5); -#endif -#if defined (GLOWMAP) -Texture2D TexGlowSampler : register(t6); -#endif -#if defined (MULTI_LAYER_PARALLAX) -Texture2D TexLayerSampler : register(t8); -#elif defined (PROJECTED_UV) && !defined(SPARKLE) -Texture2D TexProjNormalSampler : register(t8); -#endif -#if defined (BACK_LIGHTING) -Texture2D TexBackLightSampler : register(t9); -#endif -#if defined (PROJECTED_UV) -Texture2D TexProjDetail : register(t10); -#endif -#if defined (CHARACTER_LIGHT) -Texture2D TexCharacterLightSampler : register(t11); -#elif defined (PROJECTED_UV) -Texture2D TexProjNoiseSampler : register(t11); -#endif -#if defined (SOFT_LIGHTING) || defined(RIM_LIGHTING) -Texture2D TexRimSoftLightSampler : register(t12); -#elif defined (WORLD_MAP) -Texture2D TexWorldMapOverlaySampler : register(t12); -#endif -#if defined(WORLD_MAP) && (defined(LODLANDSCAPE) || defined(LODLANDNOISE)) -Texture2D TexWorldMapOverlaySnowSampler : register(t13); -#endif - -#endif - -#if defined(LOD_LAND_BLEND) -Texture2D TexLandLodBlend1Sampler : register(t13); -Texture2D TexLandLodBlend2Sampler : register(t15); -#elif defined(LODLANDNOISE) -Texture2D TexLandLodNoiseSampler : register(t15); -#endif -#if defined (DEFSHADOW) -Texture2D TexShadowMaskSampler : register(t14); -#endif +# if defined(MODELSPACENORMALS) && !defined(LODLANDNOISE) +SamplerState SampSpecularSampler : register(s2); +# endif +# if defined(FACEGEN) +SamplerState SampTintSampler : register(s3); +SamplerState SampDetailSampler : register(s4); +# elif defined(PARALLAX) +SamplerState SampParallaxSampler : register(s3); +# elif defined(PROJECTED_UV) && !defined(SPARKLE) +SamplerState SampProjDiffuseSampler : register(s3); +# endif +# if defined(PBR) +SamplerState SampRMAOSampler : register(s6); +# endif +# if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SNOW_FLAG) || defined(EYE)) && !defined(FACEGEN) +SamplerState SampEnvSampler : register(s4); +SamplerState SampEnvMaskSampler : register(s5); +# endif +# if defined(GLOWMAP) +SamplerState SampGlowSampler : register(s6); +# endif +# if defined(MULTI_LAYER_PARALLAX) +SamplerState SampLayerSampler : register(s8); +# elif defined(PROJECTED_UV) && !defined(SPARKLE) +SamplerState SampProjNormalSampler : register(s8); +# endif +# if defined(BACK_LIGHTING) +SamplerState SampBackLightSampler : register(s9); +# endif +# if defined(PROJECTED_UV) +SamplerState SampProjDetailSampler : register(s10); +# endif +# if defined(CHARACTER_LIGHT) +SamplerState SampCharacterLightSampler : register(s11); +# elif defined(PROJECTED_UV) +SamplerState SampProjNoiseSampler : register(s11); +# endif +# if defined(SOFT_LIGHTING) || defined(RIM_LIGHTING) +SamplerState SampRimSoftLightSampler : register(s12); +# elif defined(WORLD_MAP) +SamplerState SampWorldMapOverlaySampler : register(s12); +# endif +# if defined(WORLD_MAP) && (defined(LODLANDSCAPE) || defined(LODLANDNOISE)) +SamplerState SampWorldMapOverlaySnowSampler : register(s13); +# endif + +# endif + +# if defined(LOD_LAND_BLEND) +SamplerState SampLandLodBlend1Sampler : register(s13); +SamplerState SampLandLodBlend2Sampler : register(s15); +# elif defined(LODLANDNOISE) +SamplerState SampLandLodNoiseSampler : register(s15); +# endif +# if defined(DEFSHADOW) +SamplerState SampShadowMaskSampler : register(s14); +# endif + +# if defined(LANDSCAPE) + +Texture2D TexColorSampler : register(t0); +Texture2D TexLandColor2Sampler : register(t1); +Texture2D TexLandColor3Sampler : register(t2); +Texture2D TexLandColor4Sampler : register(t3); +Texture2D TexLandColor5Sampler : register(t4); +Texture2D TexLandColor6Sampler : register(t5); +Texture2D TexNormalSampler : register(t7); +Texture2D TexLandNormal2Sampler : register(t8); +Texture2D TexLandNormal3Sampler : register(t9); +Texture2D TexLandNormal4Sampler : register(t10); +Texture2D TexLandNormal5Sampler : register(t11); +Texture2D TexLandNormal6Sampler : register(t12); + +# else + +Texture2D TexColorSampler : register(t0); +Texture2D TexNormalSampler : register(t1); // normal in xyz, glossiness in w if not modelspacenormal + +# if defined(MODELSPACENORMALS) && !defined(LODLANDNOISE) +Texture2D TexSpecularSampler : register(t2); +# endif +# if defined(FACEGEN) +Texture2D TexTintSampler : register(t3); +Texture2D TexDetailSampler : register(t4); +# elif defined(PARALLAX) +Texture2D TexParallaxSampler : register(t3); +# elif defined(PROJECTED_UV) && !defined(SPARKLE) +Texture2D TexProjDiffuseSampler : register(t3); +# endif +# if defined(PBR) +Texture2D TexRMAOSampler : register(t6); +# endif +# if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(SNOW_FLAG) || defined(EYE)) && !defined(FACEGEN) +TextureCube TexEnvSampler : register(t4); +Texture2D TexEnvMaskSampler : register(t5); +# endif +# if defined(GLOWMAP) +Texture2D TexGlowSampler : register(t6); +# endif +# if defined(MULTI_LAYER_PARALLAX) +Texture2D TexLayerSampler : register(t8); +# elif defined(PROJECTED_UV) && !defined(SPARKLE) +Texture2D TexProjNormalSampler : register(t8); +# endif +# if defined(BACK_LIGHTING) +Texture2D TexBackLightSampler : register(t9); +# endif +# if defined(PROJECTED_UV) +Texture2D TexProjDetail : register(t10); +# endif +# if defined(CHARACTER_LIGHT) +Texture2D TexCharacterLightSampler : register(t11); +# elif defined(PROJECTED_UV) +Texture2D TexProjNoiseSampler : register(t11); +# endif +# if defined(SOFT_LIGHTING) || defined(RIM_LIGHTING) +Texture2D TexRimSoftLightSampler : register(t12); +# elif defined(WORLD_MAP) +Texture2D TexWorldMapOverlaySampler : register(t12); +# endif +# if defined(WORLD_MAP) && (defined(LODLANDSCAPE) || defined(LODLANDNOISE)) +Texture2D TexWorldMapOverlaySnowSampler : register(t13); +# endif + +# endif + +# if defined(LOD_LAND_BLEND) +Texture2D TexLandLodBlend1Sampler : register(t13); +Texture2D TexLandLodBlend2Sampler : register(t15); +# elif defined(LODLANDNOISE) +Texture2D TexLandLodNoiseSampler : register(t15); +# endif +# if defined(DEFSHADOW) +Texture2D TexShadowMaskSampler : register(t14); +# endif cbuffer PerFrame : register(b12) { - row_major float4x4 ViewMatrix : packoffset(c0); - row_major float4x4 ProjMatrix : packoffset(c4); - row_major float4x4 ViewProjMatrix : packoffset(c8); - row_major float4x4 ViewProjMatrixUnjittered : packoffset(c12); - row_major float4x4 PreviousViewProjMatrixUnjittered : packoffset(c16); - row_major float4x4 InvProjMatrixUnjittered : packoffset(c20); - row_major float4x4 ProjMatrixUnjittered : packoffset(c24); - row_major float4x4 InvViewMatrix : packoffset(c28); - row_major float4x4 InvViewProjMatrix : packoffset(c32); - row_major float4x4 InvProjMatrix : packoffset(c36); - float4 CurrentPosAdjust : packoffset(c40); - float4 PreviousPosAdjust : packoffset(c41); - // notes: FirstPersonY seems 1.0 regardless of third/first person, could be LE legacy stuff - float4 GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW : packoffset(c42); - float4 DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW : packoffset(c43); - float4 DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW : packoffset(c44); + row_major float4x4 ViewMatrix : packoffset(c0); + row_major float4x4 ProjMatrix : packoffset(c4); + row_major float4x4 ViewProjMatrix : packoffset(c8); + row_major float4x4 ViewProjMatrixUnjittered : packoffset(c12); + row_major float4x4 PreviousViewProjMatrixUnjittered : packoffset(c16); + row_major float4x4 InvProjMatrixUnjittered : packoffset(c20); + row_major float4x4 ProjMatrixUnjittered : packoffset(c24); + row_major float4x4 InvViewMatrix : packoffset(c28); + row_major float4x4 InvViewProjMatrix : packoffset(c32); + row_major float4x4 InvProjMatrix : packoffset(c36); + float4 CurrentPosAdjust : packoffset(c40); + float4 PreviousPosAdjust : packoffset(c41); + // notes: FirstPersonY seems 1.0 regardless of third/first person, could be LE legacy stuff + float4 GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW : packoffset(c42); + float4 DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW : packoffset(c43); + float4 DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW : packoffset(c44); } - -cbuffer PerTechnique : register(b0) +cbuffer PerTechnique : register(b0) { - float4 FogColor : packoffset(c0); // Color in xyz, invFrameBufferRange in w - float4 ColourOutputClamp : packoffset(c1); // fLightingOutputColourClampPostLit in x, fLightingOutputColourClampPostEnv in y, fLightingOutputColourClampPostSpec in z - float4 VPOSOffset : packoffset(c2); // ??? + float4 FogColor : packoffset(c0); // Color in xyz, invFrameBufferRange in w + float4 ColourOutputClamp : packoffset(c1); // fLightingOutputColourClampPostLit in x, fLightingOutputColourClampPostEnv in y, fLightingOutputColourClampPostSpec in z + float4 VPOSOffset : packoffset(c2); // ??? }; -cbuffer PerMaterial : register(b1) +cbuffer PerMaterial : register(b1) { - float4 LODTexParams : packoffset(c0); // TerrainTexOffset in xy, LodBlendingEnabled in z - float4 TintColor : packoffset(c1); - float4 EnvmapData : packoffset(c2); // fEnvmapScale in x, 1 or 0 in y depending of if has envmask - float4 ParallaxOccData : packoffset(c3); - float4 SpecularColor : packoffset(c4); // Shininess in w, color in xyz - float4 SparkleParams : packoffset(c5); - float4 MultiLayerParallaxData : packoffset(c6); // Layer thickness in x, refraction scale in y, uv scale in zw - float4 LightingEffectParams : packoffset(c7); // fSubSurfaceLightRolloff in x, fRimLightPower in y - float4 IBLParams : packoffset(c8); - float4 LandscapeTexture1to4IsSnow : packoffset(c9); - float4 LandscapeTexture5to6IsSnow : packoffset(c10); // bEnableSnowMask in z, inverse iLandscapeMultiNormalTilingFactor in w - float4 LandscapeTexture1to4IsSpecPower : packoffset(c11); - float4 LandscapeTexture5to6IsSpecPower : packoffset(c12); - float4 SnowRimLightParameters : packoffset(c13); // fSnowRimLightIntensity in x, fSnowGeometrySpecPower in y, fSnowNormalSpecPower in z, bEnableSnowRimLighting in w - float4 CharacterLightParams : packoffset(c14); + float4 LODTexParams : packoffset(c0); // TerrainTexOffset in xy, LodBlendingEnabled in z + float4 TintColor : packoffset(c1); + float4 EnvmapData : packoffset(c2); // fEnvmapScale in x, 1 or 0 in y depending of if has envmask + float4 ParallaxOccData : packoffset(c3); + float4 SpecularColor : packoffset(c4); // Shininess in w, color in xyz + float4 SparkleParams : packoffset(c5); + float4 MultiLayerParallaxData : packoffset(c6); // Layer thickness in x, refraction scale in y, uv scale in zw + float4 LightingEffectParams : packoffset(c7); // fSubSurfaceLightRolloff in x, fRimLightPower in y + float4 IBLParams : packoffset(c8); + float4 LandscapeTexture1to4IsSnow : packoffset(c9); + float4 LandscapeTexture5to6IsSnow : packoffset(c10); // bEnableSnowMask in z, inverse iLandscapeMultiNormalTilingFactor in w + float4 LandscapeTexture1to4IsSpecPower : packoffset(c11); + float4 LandscapeTexture5to6IsSpecPower : packoffset(c12); + float4 SnowRimLightParameters : packoffset(c13); // fSnowRimLightIntensity in x, fSnowGeometrySpecPower in y, fSnowNormalSpecPower in z, bEnableSnowRimLighting in w + float4 CharacterLightParams : packoffset(c14); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - float3 DirLightDirection : packoffset(c0); - float3 DirLightColor : packoffset(c1); - float4 ShadowLightMaskSelect : packoffset(c2); - float4 MaterialData : packoffset(c3); // envmapLODFade in x, specularLODFade in y, alpha in z - float AlphaTestRef : packoffset(c4); - float3 EmitColor : packoffset(c4.y); - float4 ProjectedUVParams : packoffset(c6); - float4 SSRParams : packoffset(c7); - float4 WorldMapOverlayParametersPS : packoffset(c8); - float4 ProjectedUVParams2 : packoffset(c9); - float4 ProjectedUVParams3 : packoffset(c10); // fProjectedUVDiffuseNormalTilingScale in x, fProjectedUVNormalDetailTilingScale in y, EnableProjectedNormals in w - row_major float3x4 DirectionalAmbient : packoffset(c11); - float4 AmbientSpecularTintAndFresnelPower : packoffset(c14); // Fresnel power in z, color in xyz - float4 PointLightPosition[7] : packoffset(c15); // point light radius in w - float4 PointLightColor[7] : packoffset(c22); - float2 NumLightNumShadowLight : packoffset(c29); + float3 DirLightDirection : packoffset(c0); + float3 DirLightColor : packoffset(c1); + float4 ShadowLightMaskSelect : packoffset(c2); + float4 MaterialData : packoffset(c3); // envmapLODFade in x, specularLODFade in y, alpha in z + float AlphaTestRef : packoffset(c4); + float3 EmitColor : packoffset(c4.y); + float4 ProjectedUVParams : packoffset(c6); + float4 SSRParams : packoffset(c7); + float4 WorldMapOverlayParametersPS : packoffset(c8); + float4 ProjectedUVParams2 : packoffset(c9); + float4 ProjectedUVParams3 : packoffset(c10); // fProjectedUVDiffuseNormalTilingScale in x, fProjectedUVNormalDetailTilingScale in y, EnableProjectedNormals in w + row_major float3x4 DirectionalAmbient : packoffset(c11); + float4 AmbientSpecularTintAndFresnelPower : packoffset(c14); // Fresnel power in z, color in xyz + float4 PointLightPosition[7] : packoffset(c15); // point light radius in w + float4 PointLightColor[7] : packoffset(c22); + float2 NumLightNumShadowLight : packoffset(c29); }; -cbuffer AlphaTestRefBuffer : register(b11) +cbuffer AlphaTestRefBuffer : register(b11) { - float AlphaThreshold : packoffset(c0); + float AlphaThreshold : packoffset(c0); } float GetSoftLightMultiplier(float angle) { - float softLightParam = saturate((LightingEffectParams.x + angle) / (1 + LightingEffectParams.x)); + float softLightParam = saturate((LightingEffectParams.x + angle) / (1 + LightingEffectParams.x)); float arg1 = (softLightParam * softLightParam) * (3 - 2 * softLightParam); - float clampedAngle = saturate(angle); + float clampedAngle = saturate(angle); float arg2 = (clampedAngle * clampedAngle) * (3 - 2 * clampedAngle); - float softLigtMul = saturate(arg1 - arg2); - return softLigtMul; + float softLigtMul = saturate(arg1 - arg2); + return softLigtMul; } float GetRimLightMultiplier(float3 L, float3 V, float3 N) { - float NdotV = saturate(dot(N, V)); - return exp2(LightingEffectParams.y * log2(1 - NdotV)) * saturate(dot(V, -L)); + float NdotV = saturate(dot(N, V)); + return exp2(LightingEffectParams.y * log2(1 - NdotV)) * saturate(dot(V, -L)); } float ProcessSparkleColor(float color) @@ -662,129 +658,126 @@ float ProcessSparkleColor(float color) float3 GetLightSpecularInput(PS_INPUT input, float3 L, float3 V, float3 N, float3 lightColor, float shininess, float2 uv) { - float3 H = normalize(V + L); -#if defined (ANISO_LIGHTING) + float3 H = normalize(V + L); +# if defined(ANISO_LIGHTING) float3 AN = normalize(N * 0.5 + float3(input.TBN0.z, input.TBN1.z, input.TBN2.z)); float LdotAN = dot(AN, L); float HdotAN = dot(AN, H); float HdotN = 1 - min(1, abs(LdotAN - HdotAN)); -#else - float HdotN = saturate(dot(H, N)); -#endif -#if defined (SPECULAR) - float lightColorMultiplier = exp2(shininess * log2(HdotN)); -#elif defined (SPARKLE) +# else + float HdotN = saturate(dot(H, N)); +# endif +# if defined(SPECULAR) + float lightColorMultiplier = exp2(shininess * log2(HdotN)); +# elif defined(SPARKLE) float lightColorMultiplier = 0; -#else +# else float lightColorMultiplier = HdotN; -#endif -#if defined (ANISO_LIGHTING) +# endif +# if defined(ANISO_LIGHTING) lightColorMultiplier *= 0.7 * max(0, L.z); -#endif -#if defined (SPARKLE) && !defined(SNOW) +# endif +# if defined(SPARKLE) && !defined(SNOW) float3 sparkleUvScale = exp2(float3(1.3, 1.6, 1.9) * log2(abs(SparkleParams.x)).xxx); float sparkleColor1 = TexProjDetail.Sample(SampProjDetailSampler, uv * sparkleUvScale.xx).z; float sparkleColor2 = TexProjDetail.Sample(SampProjDetailSampler, uv * sparkleUvScale.yy).z; float sparkleColor3 = TexProjDetail.Sample(SampProjDetailSampler, uv * sparkleUvScale.zz).z; - float sparkleColor = ProcessSparkleColor(sparkleColor1) - + ProcessSparkleColor(sparkleColor2) - + ProcessSparkleColor(sparkleColor3); + float sparkleColor = ProcessSparkleColor(sparkleColor1) + ProcessSparkleColor(sparkleColor2) + ProcessSparkleColor(sparkleColor3); float VdotN = dot(V, N); V += N * -(2 * VdotN); float sparkleMultiplier = exp2(SparkleParams.w * log2(saturate(dot(V, -L)))) * (SparkleParams.z * sparkleColor); sparkleMultiplier = sparkleMultiplier >= 0.5 ? 1 : 0; lightColorMultiplier += sparkleMultiplier * HdotN; -#endif - return lightColor * lightColorMultiplier.xxx; +# endif + return lightColor * lightColorMultiplier.xxx; } float3 TransformNormal(float3 normal) { - return normal * 2 + -1.0.xxx; + return normal * 2 + -1.0.xxx; } float3 fresnelSchlick(float cosTheta, float3 F0) { - return F0 + (1 - F0) * pow(saturate(1 - cosTheta), 5); + return F0 + (1 - F0) * pow(saturate(1 - cosTheta), 5); } static const float PI = 3.14159265; float DistributionGGX(float NdotH, float roughness) { - float a = roughness * roughness; - float a2 = a * a; - float NdotH2 = NdotH * NdotH; - - float num = a2; - float denom = (NdotH2 * (a2 - 1) + 1); - denom = PI * denom * denom; - - return num / denom; + float a = roughness * roughness; + float a2 = a * a; + float NdotH2 = NdotH * NdotH; + + float num = a2; + float denom = (NdotH2 * (a2 - 1) + 1); + denom = PI * denom * denom; + + return num / denom; } float GeometrySchlickGGX(float cosTheta, float roughness) { - float r = (roughness + 1); - float k = (r * r) / 8; + float r = (roughness + 1); + float k = (r * r) / 8; + + float num = cosTheta; + float denom = cosTheta * (1 - k) + k; - float num = cosTheta; - float denom = cosTheta * (1 - k) + k; - - return num / denom; + return num / denom; } float GeometrySmith(float NdotV, float NdotL, float roughness) { - float ggxV = GeometrySchlickGGX(NdotV, roughness); - float ggxL = GeometrySchlickGGX(NdotL, roughness); - - return ggxV * ggxL; + float ggxV = GeometrySchlickGGX(NdotV, roughness); + float ggxL = GeometrySchlickGGX(NdotL, roughness); + + return ggxV * ggxL; } float OrenNayarDiffuseCoefficient(float roughness, float3 N, float3 L, float3 V, float NdotL, float NdotV) { - float gamma = dot(V - N * NdotV, L - N * NdotL); - float a = roughness * roughness; - float A = 1 - 0.5 * (a / (a + 0.57)); - float B = 0.45 * (a / (a + 0.09)); - float C = sqrt((1 - NdotV * NdotV) * (1 - NdotL * NdotL)) / max(NdotV, NdotL); - return (A + B * max(0.0f, gamma) * C) / PI; - + float gamma = dot(V - N * NdotV, L - N * NdotL); + float a = roughness * roughness; + float A = 1 - 0.5 * (a / (a + 0.57)); + float B = 0.45 * (a / (a + 0.09)); + float C = sqrt((1 - NdotV * NdotV) * (1 - NdotL * NdotL)) / max(NdotV, NdotL); + return (A + B * max(0.0f, gamma) * C) / PI; } float3 GetLightRadiance(float3 N, float3 L, float3 V, float3 F0, float3 originalRadiance, float3 albedo, float roughness, float metallic) { - float3 radiance = PI * originalRadiance; - - float3 H = normalize(V + L); - float NdotL = dot(N, L); - float NdotV = dot(N, V); - float HdotV = dot(H, V); - float NdotH = dot(N, H); - - float NDF = DistributionGGX(saturate(NdotH), roughness); - float G = GeometrySmith(saturate(NdotV), saturate(NdotL), roughness); - float3 F = fresnelSchlick(saturate(HdotV), F0); - - float3 kD = (1 - F) * (1 - metallic); - - float3 numerator = NDF * G * F; - float denominator = 4 * saturate(NdotV) * saturate(NdotL) + 0.0001; - float3 specular = numerator / denominator; - - float diffuseValue = OrenNayarDiffuseCoefficient(roughness, N, L, V, NdotL, NdotV); - return (kD * diffuseValue * albedo + specular) * saturate(NdotL) * radiance; + float3 radiance = PI * originalRadiance; + + float3 H = normalize(V + L); + float NdotL = dot(N, L); + float NdotV = dot(N, V); + float HdotV = dot(H, V); + float NdotH = dot(N, H); + + float NDF = DistributionGGX(saturate(NdotH), roughness); + float G = GeometrySmith(saturate(NdotV), saturate(NdotL), roughness); + float3 F = fresnelSchlick(saturate(HdotV), F0); + + float3 kD = (1 - F) * (1 - metallic); + + float3 numerator = NDF * G * F; + float denominator = 4 * saturate(NdotV) * saturate(NdotL) + 0.0001; + float3 specular = numerator / denominator; + + float diffuseValue = OrenNayarDiffuseCoefficient(roughness, N, L, V, NdotL, NdotV); + return (kD * diffuseValue * albedo + specular) * saturate(NdotL) * radiance; } float GetLodLandBlendParameter(float3 color) { float result = saturate(1.6666666 * (dot(color, 0.55.xxx) - 0.4)); result = ((result * result) * (3 - result * 2)); -#if !defined (WORLD_MAP) +# if !defined(WORLD_MAP) result *= 0.8; -#endif +# endif return result; } @@ -801,9 +794,8 @@ float GetLandSnowMaskValue(float alpha) float3 GetLandNormal(float landSnowMask, float3 normal, float2 uv, SamplerState sampNormal, Texture2D texNormal) { float3 landNormal = TransformNormal(normal); -#if defined (SNOW) - if (landSnowMask > 1e-5 && LandscapeTexture5to6IsSnow.w != 1.0) - { +# if defined(SNOW) + if (landSnowMask > 1e-5 && LandscapeTexture5to6IsSnow.w != 1.0) { float3 snowNormal = float3(-1, -1, 1) * TransformNormal(texNormal.Sample(sampNormal, LandscapeTexture5to6IsSnow.ww * uv).xyz); @@ -811,44 +803,37 @@ float3 GetLandNormal(float landSnowMask, float3 normal, float2 uv, SamplerState float normalProjection = dot(landNormal, snowNormal); snowNormal = landNormal * normalProjection.xxx - snowNormal * landNormal.z; return normalize(snowNormal); - } - else - { + } else { return landNormal; } -#else +# else return landNormal; -#endif +# endif } -#if defined (SNOW) +# if defined(SNOW) float3 GetSnowSpecularColor(PS_INPUT input, float3 modelNormal, float3 viewDirection) { - if (SnowRimLightParameters.w > 1e-5) - { -#if defined (MODELSPACENORMALS) && !defined(SKINNED) -#if defined (HAS_VIEW_VECTOR) + if (SnowRimLightParameters.w > 1e-5) { +# if defined(MODELSPACENORMALS) && !defined(SKINNED) +# if defined(HAS_VIEW_VECTOR) float3 modelGeometryNormal = float3(0, 0, 1); -#else +# else float3 modelGeometryNormal = 0.333333333.xxx; -#endif -#else +# endif +# else float3 modelGeometryNormal = normalize(float3(input.TBN0.z, input.TBN1.z, input.TBN2.z)); -#endif +# endif float normalFactor = 1 - saturate(dot(modelNormal, viewDirection)); float geometryNormalFactor = 1 - saturate(dot(modelGeometryNormal, viewDirection)); - return (SnowRimLightParameters.x - * (exp2(SnowRimLightParameters.y * log2(geometryNormalFactor)) - * exp2(SnowRimLightParameters.z * log2(normalFactor)))).xxx; - } - else - { + return (SnowRimLightParameters.x * (exp2(SnowRimLightParameters.y * log2(geometryNormalFactor)) * exp2(SnowRimLightParameters.z * log2(normalFactor)))).xxx; + } else { return 0.0.xxx; } } -#endif +# endif -#if defined (FACEGEN) +# if defined(FACEGEN) float3 GetFacegenBaseColor(float3 rawBaseColor, float2 uv) { float3 detailColor = TexDetailSampler.Sample(SampDetailSampler, uv).xyz; @@ -858,181 +843,177 @@ float3 GetFacegenBaseColor(float3 rawBaseColor, float2 uv) tintColor = tintColor - tintColor * rawBaseColor; return (rawBaseColor * rawBaseColor + tintColor) * detailColor; } -#endif +# endif -#if defined (FACEGEN_RGB_TINT) +# if defined(FACEGEN_RGB_TINT) float3 GetFacegenRGBTintBaseColor(float3 rawBaseColor, float2 uv) { float3 tintColor = TintColor.xyz * rawBaseColor * 2.0.xxx; tintColor = tintColor - tintColor * rawBaseColor; return float3(1.01171875, 0.99609375, 1.01171875) * (rawBaseColor * rawBaseColor + tintColor); } -#endif +# endif -#if defined (WORLD_MAP) +# if defined(WORLD_MAP) float3 GetWorldMapNormal(PS_INPUT input, float3 rawNormal, float3 baseColor) { float3 normal = normalize(rawNormal); -#if defined (MODELSPACENORMALS) +# if defined(MODELSPACENORMALS) float3 worldMapNormalSrc = normal.xyz; -#else +# else float3 worldMapNormalSrc = float3(input.TBN0.z, input.TBN1.z, input.TBN2.z); -#endif +# endif float3 worldMapNormal = 7.0.xxx * (-0.2.xxx + abs(normalize(worldMapNormalSrc))); worldMapNormal = max(0.01.xxx, worldMapNormal * worldMapNormal * worldMapNormal); worldMapNormal /= dot(worldMapNormal, 1.0.xxx); float3 worldMapColor1 = TexWorldMapOverlaySampler.Sample(SampWorldMapOverlaySampler, WorldMapOverlayParametersPS.xx * input.InputPosition.yz).xyz; float3 worldMapColor2 = TexWorldMapOverlaySampler.Sample(SampWorldMapOverlaySampler, WorldMapOverlayParametersPS.xx * input.InputPosition.xz).xyz; float3 worldMapColor3 = TexWorldMapOverlaySampler.Sample(SampWorldMapOverlaySampler, WorldMapOverlayParametersPS.xx * input.InputPosition.xy).xyz; -#if defined (LODLANDNOISE) || defined (LODLANDSCAPE) +# if defined(LODLANDNOISE) || defined(LODLANDSCAPE) float3 worldMapSnowColor1 = TexWorldMapOverlaySnowSampler.Sample(SampWorldMapOverlaySnowSampler, WorldMapOverlayParametersPS.ww * input.InputPosition.yz).xyz; float3 worldMapSnowColor2 = TexWorldMapOverlaySnowSampler.Sample(SampWorldMapOverlaySnowSampler, WorldMapOverlayParametersPS.ww * input.InputPosition.xz).xyz; float3 worldMapSnowColor3 = TexWorldMapOverlaySnowSampler.Sample(SampWorldMapOverlaySnowSampler, WorldMapOverlayParametersPS.ww * input.InputPosition.xy).xyz; -#endif +# endif float3 worldMapColor = worldMapNormal.xxx * worldMapColor1 + worldMapNormal.yyy * worldMapColor2 + worldMapNormal.zzz * worldMapColor3; -#if defined (LODLANDNOISE) || defined (LODLANDSCAPE) +# if defined(LODLANDNOISE) || defined(LODLANDSCAPE) float3 worldMapSnowColor = worldMapSnowColor1 * worldMapNormal.xxx + worldMapSnowColor2 * worldMapNormal.yyy + worldMapSnowColor3 * worldMapNormal.zzz; float snowMultiplier = GetLodLandBlendParameter(baseColor); worldMapColor = snowMultiplier * (worldMapSnowColor - worldMapColor) + worldMapColor; -#endif +# endif worldMapColor = normalize(2.0.xxx * (-0.5.xxx + (worldMapColor))); -#if defined (LODLANDNOISE) || defined (LODLANDSCAPE) +# if defined(LODLANDNOISE) || defined(LODLANDSCAPE) float worldMapLandTmp = saturate(19.9999962 * (rawNormal.z - 0.95)); worldMapLandTmp = saturate(-(worldMapLandTmp * worldMapLandTmp) * (worldMapLandTmp * -2 + 3) + 1.5); float3 worldMapLandTmp1 = normalize(normal.zxy * float3(1, 0, 0) - normal.yzx * float3(0, 0, 1)); float3 worldMapLandTmp2 = normalize(worldMapLandTmp1.yzx * normal.zxy - worldMapLandTmp1.zxy * normal.yzx); float3 worldMapLandTmp3 = normalize(worldMapColor.xxx * worldMapLandTmp1 + worldMapColor.yyy * worldMapLandTmp2 + worldMapColor.zzz * normal.xyz); float worldMapLandTmp4 = dot(worldMapLandTmp3, worldMapLandTmp3); - if (worldMapLandTmp4 > 0.999 && worldMapLandTmp4 < 1.001) - { + if (worldMapLandTmp4 > 0.999 && worldMapLandTmp4 < 1.001) { normal.xyz = worldMapLandTmp * (worldMapLandTmp3 - normal.xyz) + normal.xyz; } -#else +# else normal.xyz = normalize( WorldMapOverlayParametersPS.zzz * (rawNormal.xyz - worldMapColor.xyz) + worldMapColor.xyz); -#endif +# endif return normal; } float3 GetWorldMapBaseColor(float3 originalBaseColor, float3 rawBaseColor, float texProjTmp) { -#if defined(LODOBJECTS) && !defined(PROJECTED_UV) +# if defined(LODOBJECTS) && !defined(PROJECTED_UV) return rawBaseColor; -#endif -#if defined (LODLANDSCAPE) || defined(LODOBJECTSHD) || defined(LODLANDNOISE) +# endif +# if defined(LODLANDSCAPE) || defined(LODOBJECTSHD) || defined(LODLANDNOISE) float lodMultiplier = GetLodLandBlendParameter(originalBaseColor.xyz); -#elif defined (LODOBJECTS) && defined(PROJECTED_UV) +# elif defined(LODOBJECTS) && defined(PROJECTED_UV) float lodMultiplier = saturate(10 * texProjTmp); -#else +# else float lodMultiplier = 1; -#endif -#if defined (LODOBJECTS) +# endif +# if defined(LODOBJECTS) float4 lodColorMul = lodMultiplier.xxxx * float4(0.269999981, 0.281000018, 0.441000015, 0.441000015) + float4(0.0780000091, 0.09799999, -0.0349999964, 0.465000004); float4 lodColor = lodColorMul.xyzw * 2.0.xxxx; bool useLodColorZ = lodColorMul.w > 0.5; lodColor.xyz = max(lodColor.xyz, rawBaseColor.xyz); lodColor.w = useLodColorZ ? lodColor.z : min(lodColor.w, rawBaseColor.z); return (0.5 * lodMultiplier).xxx * (lodColor.xyw - rawBaseColor.xyz) + rawBaseColor; -#else +# else float4 lodColorMul = lodMultiplier.xxxx * float4(0.199999988, 0.441000015, 0.269999981, 0.281000018) + float4(0.300000012, 0.465000004, 0.0780000091, 0.09799999); float3 lodColor = lodColorMul.zwy * 2.0.xxx; lodColor.xy = max(lodColor.xy, rawBaseColor.xy); lodColor.z = lodColorMul.y > 0.5 ? max((lodMultiplier * 0.441 + -0.0349999964) * 2, rawBaseColor.z) : min(lodColor.z, rawBaseColor.z); return lodColorMul.xxx * (lodColor - rawBaseColor.xyz) + rawBaseColor; -#endif +# endif } -#endif +# endif float GetSnowParameterY(float texProjTmp, float alpha) { -#if defined (BASE_OBJECT_IS_SNOW) +# if defined(BASE_OBJECT_IS_SNOW) return min(1, texProjTmp + alpha); -#else +# else return texProjTmp; -#endif +# endif } -#if defined(COMPLEX_PARALLAX_MATERIALS) && (defined(PARALLAX) || defined(LANDSCAPE) || defined(ENVMAP)) - #define CPM_AVAILABLE -#endif +# if defined(COMPLEX_PARALLAX_MATERIALS) && (defined(PARALLAX) || defined(LANDSCAPE) || defined(ENVMAP)) +# define CPM_AVAILABLE +# endif -#if defined(CPM_AVAILABLE) - #include "ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli" -#endif +# if defined(CPM_AVAILABLE) +# include "ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli" +# endif -#if defined(SCREEN_SPACE_SHADOWS) - #include "ScreenSpaceShadows/ShadowsPS.hlsli" -#endif +# if defined(SCREEN_SPACE_SHADOWS) +# include "ScreenSpaceShadows/ShadowsPS.hlsli" +# endif -#if defined(WATER_BLENDING) -#include "WaterBlending/WaterBlending.hlsli" -#endif +# if defined(WATER_BLENDING) +# include "WaterBlending/WaterBlending.hlsli" +# endif PS_OUTPUT main(PS_INPUT input) { - PS_OUTPUT psout; + PS_OUTPUT psout; -#if defined (SKINNED) || !defined (MODELSPACENORMALS) - float3x3 tbn = float3x3(input.TBN0.xyz, input.TBN1.xyz, input.TBN2.xyz); -#endif +# if defined(SKINNED) || !defined(MODELSPACENORMALS) + float3x3 tbn = float3x3(input.TBN0.xyz, input.TBN1.xyz, input.TBN2.xyz); +# endif -#if defined (LANDSCAPE) - float shininess = dot(input.LandBlendWeights1, LandscapeTexture1to4IsSpecPower) - + input.LandBlendWeights2.x * LandscapeTexture5to6IsSpecPower.x - + input.LandBlendWeights2.y * LandscapeTexture5to6IsSpecPower.y; -#else +# if defined(LANDSCAPE) + float shininess = dot(input.LandBlendWeights1, LandscapeTexture1to4IsSpecPower) + input.LandBlendWeights2.x * LandscapeTexture5to6IsSpecPower.x + input.LandBlendWeights2.y * LandscapeTexture5to6IsSpecPower.y; +# else float shininess = SpecularColor.w; -#endif +# endif - float3 viewPosition = mul(ViewMatrix, float4(input.WorldPosition.xyz, 1)); + float3 viewPosition = mul(ViewMatrix, float4(input.WorldPosition.xyz, 1)); -#if defined(CPM_AVAILABLE) +# if defined(CPM_AVAILABLE) float parallaxShadowQuality = 1 - smoothstep(perPassParallax[0].ShadowsStartFade, perPassParallax[0].ShadowsEndFade, viewPosition.z); -#endif +# endif -#if defined (HAS_VIEW_VECTOR) -//#if defined (SKINNED) -// float3 viewDirection = normalize(mul(tbn, input.ViewVector.xyz)); -//#else - float3 viewDirection = normalize(input.ViewVector.xyz); +# if defined(HAS_VIEW_VECTOR) + //#if defined (SKINNED) + // float3 viewDirection = normalize(mul(tbn, input.ViewVector.xyz)); + //#else + float3 viewDirection = normalize(input.ViewVector.xyz); //#endif -#else +# else float3 viewDirection = 0.57735026.xxx; -#endif +# endif float2 uv = input.TexCoord0.xy; float2 uvOriginal = uv; -#if defined(LANDSCAPE) +# if defined(LANDSCAPE) float mipLevel[6]; float sh0[6]; -#else +# else float mipLevel; float sh0; -#endif +# endif -#if defined(CPM_AVAILABLE) -#if defined (PARALLAX) - if (perPassParallax[0].EnableParallax){ +# if defined(CPM_AVAILABLE) +# if defined(PARALLAX) + if (perPassParallax[0].EnableParallax) { mipLevel = GetMipLevel(uv, TexParallaxSampler); uv = GetParallaxCoords(viewPosition.z, uv, mipLevel, viewDirection, tbn, TexParallaxSampler, SampParallaxSampler, 0); if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) sh0 = TexParallaxSampler.SampleLevel(SampParallaxSampler, uv, 0).x; } -#endif +# endif -#if defined(ENVMAP) - bool complexMaterial = false; - bool complexMaterialParallax = false; - float4 complexMaterialColor = 1; +# if defined(ENVMAP) + bool complexMaterial = false; + bool complexMaterialParallax = false; + float4 complexMaterialColor = 1; - if (perPassParallax[0].EnableComplexMaterial){ + if (perPassParallax[0].EnableComplexMaterial) { float envMaskTest = TexEnvMaskSampler.SampleLevel(SampEnvMaskSampler, uv, 15).w; complexMaterial = envMaskTest < (1.0f - (4.0f / 255.0f)); - if (complexMaterial) - { - if (envMaskTest > (4.0f / 255.0f)){ + if (complexMaterial) { + if (envMaskTest > (4.0f / 255.0f)) { complexMaterialParallax = true; mipLevel = GetMipLevel(uv, TexEnvMaskSampler); uv = GetParallaxCoords(viewPosition.z, uv, mipLevel, viewDirection, tbn, TexEnvMaskSampler, SampTerrainParallaxSampler, 3); @@ -1043,267 +1024,261 @@ PS_OUTPUT main(PS_INPUT input) complexMaterialColor = TexEnvMaskSampler.Sample(SampEnvMaskSampler, uv); } } -#endif -#endif +# endif +# endif -#if defined (SNOW) +# if defined(SNOW) bool useSnowSpecular = true; -#else +# else bool useSnowSpecular = false; -#endif +# endif -#if defined(SPARKLE) || !defined(PROJECTED_UV) +# if defined(SPARKLE) || !defined(PROJECTED_UV) bool useSnowDecalSpecular = true; -#else +# else bool useSnowDecalSpecular = false; -#endif - +# endif + float2 diffuseUv = uv; -#if defined (SPARKLE) +# if defined(SPARKLE) diffuseUv = ProjectedUVParams2.yy * input.TexCoord0.zw; -#endif +# endif -#if defined(CPM_AVAILABLE) +# if defined(CPM_AVAILABLE) -#if defined(LANDSCAPE) +# if defined(LANDSCAPE) float2 terrainUVs[6]; - if (perPassParallax[0].EnableTerrainParallax && input.LandBlendWeights1.x > 0.0){ + if (perPassParallax[0].EnableTerrainParallax && input.LandBlendWeights1.x > 0.0) { mipLevel[0] = GetMipLevel(uv, TexColorSampler); uv = GetParallaxCoords(viewPosition.z, uv, mipLevel[0], viewDirection, tbn, TexColorSampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.x); terrainUVs[0] = uv; if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) sh0[0] = TexColorSampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; } -#endif +# endif -#if defined(SPARKLE) +# if defined(SPARKLE) diffuseUv = ProjectedUVParams2.yy * (input.TexCoord0.zw + (uv - uvOriginal)); -#else +# else diffuseUv = uv; -#endif -#endif - -float4 baseColor = 0; -float4 normal = 0; -float4 glossiness = 0; - -#if defined(LANDSCAPE) - if (input.LandBlendWeights1.x > 0.0) - { -#endif - - float4 rawBaseColor = TexColorSampler.Sample(SampColorSampler, diffuseUv); - - baseColor = rawBaseColor; - - float landSnowMask1 = GetLandSnowMaskValue(baseColor.w); - float4 normalColor = TexNormalSampler.Sample(SampNormalSampler, uv); - - normal = normalColor; -#if defined (MODELSPACENORMALS) -#if defined (LODLANDNOISE) - normal.xyz = normal.xzy - 0.5.xxx; - float lodLandNoiseParameter = GetLodLandBlendParameter(baseColor.xyz); - float noise = TexLandLodNoiseSampler.Sample(SampLandLodNoiseSampler, uv * 3.0.xx).x; - float lodLandNoiseMultiplier = GetLodLandBlendMultiplier(lodLandNoiseParameter, noise); - baseColor.xyz *= lodLandNoiseMultiplier; - normal.xyz *= 2; - normal.w = 1; - glossiness = 0; -#elif defined (LODLANDSCAPE) - normal.xyz = 2.0.xxx * (-0.5.xxx + normal.xzy); - normal.w = 1; - glossiness = 0; -#else - normal.xyz = normal.xzy * 2.0.xxx + -1.0.xxx; - normal.w = 1; - glossiness = TexSpecularSampler.Sample(SampSpecularSampler, uv).x; -#endif -#elif (defined (SNOW) && defined(LANDSCAPE)) +# endif +# endif + + float4 baseColor = 0; + float4 normal = 0; + float4 glossiness = 0; + +# if defined(LANDSCAPE) + if (input.LandBlendWeights1.x > 0.0) { +# endif + + float4 rawBaseColor = TexColorSampler.Sample(SampColorSampler, diffuseUv); + + baseColor = rawBaseColor; + + float landSnowMask1 = GetLandSnowMaskValue(baseColor.w); + float4 normalColor = TexNormalSampler.Sample(SampNormalSampler, uv); + + normal = normalColor; +# if defined(MODELSPACENORMALS) +# if defined(LODLANDNOISE) + normal.xyz = normal.xzy - 0.5.xxx; + float lodLandNoiseParameter = GetLodLandBlendParameter(baseColor.xyz); + float noise = TexLandLodNoiseSampler.Sample(SampLandLodNoiseSampler, uv * 3.0.xx).x; + float lodLandNoiseMultiplier = GetLodLandBlendMultiplier(lodLandNoiseParameter, noise); + baseColor.xyz *= lodLandNoiseMultiplier; + normal.xyz *= 2; + normal.w = 1; + glossiness = 0; +# elif defined(LODLANDSCAPE) + normal.xyz = 2.0.xxx * (-0.5.xxx + normal.xzy); + normal.w = 1; + glossiness = 0; +# else + normal.xyz = normal.xzy * 2.0.xxx + -1.0.xxx; + normal.w = 1; + glossiness = TexSpecularSampler.Sample(SampSpecularSampler, uv).x; +# endif +# elif (defined(SNOW) && defined(LANDSCAPE)) normal.xyz = GetLandNormal(landSnowMask1, normal.xyz, uv, SampNormalSampler, TexNormalSampler); glossiness = normal.w; -#else - normal.xyz = TransformNormal(normal.xyz); - glossiness = normal.w; -#endif +# else + normal.xyz = TransformNormal(normal.xyz); + glossiness = normal.w; +# endif -#if defined (WORLD_MAP) - normal.xyz = GetWorldMapNormal(input, normal.xyz, rawBaseColor.xyz); -#endif +# if defined(WORLD_MAP) + normal.xyz = GetWorldMapNormal(input, normal.xyz, rawBaseColor.xyz); +# endif -#if defined(LANDSCAPE) - baseColor *= input.LandBlendWeights1.x; - normal *= input.LandBlendWeights1.x; - glossiness *= input.LandBlendWeights1.x; +# if defined(LANDSCAPE) + baseColor *= input.LandBlendWeights1.x; + normal *= input.LandBlendWeights1.x; + glossiness *= input.LandBlendWeights1.x; } -#endif +# endif -#if defined (CPM_AVAILABLE) && defined(ENVMAP) +# if defined(CPM_AVAILABLE) && defined(ENVMAP) float3 complexSpecular = 1.0f; - - if (complexMaterial){ + + if (complexMaterial) { complexMaterial = complexMaterialColor.y > (4.0f / 255.0f) && complexMaterialColor.y < (1 - (4.0f / 255.0f)); - if (complexMaterial){ + if (complexMaterial) { shininess = shininess * complexMaterialColor.y; complexSpecular = lerp(1.0f, baseColor.xyz, complexMaterialColor.z); } } -#endif - -#if defined (PBR) - //float3 rmaoColor = TexRMAOSampler.Sample(SampRMAOSampler, uv).xyz; - //float roughness = rmaoColor.x; - //float metallic = rmaoColor.y; - //float ao = rmaoColor.z; - - float roughness = 1 - glossiness; - float metallic = 0; -#if defined (ENVMAP) +# endif + +# if defined(PBR) + //float3 rmaoColor = TexRMAOSampler.Sample(SampRMAOSampler, uv).xyz; + //float roughness = rmaoColor.x; + //float metallic = rmaoColor.y; + //float ao = rmaoColor.z; + + float roughness = 1 - glossiness; + float metallic = 0; +# if defined(ENVMAP) float envMaskColor = TexEnvMaskSampler.Sample(SampEnvMaskSampler, uv).x; metallic = envMaskColor * EnvmapData.x; -#endif - float ao = 1; - - float3 F0 = 0.04.xxx; - F0 = lerp(F0, baseColor.xyz, metallic); - - float3 totalRadiance = 0.0.xxx; -#endif - -#if defined (FACEGEN) +# endif + float ao = 1; + + float3 F0 = 0.04.xxx; + F0 = lerp(F0, baseColor.xyz, metallic); + + float3 totalRadiance = 0.0.xxx; +# endif + +# if defined(FACEGEN) baseColor.xyz = GetFacegenBaseColor(baseColor.xyz, uv); -#elif defined(FACEGEN_RGB_TINT) +# elif defined(FACEGEN_RGB_TINT) baseColor.xyz = GetFacegenRGBTintBaseColor(baseColor.xyz, uv); -#endif - -#if defined (LANDSCAPE) +# endif -#if defined(SNOW) - float landSnowMask = LandscapeTexture1to4IsSnow.x * input.LandBlendWeights1.x; -#endif +# if defined(LANDSCAPE) -if (input.LandBlendWeights1.y > 0.0) -{ -#if defined(CPM_AVAILABLE) - if (perPassParallax[0].EnableTerrainParallax){ - mipLevel[1] = GetMipLevel(uvOriginal, TexLandColor2Sampler); - uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[1], viewDirection, tbn, TexLandColor2Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.y); - terrainUVs[1] = uv; - if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) - sh0[1] = TexLandColor2Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; +# if defined(SNOW) + float landSnowMask = LandscapeTexture1to4IsSnow.x * input.LandBlendWeights1.x; +# endif + + if (input.LandBlendWeights1.y > 0.0) { +# if defined(CPM_AVAILABLE) + if (perPassParallax[0].EnableTerrainParallax) { + mipLevel[1] = GetMipLevel(uvOriginal, TexLandColor2Sampler); + uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[1], viewDirection, tbn, TexLandColor2Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.y); + terrainUVs[1] = uv; + if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) + sh0[1] = TexLandColor2Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + } +# endif + float4 landColor2 = TexLandColor2Sampler.Sample(SampLandColor2Sampler, uv); + float landSnowMask2 = GetLandSnowMaskValue(landColor2.w); + baseColor += input.LandBlendWeights1.yyyy * landColor2; + float4 landNormal2 = TexLandNormal2Sampler.Sample(SampLandNormal2Sampler, uv); + landNormal2.xyz = GetLandNormal(landSnowMask2, landNormal2.xyz, uv, SampLandNormal2Sampler, TexLandNormal2Sampler); + normal.xyz += input.LandBlendWeights1.yyy * landNormal2.xyz; + glossiness += input.LandBlendWeights1.y * landNormal2.w; +# if defined(SNOW) + landSnowMask += LandscapeTexture1to4IsSnow.y * input.LandBlendWeights1.y * landSnowMask2; +# endif } -#endif - float4 landColor2 = TexLandColor2Sampler.Sample(SampLandColor2Sampler, uv); - float landSnowMask2 = GetLandSnowMaskValue(landColor2.w); - baseColor += input.LandBlendWeights1.yyyy * landColor2; - float4 landNormal2 = TexLandNormal2Sampler.Sample(SampLandNormal2Sampler, uv); - landNormal2.xyz = GetLandNormal(landSnowMask2, landNormal2.xyz, uv, SampLandNormal2Sampler, TexLandNormal2Sampler); - normal.xyz += input.LandBlendWeights1.yyy * landNormal2.xyz; - glossiness += input.LandBlendWeights1.y * landNormal2.w; -#if defined(SNOW) - landSnowMask += LandscapeTexture1to4IsSnow.y * input.LandBlendWeights1.y * landSnowMask2; -#endif -} -if (input.LandBlendWeights1.z > 0.0) -{ -#if defined(CPM_AVAILABLE) - if (perPassParallax[0].EnableTerrainParallax){ - mipLevel[2] = GetMipLevel(uvOriginal, TexLandColor3Sampler); - uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[2], viewDirection, tbn, TexLandColor3Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.z); - terrainUVs[2] = uv; - if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) - sh0[2] = TexLandColor3Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + if (input.LandBlendWeights1.z > 0.0) { +# if defined(CPM_AVAILABLE) + if (perPassParallax[0].EnableTerrainParallax) { + mipLevel[2] = GetMipLevel(uvOriginal, TexLandColor3Sampler); + uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[2], viewDirection, tbn, TexLandColor3Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.z); + terrainUVs[2] = uv; + if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) + sh0[2] = TexLandColor3Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + } +# endif + float4 landColor3 = TexLandColor3Sampler.Sample(SampLandColor3Sampler, uv); + float landSnowMask3 = GetLandSnowMaskValue(landColor3.w); + baseColor += input.LandBlendWeights1.zzzz * landColor3; + float4 landNormal3 = TexLandNormal3Sampler.Sample(SampLandNormal3Sampler, uv); + landNormal3.xyz = GetLandNormal(landSnowMask3, landNormal3.xyz, uv, SampLandNormal3Sampler, TexLandNormal3Sampler); + normal.xyz += input.LandBlendWeights1.zzz * landNormal3.xyz; + glossiness += input.LandBlendWeights1.z * landNormal3.w; +# if defined(SNOW) + landSnowMask += LandscapeTexture1to4IsSnow.z * input.LandBlendWeights1.z * landSnowMask3; +# endif } -#endif - float4 landColor3 = TexLandColor3Sampler.Sample(SampLandColor3Sampler, uv); - float landSnowMask3 = GetLandSnowMaskValue(landColor3.w); - baseColor += input.LandBlendWeights1.zzzz * landColor3; - float4 landNormal3 = TexLandNormal3Sampler.Sample(SampLandNormal3Sampler, uv); - landNormal3.xyz = GetLandNormal(landSnowMask3, landNormal3.xyz, uv, SampLandNormal3Sampler, TexLandNormal3Sampler); - normal.xyz += input.LandBlendWeights1.zzz * landNormal3.xyz; - glossiness += input.LandBlendWeights1.z * landNormal3.w; -#if defined(SNOW) - landSnowMask += LandscapeTexture1to4IsSnow.z * input.LandBlendWeights1.z * landSnowMask3; -#endif -} -if (input.LandBlendWeights1.w > 0.0) -{ -#if defined(CPM_AVAILABLE) - if (perPassParallax[0].EnableTerrainParallax){ - mipLevel[3] = GetMipLevel(uvOriginal, TexLandColor4Sampler); - uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[3], viewDirection, tbn, TexLandColor4Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.w); - terrainUVs[3] = uv; - if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) - sh0[3] = TexLandColor4Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + if (input.LandBlendWeights1.w > 0.0) { +# if defined(CPM_AVAILABLE) + if (perPassParallax[0].EnableTerrainParallax) { + mipLevel[3] = GetMipLevel(uvOriginal, TexLandColor4Sampler); + uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[3], viewDirection, tbn, TexLandColor4Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights1.w); + terrainUVs[3] = uv; + if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) + sh0[3] = TexLandColor4Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + } +# endif + float4 landColor4 = TexLandColor4Sampler.Sample(SampLandColor4Sampler, uv); + float landSnowMask4 = GetLandSnowMaskValue(landColor4.w); + baseColor += input.LandBlendWeights1.wwww * landColor4; + float4 landNormal4 = TexLandNormal4Sampler.Sample(SampLandNormal4Sampler, uv); + landNormal4.xyz = GetLandNormal(landSnowMask4, landNormal4.xyz, uv, SampLandNormal4Sampler, TexLandNormal4Sampler); + normal.xyz += input.LandBlendWeights1.www * landNormal4.xyz; + glossiness += input.LandBlendWeights1.w * landNormal4.w; +# if defined(SNOW) + landSnowMask += LandscapeTexture1to4IsSnow.w * input.LandBlendWeights1.w * landSnowMask4; +# endif } -#endif - float4 landColor4 = TexLandColor4Sampler.Sample(SampLandColor4Sampler, uv); - float landSnowMask4 = GetLandSnowMaskValue(landColor4.w); - baseColor += input.LandBlendWeights1.wwww * landColor4; - float4 landNormal4 = TexLandNormal4Sampler.Sample(SampLandNormal4Sampler, uv); - landNormal4.xyz = GetLandNormal(landSnowMask4, landNormal4.xyz, uv, SampLandNormal4Sampler, TexLandNormal4Sampler); - normal.xyz += input.LandBlendWeights1.www * landNormal4.xyz; - glossiness += input.LandBlendWeights1.w * landNormal4.w; -#if defined(SNOW) - landSnowMask += LandscapeTexture1to4IsSnow.w * input.LandBlendWeights1.w * landSnowMask4; -#endif -} -if (input.LandBlendWeights2.x > 0.0) -{ -#if defined(CPM_AVAILABLE) - if (perPassParallax[0].EnableTerrainParallax){ - mipLevel[4] = GetMipLevel(uvOriginal, TexLandColor5Sampler); - uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[4], viewDirection, tbn, TexLandColor5Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights2.x); - terrainUVs[4] = uv; - if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) - sh0[4] = TexLandColor5Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + if (input.LandBlendWeights2.x > 0.0) { +# if defined(CPM_AVAILABLE) + if (perPassParallax[0].EnableTerrainParallax) { + mipLevel[4] = GetMipLevel(uvOriginal, TexLandColor5Sampler); + uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[4], viewDirection, tbn, TexLandColor5Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights2.x); + terrainUVs[4] = uv; + if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) + sh0[4] = TexLandColor5Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + } +# endif + float4 landColor5 = TexLandColor5Sampler.Sample(SampLandColor5Sampler, uv); + float landSnowMask5 = GetLandSnowMaskValue(landColor5.w); + baseColor += input.LandBlendWeights2.xxxx * landColor5; + float4 landNormal5 = TexLandNormal5Sampler.Sample(SampLandNormal5Sampler, uv); + landNormal5.xyz = GetLandNormal(landSnowMask5, landNormal5.xyz, uv, SampLandNormal5Sampler, TexLandNormal5Sampler); + normal.xyz += input.LandBlendWeights2.xxx * landNormal5.xyz; + glossiness += input.LandBlendWeights2.x * landNormal5.w; +# if defined(SNOW) + landSnowMask += LandscapeTexture5to6IsSnow.x * input.LandBlendWeights2.x * landSnowMask5; +# endif } -#endif - float4 landColor5 = TexLandColor5Sampler.Sample(SampLandColor5Sampler, uv); - float landSnowMask5 = GetLandSnowMaskValue(landColor5.w); - baseColor += input.LandBlendWeights2.xxxx * landColor5; - float4 landNormal5 = TexLandNormal5Sampler.Sample(SampLandNormal5Sampler, uv); - landNormal5.xyz = GetLandNormal(landSnowMask5, landNormal5.xyz, uv, SampLandNormal5Sampler, TexLandNormal5Sampler); - normal.xyz += input.LandBlendWeights2.xxx * landNormal5.xyz; - glossiness += input.LandBlendWeights2.x * landNormal5.w; -#if defined(SNOW) - landSnowMask += LandscapeTexture5to6IsSnow.x * input.LandBlendWeights2.x * landSnowMask5; -#endif -} -if (input.LandBlendWeights2.y > 0.0) -{ -#if defined(CPM_AVAILABLE) - if (perPassParallax[0].EnableTerrainParallax){ - mipLevel[5] = GetMipLevel(uvOriginal, TexLandColor6Sampler); - uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[5], viewDirection, tbn, TexLandColor6Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights2.y); - terrainUVs[5] = uv; - if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) - sh0[5] = TexLandColor6Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + if (input.LandBlendWeights2.y > 0.0) { +# if defined(CPM_AVAILABLE) + if (perPassParallax[0].EnableTerrainParallax) { + mipLevel[5] = GetMipLevel(uvOriginal, TexLandColor6Sampler); + uv = GetParallaxCoords(viewPosition.z, uvOriginal, mipLevel[5], viewDirection, tbn, TexLandColor6Sampler, SampTerrainParallaxSampler, 3, input.LandBlendWeights2.y); + terrainUVs[5] = uv; + if (perPassParallax[0].EnableShadows && parallaxShadowQuality > 0.0f) + sh0[5] = TexLandColor6Sampler.SampleLevel(SampTerrainParallaxSampler, uv, 0).w; + } +# endif + float4 landColor6 = TexLandColor6Sampler.Sample(SampLandColor6Sampler, uv); + float landSnowMask6 = GetLandSnowMaskValue(landColor6.w); + baseColor += input.LandBlendWeights2.yyyy * landColor6; + float4 landNormal6 = TexLandNormal6Sampler.Sample(SampLandNormal6Sampler, uv); + landNormal6.xyz = GetLandNormal(landSnowMask6, landNormal6.xyz, uv, SampLandNormal6Sampler, TexLandNormal6Sampler); + normal.xyz += input.LandBlendWeights2.yyy * landNormal6.xyz; + glossiness += input.LandBlendWeights2.y * landNormal6.w; +# if defined(SNOW) + landSnowMask += LandscapeTexture5to6IsSnow.y * input.LandBlendWeights2.y * landSnowMask6; +# endif } -#endif - float4 landColor6 = TexLandColor6Sampler.Sample(SampLandColor6Sampler, uv); - float landSnowMask6 = GetLandSnowMaskValue(landColor6.w); - baseColor += input.LandBlendWeights2.yyyy * landColor6; - float4 landNormal6 = TexLandNormal6Sampler.Sample(SampLandNormal6Sampler, uv); - landNormal6.xyz = GetLandNormal(landSnowMask6, landNormal6.xyz, uv, SampLandNormal6Sampler, TexLandNormal6Sampler); - normal.xyz += input.LandBlendWeights2.yyy * landNormal6.xyz; - glossiness += input.LandBlendWeights2.y * landNormal6.w; -#if defined(SNOW) - landSnowMask += LandscapeTexture5to6IsSnow.y * input.LandBlendWeights2.y * landSnowMask6; -#endif -} - -#if defined (LOD_LAND_BLEND) + +# if defined(LOD_LAND_BLEND) float4 lodBlendColor = TexLandLodBlend1Sampler.Sample(SampLandLodBlend1Sampler, input.TexCoord0.zw); -#endif +# endif -#if defined (LOD_LAND_BLEND) +# if defined(LOD_LAND_BLEND) float lodBlendTmp = GetLodLandBlendParameter(lodBlendColor.xyz); float lodBlendMask = TexLandLodBlend2Sampler.Sample(SampLandLodBlend2Sampler, 3.0.xx * input.TexCoord0.zw).x; float lodBlendMul1 = GetLodLandBlendMultiplier(lodBlendTmp, lodBlendMask); @@ -1312,83 +1287,79 @@ if (input.LandBlendWeights2.y > 0.0) baseColor = lodBlendMul2.xxxx * (lodBlendColor * lodBlendMul1.xxxx - baseColor) + baseColor; normal.xyz = lodBlendMul2.xxx * (float3(0, 0, 1) - normal.xyz) + normal.xyz; glossiness += lodBlendMul2 * -glossiness; -#endif +# endif -#if defined (SNOW) +# if defined(SNOW) useSnowSpecular = landSnowMask > 0; -#endif -#endif - -#if defined (BACK_LIGHTING) +# endif +# endif + +# if defined(BACK_LIGHTING) float4 backLightColor = TexBackLightSampler.Sample(SampBackLightSampler, uv); -#endif -#if defined (SOFT_LIGHTING) || defined(RIM_LIGHTING) +# endif +# if defined(SOFT_LIGHTING) || defined(RIM_LIGHTING) float4 rimSoftLightColor = TexRimSoftLightSampler.Sample(SampRimSoftLightSampler, uv); -#endif - - float numLights = min(7, NumLightNumShadowLight.x); -#if defined (DEFSHADOW) +# endif + + float numLights = min(7, NumLightNumShadowLight.x); +# if defined(DEFSHADOW) float numShadowLights = min(4, NumLightNumShadowLight.y); -#endif - +# endif -#if defined (MODELSPACENORMALS) && !defined (SKINNED) +# if defined(MODELSPACENORMALS) && !defined(SKINNED) float4 modelNormal = normal; -#else - float4 modelNormal = float4(normalize(mul(tbn, normal.xyz)), 1); +# else + float4 modelNormal = float4(normalize(mul(tbn, normal.xyz)), 1); -#if defined (SPARKLE) +# if defined(SPARKLE) float3 projectedNormal = normalize(mul(tbn, float3(ProjectedUVParams2.xx * normal.xy, normal.z))); -#endif -#endif - - float2 baseShadowUV = 1.0.xx; -#if defined (DEFSHADOW) +# endif +# endif + + float2 baseShadowUV = 1.0.xx; +# if defined(DEFSHADOW) float4 shadowColor; -#if !defined (SHADOW_DIR) +# if !defined(SHADOW_DIR) if (numShadowLights > 0) -#endif +# endif { baseShadowUV = input.Position.xy * DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW.xy; float2 shadowUV = min(float2(DynamicRes_InvWidthX_InvHeightY_WidthClampZ_HeightClampW.z, DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW.y), max(0.0.xx, DynamicRes_WidthX_HeightY_PreviousWidthZ_PreviousHeightW.xy * (baseShadowUV * VPOSOffset.xy + VPOSOffset.zw))); shadowColor = TexShadowMaskSampler.Sample(SampShadowMaskSampler, shadowUV); } -#if !defined (SHADOW_DIR) - else - { +# if !defined(SHADOW_DIR) + else { shadowColor = 1.0.xxxx; } -#endif -#endif +# endif +# endif float texProjTmp = 0; -#if defined (PROJECTED_UV) +# if defined(PROJECTED_UV) float2 projNoiseUv = ProjectedUVParams.zz * input.TexCoord0.zw; float projNoise = TexProjNoiseSampler.Sample(SampProjNoiseSampler, projNoiseUv).x; float3 texProj = normalize(input.TexProj); -#if defined (TREE_ANIM) || defined (LODOBJECTSHD) +# if defined(TREE_ANIM) || defined(LODOBJECTSHD) float vertexAlpha = 1; -#else +# else float vertexAlpha = input.Color.w; -#endif +# endif texProjTmp = -ProjectedUVParams.x * projNoise + (dot(modelNormal.xyz, texProj) * vertexAlpha - ProjectedUVParams.w); -#if defined (LODOBJECTSHD) +# if defined(LODOBJECTSHD) texProjTmp += (-0.5 + input.Color.w) * 2.5; -#endif -#if defined (SPARKLE) - if (texProjTmp < 0) - { +# endif +# if defined(SPARKLE) + if (texProjTmp < 0) { discard; } modelNormal.xyz = projectedNormal; -#if defined (SNOW) +# if defined(SNOW) psout.SnowParameters.y = 1; -#endif -#else - if (ProjectedUVParams3.w > 0.5) - { +# endif +# else + if (ProjectedUVParams3.w > 0.5) { float2 projNormalUv = ProjectedUVParams3.x * projNoiseUv; float3 projNormal = TransformNormal(TexProjNormalSampler.Sample(SampProjNormalSampler, projNormalUv).xyz); float2 projDetailUv = ProjectedUVParams3.y * projNoiseUv; @@ -1404,247 +1375,232 @@ if (input.LandBlendWeights2.y > 0.0) baseColor.xyz = texProjTmp2.xxx * (projDiffuse * ProjectedUVParams2.xyz - baseColor.xyz) + baseColor.xyz; useSnowDecalSpecular = true; -#if defined (SNOW) +# if defined(SNOW) psout.SnowParameters.y = GetSnowParameterY(texProjTmp2, baseColor.w); -#endif - } - else - { - if (texProjTmp > 0) - { +# endif + } else { + if (texProjTmp > 0) { baseColor.xyz = ProjectedUVParams2.xyz; useSnowDecalSpecular = true; -#if defined (SNOW) +# if defined(SNOW) psout.SnowParameters.y = GetSnowParameterY(texProjTmp, baseColor.w); -#endif - } - else - { -#if defined (SNOW) +# endif + } else { +# if defined(SNOW) psout.SnowParameters.y = 0; -#endif +# endif } } -#if defined (SPECULAR) +# if defined(SPECULAR) useSnowSpecular = useSnowDecalSpecular; -#endif -#endif +# endif +# endif -#elif defined (SNOW) -#if defined (LANDSCAPE) +# elif defined(SNOW) +# if defined(LANDSCAPE) psout.SnowParameters.y = landSnowMask; -#else +# else psout.SnowParameters.y = baseColor.w; -#endif -#endif +# endif +# endif -#if defined (WORLD_MAP) +# if defined(WORLD_MAP) baseColor.xyz = GetWorldMapBaseColor(rawBaseColor.xyz, baseColor.xyz, texProjTmp); -#endif +# endif float3 dirLightColor = DirLightColor.xyz; float selfShadowFactor = 1.0f; float3 nsDirLightColor = dirLightColor; -#if defined (DEFSHADOW) && defined (SHADOW_DIR) +# if defined(DEFSHADOW) && defined(SHADOW_DIR) dirLightColor *= shadowColor.xxx; -#endif +# endif -#if defined(SCREEN_SPACE_SHADOWS) +# if defined(SCREEN_SPACE_SHADOWS) float dirLightSShadow = PrepassScreenSpaceShadows(input.WorldPosition); dirLightColor *= dirLightSShadow; -#endif +# endif -#if defined(CPM_AVAILABLE) && (defined (SKINNED) || !defined (MODELSPACENORMALS)) - float3 dirLightDirectionTS = mul(DirLightDirection, tbn).xyz; +# if defined(CPM_AVAILABLE) && (defined(SKINNED) || !defined(MODELSPACENORMALS)) + float3 dirLightDirectionTS = mul(DirLightDirection, tbn).xyz; bool dirLightIsLit = true; -#if defined (DEFSHADOW) && defined (SHADOW_DIR) +# if defined(DEFSHADOW) && defined(SHADOW_DIR) if (shadowColor.x == 0) dirLightIsLit = false; -#endif +# endif -#if defined(SCREEN_SPACE_SHADOWS) +# if defined(SCREEN_SPACE_SHADOWS) if (dirLightSShadow == 0) dirLightIsLit = false; -#endif +# endif -#if defined (LANDSCAPE) +# if defined(LANDSCAPE) if (perPassParallax[0].EnableTerrainParallax && perPassParallax[0].EnableShadows) - dirLightColor *= GetParallaxSoftShadowMultiplierTerrain(input, terrainUVs, mipLevel, dirLightDirectionTS, sh0, dirLightIsLit * parallaxShadowQuality); -#elif defined (PARALLAX) + dirLightColor *= GetParallaxSoftShadowMultiplierTerrain(input, terrainUVs, mipLevel, dirLightDirectionTS, sh0, dirLightIsLit * parallaxShadowQuality); +# elif defined(PARALLAX) if (perPassParallax[0].EnableParallax && perPassParallax[0].EnableShadows) - dirLightColor *= GetParallaxSoftShadowMultiplier(uv, mipLevel, dirLightDirectionTS, sh0, TexParallaxSampler, SampParallaxSampler, 0, dirLightIsLit * parallaxShadowQuality); -#elif defined(ENVMAP) - if (complexMaterialParallax && perPassParallax[0].EnableShadows) + dirLightColor *= GetParallaxSoftShadowMultiplier(uv, mipLevel, dirLightDirectionTS, sh0, TexParallaxSampler, SampParallaxSampler, 0, dirLightIsLit * parallaxShadowQuality); +# elif defined(ENVMAP) + if (complexMaterialParallax && perPassParallax[0].EnableShadows) dirLightColor *= GetParallaxSoftShadowMultiplier(uv, mipLevel, dirLightDirectionTS, sh0, TexEnvMaskSampler, SampEnvMaskSampler, 3, dirLightIsLit * parallaxShadowQuality); -#endif -#endif - -#if defined(PBR) - totalRadiance += GetLightRadiance(modelNormal.xyz, DirLightDirection.xyz, viewDirection, F0, dirLightColor.xyz, baseColor.xyz, roughness, metallic); -#else +# endif +# endif + +# if defined(PBR) + totalRadiance += GetLightRadiance(modelNormal.xyz, DirLightDirection.xyz, viewDirection, F0, dirLightColor.xyz, baseColor.xyz, roughness, metallic); +# else float3 diffuseColor = 0.0.xxx; float3 specularColor = 0.0.xxx; - + float3 lightsDiffuseColor = 0.0.xxx; float3 lightsSpecularColor = 0.0.xxx; - + float dirLightAngle = dot(modelNormal.xyz, DirLightDirection.xyz); float3 dirDiffuseColor = dirLightColor * saturate(dirLightAngle.xxx); - -#if defined (SOFT_LIGHTING) + +# if defined(SOFT_LIGHTING) lightsDiffuseColor += nsDirLightColor.xyz * GetSoftLightMultiplier(dirLightAngle) * rimSoftLightColor.xyz; -#endif - -#if defined (RIM_LIGHTING) +# endif + +# if defined(RIM_LIGHTING) lightsDiffuseColor += nsDirLightColor.xyz * GetRimLightMultiplier(DirLightDirection, viewDirection, modelNormal.xyz) * rimSoftLightColor.xyz; -#endif - -#if defined (BACK_LIGHTING) +# endif + +# if defined(BACK_LIGHTING) lightsDiffuseColor += nsDirLightColor.xyz * (saturate(-dirLightAngle) * backLightColor.xyz); -#endif +# endif - if (useSnowSpecular && useSnowDecalSpecular) - { -#if defined (SNOW) + if (useSnowSpecular && useSnowDecalSpecular) { +# if defined(SNOW) lightsSpecularColor = GetSnowSpecularColor(input, modelNormal.xyz, viewDirection); -#endif - } - else - { -#if defined (SPECULAR) || defined (SPARKLE) +# endif + } else { +# if defined(SPECULAR) || defined(SPARKLE) lightsSpecularColor = GetLightSpecularInput(input, DirLightDirection, viewDirection, modelNormal.xyz, dirLightColor.xyz, shininess, uv); -#endif +# endif } - + lightsDiffuseColor += dirDiffuseColor; -#endif - - if (numLights > 0) - { - for (float lightIndex = 0; lightIndex < numLights; ++lightIndex) - { -#if defined (DEFSHADOW) +# endif + + if (numLights > 0) { + for (float lightIndex = 0; lightIndex < numLights; ++lightIndex) { +# if defined(DEFSHADOW) float shadowComponent; - if (lightIndex < numShadowLights) - { + if (lightIndex < numShadowLights) { shadowComponent = shadowColor[ShadowLightMaskSelect[lightIndex]]; - } - else - { + } else { shadowComponent = 1; } -#endif +# endif int intLightIndex = lightIndex; - float3 lightDirection = PointLightPosition[intLightIndex].xyz - input.InputPosition.xyz; - float lightDist = length(lightDirection); - float intensityFactor = saturate(lightDist / PointLightPosition[intLightIndex].w); - float intensityMultiplier = 1 - intensityFactor * intensityFactor; + float3 lightDirection = PointLightPosition[intLightIndex].xyz - input.InputPosition.xyz; + float lightDist = length(lightDirection); + float intensityFactor = saturate(lightDist / PointLightPosition[intLightIndex].w); + float intensityMultiplier = 1 - intensityFactor * intensityFactor; if (!(intensityMultiplier > 0.0)) continue; - - float3 lightColor = PointLightColor[intLightIndex].xyz; + + float3 lightColor = PointLightColor[intLightIndex].xyz; float3 nsLightColor = lightColor; -#if defined (DEFSHADOW) +# if defined(DEFSHADOW) lightColor *= shadowComponent.xxx; -#endif - float3 normalizedLightDirection = normalize(lightDirection); - -#if defined(CPM_AVAILABLE) - if (perPassParallax[0].EnableShadows) - { - float3 lightDirectionTS = mul(normalizedLightDirection, tbn).xyz; - +# endif + float3 normalizedLightDirection = normalize(lightDirection); + +# if defined(CPM_AVAILABLE) + if (perPassParallax[0].EnableShadows) { + float3 lightDirectionTS = mul(normalizedLightDirection, tbn).xyz; + bool lightIsLit = true; -#if defined (DEFSHADOW) && defined (SHADOW_DIR) +# if defined(DEFSHADOW) && defined(SHADOW_DIR) if (shadowComponent.x == 0) lightIsLit = false; -#endif +# endif -#if defined(PARALLAX) - if (perPassParallax[0].EnableParallax) - lightColor *= GetParallaxSoftShadowMultiplier(uv, mipLevel, lightDirectionTS, sh0, TexParallaxSampler, SampParallaxSampler, 0, lightIsLit * parallaxShadowQuality); -#elif defined (LANDSCAPE) +# if defined(PARALLAX) + if (perPassParallax[0].EnableParallax) + lightColor *= GetParallaxSoftShadowMultiplier(uv, mipLevel, lightDirectionTS, sh0, TexParallaxSampler, SampParallaxSampler, 0, lightIsLit * parallaxShadowQuality); +# elif defined(LANDSCAPE) if (perPassParallax[0].EnableTerrainParallax) lightColor *= GetParallaxSoftShadowMultiplierTerrain(input, terrainUVs, mipLevel, lightDirectionTS, sh0, lightIsLit * parallaxShadowQuality); -#elif defined(ENVMAP) - if (complexMaterialParallax) +# elif defined(ENVMAP) + if (complexMaterialParallax) lightColor *= GetParallaxSoftShadowMultiplier(uv, mipLevel, lightDirectionTS, sh0, TexEnvMaskSampler, SampEnvMaskSampler, 3, lightIsLit * parallaxShadowQuality); -#endif - } -#endif +# endif + } +# endif - -#if defined(PBR) - totalRadiance += GetLightRadiance(modelNormal.xyz, normalizedLightDirection, viewDirection, F0, lightColor * intensityMultiplier.xxx, baseColor.xyz, roughness, metallic); -#else +# if defined(PBR) + totalRadiance += GetLightRadiance(modelNormal.xyz, normalizedLightDirection, viewDirection, F0, lightColor * intensityMultiplier.xxx, baseColor.xyz, roughness, metallic); +# else float lightAngle = dot(modelNormal.xyz, normalizedLightDirection.xyz); float3 lightDiffuseColor = lightColor * saturate(lightAngle.xxx); - -#if defined (SOFT_LIGHTING) + +# if defined(SOFT_LIGHTING) lightDiffuseColor += nsLightColor * GetSoftLightMultiplier(dot(modelNormal.xyz, lightDirection.xyz)) * rimSoftLightColor.xyz; -#endif - -#if defined (RIM_LIGHTING) +# endif + +# if defined(RIM_LIGHTING) lightDiffuseColor += nsLightColor * GetRimLightMultiplier(normalizedLightDirection, viewDirection, modelNormal.xyz) * rimSoftLightColor.xyz; -#endif - -#if defined (BACK_LIGHTING) +# endif + +# if defined(BACK_LIGHTING) lightDiffuseColor += (saturate(-lightAngle) * backLightColor.xyz) * nsLightColor; -#endif - -#if defined (SPECULAR) || (defined (SPARKLE) && !defined(SNOW)) +# endif + +# if defined(SPECULAR) || (defined(SPARKLE) && !defined(SNOW)) lightsSpecularColor += GetLightSpecularInput(input, normalizedLightDirection, viewDirection, modelNormal.xyz, lightColor, shininess, uv) * intensityMultiplier.xxx; -#endif - +# endif + lightsDiffuseColor += lightDiffuseColor * intensityMultiplier.xxx; -#endif - } - } - -#if defined (PBR) +# endif + } + } + +# if defined(PBR) //float3 ambientColor = 0.03 * baseColor.xyz * ao; - float3 ambientColor = (mul(DirectionalAmbient, modelNormal) + IBLParams.yzw * IBLParams.xxx) * baseColor.xyz * ao; - float3 color = ambientColor + totalRadiance; - + float3 ambientColor = (mul(DirectionalAmbient, modelNormal) + IBLParams.yzw * IBLParams.xxx) * baseColor.xyz * ao; + float3 color = ambientColor + totalRadiance; + //color = color / (color + 1.0); //color = pow(color, 1.0 / 2.2); -#else - +# else + diffuseColor += lightsDiffuseColor; specularColor += lightsSpecularColor; - -#if defined (CHARACTER_LIGHT) + +# if defined(CHARACTER_LIGHT) float charLightMul = saturate(dot(viewDirection, modelNormal.xyz)) * CharacterLightParams.x + CharacterLightParams.y * saturate(dot(float2(0.164398998, -0.986393988), modelNormal.yz)); float charLightColor = min(CharacterLightParams.w, max(0, CharacterLightParams.z * TexCharacterLightSampler.Sample(SampCharacterLightSampler, baseShadowUV).x)); diffuseColor += (charLightMul * charLightColor).xxx; -#endif +# endif -#if defined(EYE) +# if defined(EYE) modelNormal.xyz = input.EyeNormal; -#endif +# endif -#if defined (ENVMAP) || defined (MULTI_LAYER_PARALLAX) || defined(EYE) +# if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE) float envMaskColor = TexEnvMaskSampler.Sample(SampEnvMaskSampler, uv).x; float envMask = (EnvmapData.y * (envMaskColor - glossiness) + glossiness) * (EnvmapData.x * MaterialData.x); float viewNormalAngle = dot(modelNormal.xyz, viewDirection); float3 envSamplingPoint = (viewNormalAngle * 2) * modelNormal.xyz - viewDirection; float3 envColor = TexEnvSampler.Sample(SampEnvSampler, envSamplingPoint).xyz * envMask.xxx; -#endif - +# endif + float3 emitColor = EmitColor; -#if defined (GLOWMAP) +# if defined(GLOWMAP) float3 glowColor = TexGlowSampler.Sample(SampGlowSampler, uv).xyz; emitColor *= glowColor; -#endif - +# endif + float3 directionalAmbientColor = mul(DirectionalAmbient, modelNormal); diffuseColor = directionalAmbientColor + emitColor.xyz + diffuseColor; diffuseColor += IBLParams.yzw * IBLParams.xxx; @@ -1652,101 +1608,97 @@ if (input.LandBlendWeights2.y > 0.0) float4 color; color.xyz = diffuseColor * baseColor.xyz; -#endif +# endif - - -#if defined(HAIR) +# if defined(HAIR) float3 vertexColor = (input.Color.yyy * (TintColor.xyz - 1.0.xxx) + 1.0.xxx) * color.xyz; -#else - float3 vertexColor = input.Color.xyz * color.xyz; -#endif +# else + float3 vertexColor = input.Color.xyz * color.xyz; +# endif -#if defined (MULTI_LAYER_PARALLAX) +# if defined(MULTI_LAYER_PARALLAX) float layerValue = MultiLayerParallaxData.x * TexLayerSampler.Sample(SampLayerSampler, uv).w; float3 tangentViewDirection = mul(viewDirection, tbn); float3 layerNormal = MultiLayerParallaxData.yyy * (normalColor.xyz * 2.0.xxx + float3(-1, -1, -2)) + float3(0, 0, 1); float layerViewAngle = dot(-tangentViewDirection.xyz, layerNormal.xyz) * 2; float3 layerViewProjection = -layerNormal.xyz * layerViewAngle.xxx - tangentViewDirection.xyz; float2 layerUv = uv * MultiLayerParallaxData.zw + (0.0009765625 * (layerValue / abs(layerViewProjection.z))).xx * layerViewProjection.xy; - + float3 layerColor = TexLayerSampler.Sample(SampLayerSampler, layerUv).xyz; vertexColor = (saturate(viewNormalAngle) * (1 - baseColor.w)).xxx * ((directionalAmbientColor + lightsDiffuseColor) * (input.Color.xyz * layerColor) - vertexColor) + vertexColor; -#endif - - float4 screenPosition = mul(ViewProjMatrixUnjittered, input.WorldPosition); - screenPosition.xy = screenPosition.xy / screenPosition.ww; - float4 previousScreenPosition = mul(PreviousViewProjMatrixUnjittered, input.PreviousWorldPosition); - previousScreenPosition.xy = previousScreenPosition.xy / previousScreenPosition.ww; - float2 screenMotionVector = float2(-0.5, 0.5) * (screenPosition.xy - previousScreenPosition.xy); - -#if !defined(PBR) -#if defined (SPECULAR) +# endif + + float4 screenPosition = mul(ViewProjMatrixUnjittered, input.WorldPosition); + screenPosition.xy = screenPosition.xy / screenPosition.ww; + float4 previousScreenPosition = mul(PreviousViewProjMatrixUnjittered, input.PreviousWorldPosition); + previousScreenPosition.xy = previousScreenPosition.xy / previousScreenPosition.ww; + float2 screenMotionVector = float2(-0.5, 0.5) * (screenPosition.xy - previousScreenPosition.xy); + +# if !defined(PBR) +# if defined(SPECULAR) specularColor = (specularColor * glossiness * MaterialData.yyy) * SpecularColor.xyz; -#elif defined(SPARKLE) +# elif defined(SPARKLE) specularColor *= glossiness; -#endif -#endif - if (useSnowSpecular) - { +# endif +# endif + if (useSnowSpecular) { specularColor = 0; } - -#if defined (AMBIENT_SPECULAR) + +# if defined(AMBIENT_SPECULAR) float viewAngle = saturate(dot(modelNormal.xyz, viewDirection)); float ambientSpecularColorMultiplier = exp2(AmbientSpecularTintAndFresnelPower.w * log2(1 - viewAngle)); float3 ambientSpecularColor = AmbientSpecularTintAndFresnelPower.xyz * saturate(mul(DirectionalAmbient, float4(modelNormal.xyz, 0.15))); specularColor += ambientSpecularColor * ambientSpecularColorMultiplier.xxx; -#endif - -#if !defined(PBR) && (defined (ENVMAP) || defined (MULTI_LAYER_PARALLAX) || defined(EYE)) -#if defined (CPM_AVAILABLE) && defined(ENVMAP) +# endif + +# if !defined(PBR) && (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE)) +# if defined(CPM_AVAILABLE) && defined(ENVMAP) vertexColor += diffuseColor * envColor * complexSpecular; -#else +# else vertexColor += diffuseColor * envColor; -#endif -#endif - - color.xyz = lerp(vertexColor.xyz, input.FogParam.xyz, input.FogParam.w); - color.xyz = vertexColor.xyz - color.xyz * FogColor.w; - - float3 tmpColor = color.xyz * GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW.yyy; - color.xyz = tmpColor.xyz + ColourOutputClamp.xxx; - color.xyz = min(vertexColor.xyz, color.xyz); - -#if !defined(PBR) -#if defined (CPM_AVAILABLE) && defined(ENVMAP) +# endif +# endif + + color.xyz = lerp(vertexColor.xyz, input.FogParam.xyz, input.FogParam.w); + color.xyz = vertexColor.xyz - color.xyz * FogColor.w; + + float3 tmpColor = color.xyz * GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW.yyy; + color.xyz = tmpColor.xyz + ColourOutputClamp.xxx; + color.xyz = min(vertexColor.xyz, color.xyz); + +# if !defined(PBR) +# if defined(CPM_AVAILABLE) && defined(ENVMAP) color.xyz += specularColor * complexSpecular; -#else +# else color.xyz += specularColor; -#endif - -#if defined (SPECULAR) || defined(AMBIENT_SPECULAR) || defined(SPARKLE) +# endif + +# if defined(SPECULAR) || defined(AMBIENT_SPECULAR) || defined(SPARKLE) float3 specularTmp = lerp(color.xyz, input.FogParam.xyz, input.FogParam.w); specularTmp = color.xyz - specularTmp.xyz * FogColor.w; - + tmpColor = specularTmp.xyz * GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW.yyy; specularTmp.xyz = tmpColor.xyz + ColourOutputClamp.zzz; color.xyz = min(specularTmp.xyz, color.xyz); -#endif +# endif -#endif - -#if defined (LANDSCAPE) && !defined(LOD_LAND_BLEND) +# endif + +# if defined(LANDSCAPE) && !defined(LOD_LAND_BLEND) psout.Albedo.w = 0; -#else - float alpha = baseColor.w; -#if !defined(ADDITIONAL_ALPHA_MASK) - alpha *= MaterialData.z; -#else +# else + float alpha = baseColor.w; +# if !defined(ADDITIONAL_ALPHA_MASK) + alpha *= MaterialData.z; +# else uint2 alphaMask = input.Position.xy; alphaMask.x = ((alphaMask.x << 2) & 12); alphaMask.x = (alphaMask.y & 3) | (alphaMask.x & ~3); - const float maskValues[16] = - { + const float maskValues[16] = { 0.003922, 0.533333, 0.133333, @@ -1766,82 +1718,78 @@ if (input.LandBlendWeights2.y > 0.0) }; float testTmp = 0; - if (MaterialData.z - maskValues[alphaMask.x] < 0) - { + if (MaterialData.z - maskValues[alphaMask.x] < 0) { discard; } -#endif -#if !(defined(TREE_ANIM) || defined(LODOBJECTSHD) || defined(LODOBJECTS)) +# endif +# if !(defined(TREE_ANIM) || defined(LODOBJECTSHD) || defined(LODOBJECTS)) alpha *= input.Color.w; -#endif -#if defined (DO_ALPHA_TEST) -#if defined (DEPTH_WRITE_DECALS) - if (alpha - 0.0156862754 < 0) - { +# endif +# if defined(DO_ALPHA_TEST) +# if defined(DEPTH_WRITE_DECALS) + if (alpha - 0.0156862754 < 0) { discard; } alpha = saturate(1.05 * alpha); -#endif - if (alpha - AlphaThreshold < 0) - { +# endif + if (alpha - AlphaThreshold < 0) { discard; } -#endif - psout.Albedo.w = alpha; - -#endif - - psout.Albedo.xyz = color.xyz - tmpColor.xyz * GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW.zzz; +# endif + psout.Albedo.w = alpha; + +# endif -#if defined (SNOW) + psout.Albedo.xyz = color.xyz - tmpColor.xyz * GammaInvX_FirstPersonY_AlphaPassZ_CreationKitW.zzz; + +# if defined(SNOW) psout.SnowParameters.x = dot(lightsSpecularColor, float3(0.3, 0.59, 0.11)); -#endif - - psout.MotionVectors.xy = SSRParams.z > 1e-5 ? float2(1, 0) : screenMotionVector.xy; - psout.MotionVectors.zw = float2(0, 1); +# endif + + psout.MotionVectors.xy = SSRParams.z > 1e-5 ? float2(1, 0) : screenMotionVector.xy; + psout.MotionVectors.zw = float2(0, 1); float tmp = -1e-5 + SSRParams.x; float tmp3 = (SSRParams.y - tmp); float tmp2 = (glossiness - tmp); float tmp1 = 1 / tmp3; tmp = saturate(tmp1 * tmp2); - tmp *= tmp * (3 + -2 * tmp); - psout.ScreenSpaceNormals.w = tmp * SSRParams.w; + tmp *= tmp * (3 + -2 * tmp); + psout.ScreenSpaceNormals.w = tmp * SSRParams.w; -#if defined(WATER_BLENDING) - if (perPassWaterBlending[0].EnableWaterBlendingSSR) - { +# if defined(WATER_BLENDING) + if (perPassWaterBlending[0].EnableWaterBlendingSSR) { // Compute distance to water surface float distToWater = max(0, input.WorldPosition.z - perPassWaterBlending[0].WaterHeight); - float blendFactor = smoothstep(viewPosition.z * 0.001 * 4, viewPosition.z * 0.001 * 16 * perPassWaterBlending[0].SSRBlendRange, distToWater ); + float blendFactor = smoothstep(viewPosition.z * 0.001 * 4, viewPosition.z * 0.001 * 16 * perPassWaterBlending[0].SSRBlendRange, distToWater); // Reduce SSR amount normal.z *= blendFactor; normal.xyz = normalize(normal.xyz); psout.ScreenSpaceNormals.w *= blendFactor; } -#endif +# endif -#if !defined(LANDSCAPE) && defined(SPECULAR) +# if !defined(LANDSCAPE) && defined(SPECULAR) // Green reflections fix psout.ScreenSpaceNormals.w = psout.ScreenSpaceNormals.w * (psout.Albedo.w == 1); -#endif +# endif - float3 screenSpaceNormal; - screenSpaceNormal.x = dot(input.ScreenNormalTransform0.xyz, normal.xyz); - screenSpaceNormal.y = dot(input.ScreenNormalTransform1.xyz, normal.xyz); - screenSpaceNormal.z = dot(input.ScreenNormalTransform2.xyz, normal.xyz); - screenSpaceNormal = normalize(screenSpaceNormal); + float3 screenSpaceNormal; + screenSpaceNormal.x = dot(input.ScreenNormalTransform0.xyz, normal.xyz); + screenSpaceNormal.y = dot(input.ScreenNormalTransform1.xyz, normal.xyz); + screenSpaceNormal.z = dot(input.ScreenNormalTransform2.xyz, normal.xyz); + screenSpaceNormal = normalize(screenSpaceNormal); - screenSpaceNormal.z = max(0.001, sqrt(8 + -8 * screenSpaceNormal.z)); - screenSpaceNormal.xy /= screenSpaceNormal.zz; - psout.ScreenSpaceNormals.xy = screenSpaceNormal.xy + 0.5.xx; - psout.ScreenSpaceNormals.z = 0; + screenSpaceNormal.z = max(0.001, sqrt(8 + -8 * screenSpaceNormal.z)); + screenSpaceNormal.xy /= screenSpaceNormal.zz; + psout.ScreenSpaceNormals.xy = screenSpaceNormal.xy + 0.5.xx; + psout.ScreenSpaceNormals.z = 0; -#if defined(OUTLINE) +# if defined(OUTLINE) psout.Albedo = float4(1, 0, 0, 1); -#endif - - return psout; +# endif + + return psout; } #endif diff --git a/package/Shaders/Particle.hlsl b/package/Shaders/Particle.hlsl index 7a079b22e..0a5870475 100644 --- a/package/Shaders/Particle.hlsl +++ b/package/Shaders/Particle.hlsl @@ -1,41 +1,41 @@ struct VS_INPUT { - float4 Position : POSITION0; + float4 Position : POSITION0; #if !defined(ENVCUBE) - float4 Normal : NORMAL0; + float4 Normal : NORMAL0; #endif - float4 TexCoord0 : TEXCOORD0; + float4 TexCoord0 : TEXCOORD0; #if defined(ENVCUBE) float4 #else int4 #endif - TexCoord1 : TEXCOORD1; + TexCoord1 : TEXCOORD1; }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; - float4 Color : COLOR0; - float2 TexCoord0 : TEXCOORD0; + float4 Position : SV_POSITION0; + float4 Color : COLOR0; + float2 TexCoord0 : TEXCOORD0; #if defined(ENVCUBE) - float4 PrecipitationOcclusionTexCoord : TEXCOORD1; + float4 PrecipitationOcclusionTexCoord : TEXCOORD1; #endif }; #ifdef VSHADER -cbuffer PerTechnique : register(b0) +cbuffer PerTechnique : register(b0) { - float2 ScaleAdjust : packoffset(c0); + float2 ScaleAdjust : packoffset(c0); }; -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { row_major float4x4 WorldViewProj; row_major float4x4 WorldView; -#if defined(ENVCUBE) +# if defined(ENVCUBE) row_major float4x4 PrecipitationOcclusionWorldViewProj; -#endif +# endif float4 fVars0; float4 fVars1; float4 fVars2; @@ -49,7 +49,7 @@ cbuffer PerGeometry : register(b2) float4 Wind; } -float2x2 GetRotationMatrix(float angle) +float2x2 GetRotationMatrix(float angle) { float sine, cosine; sincos(angle, sine, cosine); @@ -61,13 +61,13 @@ VS_OUTPUT main(VS_INPUT input) { VS_OUTPUT vsout; -#if defined (ENVCUBE) -#if defined(RAIN) +# if defined(ENVCUBE) +# if defined(RAIN) float2 positionOffset = input.TexCoord1.xy; -#else +# else float2x2 rotationMatrix = GetRotationMatrix(fVars0.w); float2 positionOffset = mul(rotationMatrix, input.TexCoord1.xy) * ScaleAdjust + mul(rotationMatrix, input.TexCoord1.zw); -#endif +# endif float3 normalizedPosition = (fVars0.xyz + input.Position.xyz) / fVars2.xxx; normalizedPosition = normalizedPosition >= -normalizedPosition ? frac(abs(normalizedPosition)) : @@ -78,14 +78,14 @@ VS_OUTPUT main(VS_INPUT input) msPosition.w = 1; float4 viewPosition = mul(WorldViewProj, msPosition); -#if defined(RAIN) +# if defined(RAIN) float4 adjustedMsPosition = msPosition - float4(Velocity.xyz, 0); float positionBlendParam = 0.5 * (1 + input.TexCoord1.y); float4 adjustedViewPosition = mul(WorldViewProj, adjustedMsPosition); float4 finalViewPosition = lerp(adjustedViewPosition, viewPosition, positionBlendParam); -#else +# else float4 finalViewPosition = viewPosition; -#endif +# endif vsout.Position.xy = positionOffset + finalViewPosition.xy; vsout.Position.zw = finalViewPosition.zw; @@ -96,28 +96,23 @@ VS_OUTPUT main(VS_INPUT input) float4 precipitationOcclusionTexCoord = mul(PrecipitationOcclusionWorldViewProj, msPosition); precipitationOcclusionTexCoord.y = -precipitationOcclusionTexCoord.y; - vsout.PrecipitationOcclusionTexCoord =precipitationOcclusionTexCoord; -#else + vsout.PrecipitationOcclusionTexCoord = precipitationOcclusionTexCoord; +# else float tmp2 = input.Normal.w * input.Position.w; float tmp1 = tmp2 / fVars0.y; float uvScale1, uvScale2, tmp3, tmp4; - if (tmp1 > fVars2.w) - { + if (tmp1 > fVars2.w) { uvScale1 = fVars2.y; uvScale2 = 0; tmp3 = fVars2.w; tmp4 = 1; - } - else if (tmp1 > fVars2.z) - { + } else if (tmp1 > fVars2.z) { uvScale1 = fVars2.x; uvScale2 = fVars2.y; tmp3 = fVars2.z; tmp4 = fVars2.w; - } - else - { + } else { uvScale1 = 0; uvScale2 = fVars2.x; tmp3 = 0; @@ -148,29 +143,22 @@ VS_OUTPUT main(VS_INPUT input) float4 color1, color2; float colorTmp1, colorTmp2; - if (tmp1 > fVars1.z) - { + if (tmp1 > fVars1.z) { color1 = Color3.xyzw; color2 = float4(Color3.xyz, 0); colorTmp1 = fVars1.z; colorTmp2 = 1; - } - else if (tmp1 > fVars1.y) - { + } else if (tmp1 > fVars1.y) { color1 = Color2.xyzw; color2 = Color3.xyzw; colorTmp1 = fVars1.y; colorTmp2 = fVars1.z; - } - else if (tmp1 > fVars1.x) - { + } else if (tmp1 > fVars1.x) { color1 = Color1.xyzw; color2 = Color2.xyzw; colorTmp1 = fVars1.x; colorTmp2 = fVars1.y; - } - else - { + } else { color1 = float4(Color1.xyz, 0); color2 = Color1.xyzw; colorTmp1 = 0; @@ -181,7 +169,7 @@ VS_OUTPUT main(VS_INPUT input) vsout.Color.w = fVars3.w * color.w; vsout.Color.xyz = color.xyz; -#endif +# endif return vsout; } @@ -191,40 +179,40 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { - float4 Color : SV_Target0; - float4 Normal : SV_Target1; + float4 Color : SV_Target0; + float4 Normal : SV_Target1; }; #ifdef PSHADER -SamplerState SampSourceTexture : register(s0); -#if defined(GRAYSCALE_TO_COLOR) || defined(GRAYSCALE_TO_ALPHA) -SamplerState SampGrayscaleTexture : register(s1); -#endif -#if defined(ENVCUBE) -SamplerState SampPrecipitationOcclusionTexture : register(s2); -SamplerState SampUnderwaterMask : register(s3); -#endif - -Texture2D TexSourceTexture : register(t0); -#if defined(GRAYSCALE_TO_COLOR) || defined(GRAYSCALE_TO_ALPHA) -Texture2D TexGrayscaleTexture : register(t1); -#endif -#if defined(ENVCUBE) -Texture2D TexPrecipitationOcclusionTexture : register(t2); -Texture2D TexUnderwaterMask : register(t3); -#endif - -cbuffer PerGeometry : register(b2) +SamplerState SampSourceTexture : register(s0); +# if defined(GRAYSCALE_TO_COLOR) || defined(GRAYSCALE_TO_ALPHA) +SamplerState SampGrayscaleTexture : register(s1); +# endif +# if defined(ENVCUBE) +SamplerState SampPrecipitationOcclusionTexture : register(s2); +SamplerState SampUnderwaterMask : register(s3); +# endif + +Texture2D TexSourceTexture : register(t0); +# if defined(GRAYSCALE_TO_COLOR) || defined(GRAYSCALE_TO_ALPHA) +Texture2D TexGrayscaleTexture : register(t1); +# endif +# if defined(ENVCUBE) +Texture2D TexPrecipitationOcclusionTexture : register(t2); +Texture2D TexUnderwaterMask : register(t3); +# endif + +cbuffer PerGeometry : register(b2) { - float ColorScale : packoffset(c0); - float3 TextureSize : packoffset(c1); + float ColorScale : packoffset(c0); + float3 TextureSize : packoffset(c1); }; PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; -#if defined (ENVCUBE) +# if defined(ENVCUBE) float3 precipitationOcclusionUv = float3(TextureSize.xx * (input.PrecipitationOcclusionTexCoord.xy * 0.5.xx + 0.5.xx), 0); float precipitationOcclusion = @@ -232,33 +220,32 @@ PS_OUTPUT main(PS_INPUT input) TexPrecipitationOcclusionTexture.Load(precipitationOcclusionUv).x; float2 underwaterMaskUv = TextureSize.yz * input.Position.xy; float underwaterMask = TexUnderwaterMask.Sample(SampUnderwaterMask, underwaterMaskUv).x; - if (precipitationOcclusion - underwaterMask < 0) - { + if (precipitationOcclusion - underwaterMask < 0) { discard; } -#endif +# endif float4 sourceColor = TexSourceTexture.Sample(SampSourceTexture, input.TexCoord0); float4 baseColor = input.Color * sourceColor; -#if defined(GRAYSCALE_TO_COLOR) +# if defined(GRAYSCALE_TO_COLOR) float3 grayScaleColor = TexGrayscaleTexture.Sample(SampGrayscaleTexture, float2(sourceColor.y, input.Color.x)).xyz; baseColor.xyz = grayScaleColor; -#endif -#if defined(GRAYSCALE_TO_ALPHA) +# endif +# if defined(GRAYSCALE_TO_ALPHA) float grayScaleAlpha = TexGrayscaleTexture.Sample(SampGrayscaleTexture, float2(sourceColor.w, input.Color.w)).w; baseColor.w = grayScaleAlpha; -#endif +# endif psout.Color.xyz = ColorScale * baseColor.xyz; psout.Color.w = baseColor.w; psout.Normal.w = baseColor.w; -#if defined(ENVCUBE) +# if defined(ENVCUBE) psout.Normal.xyz = float3(0, 1, 0); -#else +# else psout.Normal.xyz = float3(1, 0, 0); -#endif +# endif return psout; } diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index a62930f2b..81e1dd92d 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -1,64 +1,63 @@ struct VS_INPUT { - float4 Position : POSITION0; - float2 TexCoord : TEXCOORD0; - float4 Normal : NORMAL0; - float4 Color : COLOR0; - float4 InstanceData1 : TEXCOORD4; - float4 InstanceData2 : TEXCOORD5; - float4 InstanceData3 : TEXCOORD6; - float4 InstanceData4 : TEXCOORD7; + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD0; + float4 Normal : NORMAL0; + float4 Color : COLOR0; + float4 InstanceData1 : TEXCOORD4; + float4 InstanceData2 : TEXCOORD5; + float4 InstanceData3 : TEXCOORD6; + float4 InstanceData4 : TEXCOORD7; }; struct VS_OUTPUT { - float4 HPosition : SV_POSITION0; - float4 DiffuseColor : COLOR0; - float3 TexCoord : TEXCOORD0; - float4 AmbientColor : TEXCOORD1; - float3 ViewSpacePosition : TEXCOORD2; + float4 HPosition : SV_POSITION0; + float4 DiffuseColor : COLOR0; + float3 TexCoord : TEXCOORD0; + float4 AmbientColor : TEXCOORD1; + float3 ViewSpacePosition : TEXCOORD2; #if defined(RENDER_DEPTH) - float2 Depth : TEXCOORD3; + float2 Depth : TEXCOORD3; #endif - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; }; #ifdef VSHADER -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float4x4 WorldViewProj : packoffset(c0); - row_major float4x4 WorldView : packoffset(c4); - row_major float4x4 World : packoffset(c8); - row_major float4x4 PreviousWorld : packoffset(c12); - float4 FogNearColor : packoffset(c16); - float3 WindVector : packoffset(c17); - float WindTimer : packoffset(c17.w); - float3 DirLightDirection : packoffset(c18); - float PreviousWindTimer : packoffset(c18.w); - float3 DirLightColor : packoffset(c19); - float AlphaParam1 : packoffset(c19.w); - float3 AmbientColor : packoffset(c20); - float AlphaParam2 : packoffset(c20.w); - float3 ScaleMask : packoffset(c21); - float ShadowClampValue : packoffset(c21.w); + row_major float4x4 WorldViewProj : packoffset(c0); + row_major float4x4 WorldView : packoffset(c4); + row_major float4x4 World : packoffset(c8); + row_major float4x4 PreviousWorld : packoffset(c12); + float4 FogNearColor : packoffset(c16); + float3 WindVector : packoffset(c17); + float WindTimer : packoffset(c17.w); + float3 DirLightDirection : packoffset(c18); + float PreviousWindTimer : packoffset(c18.w); + float3 DirLightColor : packoffset(c19); + float AlphaParam1 : packoffset(c19.w); + float3 AmbientColor : packoffset(c20); + float AlphaParam2 : packoffset(c20.w); + float3 ScaleMask : packoffset(c21); + float ShadowClampValue : packoffset(c21.w); } -cbuffer cb7 : register(b7) -{ - float4 cb7[1]; +cbuffer cb7 : register(b7) +{ + float4 cb7[1]; } -cbuffer cb8 : register(b8) +cbuffer cb8 : register(b8) { - float4 cb8[240]; + float4 cb8[240]; } -#define M_PI 3.1415925 // PI -#define M_2PI 6.283185 // PI * 2 +# define M_PI 3.1415925 // PI +# define M_2PI 6.283185 // PI * 2 -const static float4x4 M_IdentityMatrix = -{ +const static float4x4 M_IdentityMatrix = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, @@ -75,7 +74,7 @@ float4 GetMSPosition(VS_INPUT input, float windTimer) float windTmp1 = sin(M_PI * windAngleSin); float windTmp2 = sin(M_2PI * windAngleSin); float windPower = WindVector.z * (((windTmp1 + windTmp2) * 0.3 + windTmp3) * - (0.5 * (input.Color.w * input.Color.w))); + (0.5 * (input.Color.w * input.Color.w))); float3 inputPosition = input.Position.xyz * (input.InstanceData4.yyy * ScaleMask.xyz + float3(1, 1, 1)); @@ -103,9 +102,9 @@ VS_OUTPUT main(VS_INPUT input) float4 projSpacePosition = mul(WorldViewProj, msPosition); vsout.HPosition = projSpacePosition; -#if defined(RENDER_DEPTH) +# if defined(RENDER_DEPTH) vsout.Depth = projSpacePosition.zw; -#endif +# endif float3 instanceNormal = float3(input.InstanceData2.z, input.InstanceData3.zw); float dirLightAngle = dot(DirLightDirection.xyz, instanceNormal); @@ -139,31 +138,31 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { #if defined(RENDER_DEPTH) - float4 PS : SV_Target0; + float4 PS : SV_Target0; #else - float4 Albedo : SV_Target0; - float2 MotionVectors : SV_Target1; - float4 Normal : SV_Target2; + float4 Albedo : SV_Target0; + float2 MotionVectors : SV_Target1; + float4 Normal : SV_Target2; #endif }; #ifdef PSHADER -SamplerState SampBaseSampler : register(s0); -SamplerState SampShadowMaskSampler : register(s1); +SamplerState SampBaseSampler : register(s0); +SamplerState SampShadowMaskSampler : register(s1); -Texture2D TexBaseSampler : register(t0); -Texture2D TexShadowMaskSampler : register(t1); +Texture2D TexBaseSampler : register(t0); +Texture2D TexShadowMaskSampler : register(t1); -cbuffer AlphaTestRefCB : register(b11) -{ - float AlphaTestRefRS : packoffset(c0); +cbuffer AlphaTestRefCB : register(b11) +{ + float AlphaTestRefRS : packoffset(c0); } cbuffer PerFrame : register(b12) { - float4 UnknownPerFrame1[12] : packoffset(c0); - row_major float4x4 ScreenProj : packoffset(c12); - row_major float4x4 PreviousScreenProj : packoffset(c16); + float4 UnknownPerFrame1[12] : packoffset(c0); + row_major float4x4 ScreenProj : packoffset(c12); + row_major float4x4 PreviousScreenProj : packoffset(c16); }; PS_OUTPUT main(PS_INPUT input) @@ -172,20 +171,19 @@ PS_OUTPUT main(PS_INPUT input) float4 baseColor = TexBaseSampler.Sample(SampBaseSampler, input.TexCoord.xy); -#if defined(RENDER_DEPTH) || defined(DO_ALPHA_TEST) +# if defined(RENDER_DEPTH) || defined(DO_ALPHA_TEST) float diffuseAlpha = input.DiffuseColor.w * baseColor.w; - if ((diffuseAlpha - AlphaTestRefRS) < 0) - { + if ((diffuseAlpha - AlphaTestRefRS) < 0) { discard; } -#endif +# endif -#if defined(RENDER_DEPTH) +# if defined(RENDER_DEPTH) // Depth psout.PS.xyz = input.Depth.xxx / input.Depth.yyy; psout.PS.w = diffuseAlpha; -#else +# else float sunShadowMask = TexShadowMaskSampler.Load(int3(input.HPosition.xy, 0)).x; // Albedo @@ -209,7 +207,7 @@ PS_OUTPUT main(PS_INPUT input) float normalScale = max(1.0 / 1000.0, sqrt(normal.z * -8 + 8)); psout.Normal.xy = float2(0.5, 0.5) + normal.xy / normalScale; psout.Normal.zw = float2(0, 0); -#endif +# endif return psout; } diff --git a/package/Shaders/Sky.hlsl b/package/Shaders/Sky.hlsl index 47d26e4ff..33dc7741d 100644 --- a/package/Shaders/Sky.hlsl +++ b/package/Shaders/Sky.hlsl @@ -1,52 +1,52 @@ struct VS_INPUT { - float4 Position : POSITION0; + float4 Position : POSITION0; #if defined(TEX) || defined(HORIZFADE) - float2 TexCoord : TEXCOORD0; + float2 TexCoord : TEXCOORD0; #endif - float4 Color : COLOR0; + float4 Color : COLOR0; }; struct VS_OUTPUT { - float4 Position : SV_POSITION0; + float4 Position : SV_POSITION0; #if defined(DITHER) && defined(TEX) - float4 TexCoord0 : TEXCOORD0; + float4 TexCoord0 : TEXCOORD0; #elif defined(DITHER) - float2 TexCoord0 : TEXCOORD3; + float2 TexCoord0 : TEXCOORD3; #elif defined(TEX) || defined(HORIZFADE) - float2 TexCoord0 : TEXCOORD0; + float2 TexCoord0 : TEXCOORD0; #endif #if defined(TEXLERP) - float2 TexCoord1 : TEXCOORD1; + float2 TexCoord1 : TEXCOORD1; #endif #if defined(HORIZFADE) - float TexCoord2 : TEXCOORD2; + float TexCoord2 : TEXCOORD2; #endif #if defined(TEX) || defined(DITHER) || defined(HORIZFADE) - float4 Color : COLOR0; + float4 Color : COLOR0; #endif - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; }; #ifdef VSHADER -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - row_major float4x4 WorldViewProj : packoffset(c0); - row_major float4x4 World : packoffset(c4); - row_major float4x4 PreviousWorld : packoffset(c8); - float3 EyePosition : packoffset(c12); - float VParams : packoffset(c12.w); - float4 BlendColor[3] : packoffset(c13); - float2 TexCoordOff : packoffset(c16); + row_major float4x4 WorldViewProj : packoffset(c0); + row_major float4x4 World : packoffset(c4); + row_major float4x4 PreviousWorld : packoffset(c8); + float3 EyePosition : packoffset(c12); + float VParams : packoffset(c12.w); + float4 BlendColor[3] : packoffset(c13); + float2 TexCoordOff : packoffset(c16); }; VS_OUTPUT main(VS_INPUT input) @@ -55,16 +55,16 @@ VS_OUTPUT main(VS_INPUT input) float4 inputPosition = float4(input.Position.xyz, 1.0); -#if defined(OCCLUSION) +# if defined(OCCLUSION) // Intentionally left blank -#elif defined(MOONMASK) +# elif defined(MOONMASK) vsout.TexCoord0 = input.TexCoord; vsout.Color = float4(VParams.xxx, 1.0); -#elif defined(HORIZFADE) +# elif defined(HORIZFADE) float worldHeight = mul(World, inputPosition).z; float eyeHeightDelta = -EyePosition.z + worldHeight; @@ -74,37 +74,37 @@ VS_OUTPUT main(VS_INPUT input) vsout.Color.xyz = BlendColor[0].xyz * VParams; vsout.Color.w = BlendColor[0].w; -#else // MOONMASK HORIZFADE +# else // MOONMASK HORIZFADE -#if defined(DITHER) +# if defined(DITHER) -#if defined(TEX) +# if defined(TEX) vsout.TexCoord0.xyzw = input.TexCoord.xyxy * float4(1.0, 1.0, 501.0, 501.0); -#else +# else float3 inputDirection = normalize(input.Position.xyz); inputDirection.y += inputDirection.z; vsout.TexCoord0.x = 501 * acos(inputDirection.x); vsout.TexCoord0.y = 501 * asin(inputDirection.y); -#endif // TEX +# endif // TEX -#elif defined(CLOUDS) +# elif defined(CLOUDS) vsout.TexCoord0.xy = TexCoordOff + input.TexCoord; -#else +# else vsout.TexCoord0.xy = input.TexCoord; -#endif // DITHER CLOUDS +# endif // DITHER CLOUDS -#ifdef TEXLERP +# ifdef TEXLERP vsout.TexCoord1.xy = TexCoordOff + input.TexCoord; -#endif // TEXLERP +# endif // TEXLERP float3 skyColor = BlendColor[0].xyz * input.Color.xxx + BlendColor[1].xyz * input.Color.yyy + - BlendColor[2].xyz * input.Color.zzz; + BlendColor[2].xyz * input.Color.zzz; vsout.Color.xyz = VParams * skyColor; vsout.Color.w = BlendColor[0].w * input.Color.w; -#endif // OCCLUSION MOONMASK HORIZFADE +# endif // OCCLUSION MOONMASK HORIZFADE vsout.Position = mul(WorldViewProj, inputPosition).xyww; vsout.WorldPosition = mul(World, inputPosition); @@ -118,84 +118,83 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { - float4 Color : SV_Target0; - float2 MotionVectors : SV_Target1; - float4 Normal : SV_Target2; + float4 Color : SV_Target0; + float2 MotionVectors : SV_Target1; + float4 Normal : SV_Target2; }; #ifdef PSHADER -SamplerState SampBaseSampler : register(s0); -SamplerState SampBlendSampler : register(s1); -SamplerState SampNoiseGradSampler : register(s2); +SamplerState SampBaseSampler : register(s0); +SamplerState SampBlendSampler : register(s1); +SamplerState SampNoiseGradSampler : register(s2); -Texture2D TexBaseSampler : register(t0); -Texture2D TexBlendSampler : register(t1); -Texture2D TexNoiseGradSampler : register(t2); +Texture2D TexBaseSampler : register(t0); +Texture2D TexBlendSampler : register(t1); +Texture2D TexNoiseGradSampler : register(t2); -cbuffer PerFrame : register(b12) +cbuffer PerFrame : register(b12) { - float4 UnknownPerFrame1[12] : packoffset(c0); - row_major float4x4 ScreenProj : packoffset(c12); - row_major float4x4 PreviousScreenProj : packoffset(c16); + float4 UnknownPerFrame1[12] : packoffset(c0); + row_major float4x4 ScreenProj : packoffset(c12); + row_major float4x4 PreviousScreenProj : packoffset(c16); } -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - float2 PParams : packoffset(c0); + float2 PParams : packoffset(c0); }; -cbuffer AlphaTestRefCB : register(b11) +cbuffer AlphaTestRefCB : register(b11) { - float AlphaTestRefRS : packoffset(c0); + float AlphaTestRefRS : packoffset(c0); } PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; -#ifndef OCCLUSION -#ifndef TEXLERP +# ifndef OCCLUSION +# ifndef TEXLERP float4 baseColor = TexBaseSampler.Sample(SampBaseSampler, input.TexCoord0.xy); -#ifdef TEXFADE +# ifdef TEXFADE baseColor.w *= PParams.x; -#endif -#else +# endif +# else float4 blendColor = TexBlendSampler.Sample(SampBlendSampler, input.TexCoord1.xy); float4 baseColor = TexBaseSampler.Sample(SampBaseSampler, input.TexCoord0.xy); baseColor = PParams.xxxx * (-baseColor + blendColor) + baseColor; -#endif +# endif -#if defined(DITHER) - float2 noiseGradUv = float2(0.125,0.125) * input.Position.xy; +# if defined(DITHER) + float2 noiseGradUv = float2(0.125, 0.125) * input.Position.xy; float noiseGrad = TexNoiseGradSampler.Sample(SampNoiseGradSampler, noiseGradUv).x * 0.03125 + -0.0078125; -#ifdef TEX +# ifdef TEX psout.Color.xyz = (input.Color.xyz * baseColor.xyz + PParams.yyy) + noiseGrad; psout.Color.w = baseColor.w * input.Color.w; -#else +# else psout.Color.xyz = (PParams.yyy + input.Color.xyz) + noiseGrad; psout.Color.w = input.Color.w; -#endif // TEX -#elif defined(MOONMASK) +# endif // TEX +# elif defined(MOONMASK) psout.Color.xyzw = baseColor; - if (baseColor.w - AlphaTestRefRS.x < 0) - { + if (baseColor.w - AlphaTestRefRS.x < 0) { discard; } -#elif defined(HORIZFADE) +# elif defined(HORIZFADE) psout.Color.xyz = float3(1.5, 1.5, 1.5) * (input.Color.xyz * baseColor.xyz + PParams.yyy); psout.Color.w = input.TexCoord2.x * (baseColor.w * input.Color.w); -#else +# else psout.Color.w = input.Color.w * baseColor.w; psout.Color.xyz = input.Color.xyz * baseColor.xyz + PParams.yyy; -#endif +# endif -#else +# else psout.Color = float4(0, 0, 0, 1.0); -#endif // OCCLUSION +# endif // OCCLUSION float4 screenPosition = mul(ScreenProj, input.WorldPosition); screenPosition.xy = screenPosition.xy / screenPosition.ww; diff --git a/package/Shaders/Water.hlsl b/package/Shaders/Water.hlsl index 192269bcc..8011d950b 100644 --- a/package/Shaders/Water.hlsl +++ b/package/Shaders/Water.hlsl @@ -2,68 +2,68 @@ #include "Common/MotionBlur.hlsl" #if defined(VERTEX_ALPHA_DEPTH) -#define VC +# define VC #endif struct VS_INPUT { #if defined(SPECULAR) || defined(UNDERWATER) || defined(STENCIL) || defined(SIMPLE) - float4 Position : POSITION0; -#if defined(NORMAL_TEXCOORD) - float2 TexCoord0 : TEXCOORD0; -#endif -#if defined(VC) - float4 Color : COLOR0; -#endif + float4 Position : POSITION0; +# if defined(NORMAL_TEXCOORD) + float2 TexCoord0 : TEXCOORD0; +# endif +# if defined(VC) + float4 Color : COLOR0; +# endif #endif #if defined(LOD) - float4 Position : POSITION0; -#if defined(VC) - float4 Color : COLOR0; -#endif + float4 Position : POSITION0; +# if defined(VC) + float4 Color : COLOR0; +# endif #endif }; struct VS_OUTPUT { #if defined(SPECULAR) || defined(UNDERWATER) - float4 HPosition : SV_POSITION0; - float4 FogParam : COLOR0; - float4 WPosition : TEXCOORD0; - float4 TexCoord1 : TEXCOORD1; - float4 TexCoord2 : TEXCOORD2; -#if defined(WADING) || (defined(FLOWMAP) && (defined(REFRACTIONS) || defined(BLEND_NORMALS))) || (defined(VERTEX_ALPHA_DEPTH) && defined(VC)) || ((defined(SPECULAR) && NUM_SPECULAR_LIGHTS == 0) && defined(FLOWMAP) /*!defined(NORMAL_TEXCOORD) && !defined(BLEND_NORMALS) && !defined(VC)*/) - float4 TexCoord3 : TEXCOORD3; -#endif -#if defined(FLOWMAP) - nointerpolation float TexCoord4 : TEXCOORD4; -#endif -#if NUM_SPECULAR_LIGHTS == 0 - float4 MPosition : TEXCOORD5; -#endif + float4 HPosition : SV_POSITION0; + float4 FogParam : COLOR0; + float4 WPosition : TEXCOORD0; + float4 TexCoord1 : TEXCOORD1; + float4 TexCoord2 : TEXCOORD2; +# if defined(WADING) || (defined(FLOWMAP) && (defined(REFRACTIONS) || defined(BLEND_NORMALS))) || (defined(VERTEX_ALPHA_DEPTH) && defined(VC)) || ((defined(SPECULAR) && NUM_SPECULAR_LIGHTS == 0) && defined(FLOWMAP) /*!defined(NORMAL_TEXCOORD) && !defined(BLEND_NORMALS) && !defined(VC)*/) + float4 TexCoord3 : TEXCOORD3; +# endif +# if defined(FLOWMAP) + nointerpolation float TexCoord4 : TEXCOORD4; +# endif +# if NUM_SPECULAR_LIGHTS == 0 + float4 MPosition : TEXCOORD5; +# endif #endif #if defined(SIMPLE) - float4 HPosition : SV_POSITION0; - float4 FogParam : COLOR0; - float4 WPosition : TEXCOORD0; - float4 TexCoord1 : TEXCOORD1; - float4 TexCoord2 : TEXCOORD2; - float4 MPosition : TEXCOORD5; + float4 HPosition : SV_POSITION0; + float4 FogParam : COLOR0; + float4 WPosition : TEXCOORD0; + float4 TexCoord1 : TEXCOORD1; + float4 TexCoord2 : TEXCOORD2; + float4 MPosition : TEXCOORD5; #endif #if defined(LOD) - float4 HPosition : SV_POSITION0; - float4 FogParam : COLOR0; - float4 WPosition : TEXCOORD0; - float4 TexCoord1 : TEXCOORD1; + float4 HPosition : SV_POSITION0; + float4 FogParam : COLOR0; + float4 WPosition : TEXCOORD0; + float4 TexCoord1 : TEXCOORD1; #endif #if defined(STENCIL) - float4 HPosition : SV_POSITION0; - float4 WorldPosition : POSITION1; - float4 PreviousWorldPosition : POSITION2; + float4 HPosition : SV_POSITION0; + float4 WorldPosition : POSITION1; + float4 PreviousWorldPosition : POSITION2; #endif }; @@ -71,136 +71,134 @@ struct VS_OUTPUT cbuffer PerTechnique : register(b0) { - float4 QPosAdjust : packoffset(c0); + float4 QPosAdjust : packoffset(c0); }; cbuffer PerMaterial : register(b1) { - float4 VSFogParam : packoffset(c0); - float4 VSFogNearColor : packoffset(c1); - float4 VSFogFarColor : packoffset(c2); - float4 NormalsScroll0 : packoffset(c3); - float4 NormalsScroll1 : packoffset(c4); - float4 NormalsScale : packoffset(c5); + float4 VSFogParam : packoffset(c0); + float4 VSFogNearColor : packoffset(c1); + float4 VSFogFarColor : packoffset(c2); + float4 NormalsScroll0 : packoffset(c3); + float4 NormalsScroll1 : packoffset(c4); + float4 NormalsScale : packoffset(c5); }; cbuffer PerGeometry : register(b2) { - row_major float4x4 World : packoffset(c0); - row_major float4x4 PreviousWorld : packoffset(c4); - row_major float4x4 WorldViewProj : packoffset(c8); - float3 ObjectUV : packoffset(c12); - float4 CellTexCoordOffset : packoffset(c13); + row_major float4x4 World : packoffset(c0); + row_major float4x4 PreviousWorld : packoffset(c4); + row_major float4x4 WorldViewProj : packoffset(c8); + float3 ObjectUV : packoffset(c12); + float4 CellTexCoordOffset : packoffset(c13); }; VS_OUTPUT main(VS_INPUT input) { - VS_OUTPUT vsout; + VS_OUTPUT vsout; - float4 inputPosition = float4(input.Position.xyz, 1.0); - float4 worldPos = mul(World, inputPosition); - float4 worldViewPos = mul(WorldViewProj, inputPosition); + float4 inputPosition = float4(input.Position.xyz, 1.0); + float4 worldPos = mul(World, inputPosition); + float4 worldViewPos = mul(WorldViewProj, inputPosition); - float heightMult = min((1.0 / 10000.0) * max(worldViewPos.z - 70000, 0), 1); + float heightMult = min((1.0 / 10000.0) * max(worldViewPos.z - 70000, 0), 1); - vsout.HPosition.xy = worldViewPos.xy; - vsout.HPosition.z = heightMult * 0.5 + worldViewPos.z; - vsout.HPosition.w = worldViewPos.w; + vsout.HPosition.xy = worldViewPos.xy; + vsout.HPosition.z = heightMult * 0.5 + worldViewPos.z; + vsout.HPosition.w = worldViewPos.w; -#if defined(STENCIL) +# if defined(STENCIL) vsout.WorldPosition = worldPos; vsout.PreviousWorldPosition = mul(PreviousWorld, inputPosition); -#else +# else float fogColorParam = min(VSFogFarColor.w, pow(saturate(length(worldViewPos.xyz) * VSFogParam.y - VSFogParam.x), NormalsScale.w)); vsout.FogParam.xyz = lerp(VSFogNearColor.xyz, VSFogFarColor.xyz, fogColorParam); vsout.FogParam.w = fogColorParam; - vsout.WPosition.xyz = worldPos.xyz; - vsout.WPosition.w = length(worldPos.xyz); + vsout.WPosition.xyz = worldPos.xyz; + vsout.WPosition.w = length(worldPos.xyz); -#if defined(LOD) +# if defined(LOD) float4 posAdjust = ObjectUV.x ? 0.0 : (QPosAdjust.xyxy + worldPos.xyxy) / NormalsScale.xxyy; vsout.TexCoord1.xyzw = NormalsScroll0 + posAdjust; -#else -#if !defined(SPECULAR) || (NUM_SPECULAR_LIGHTS == 0) - vsout.MPosition.xyzw = inputPosition.xyzw; -#endif +# else +# if !defined(SPECULAR) || (NUM_SPECULAR_LIGHTS == 0) + vsout.MPosition.xyzw = inputPosition.xyzw; +# endif - float2 posAdjust = worldPos.xy + QPosAdjust.xy; + float2 posAdjust = worldPos.xy + QPosAdjust.xy; float2 scrollAdjust1 = posAdjust / NormalsScale.xx; float2 scrollAdjust2 = posAdjust / NormalsScale.yy; float2 scrollAdjust3 = posAdjust / NormalsScale.zz; -#if !(defined(FLOWMAP) && (defined(REFRACTIONS) || defined(BLEND_NORMALS) || defined(DEPTH) || NUM_SPECULAR_LIGHTS == 0)) -#if defined(NORMAL_TEXCOORD) +# if !(defined(FLOWMAP) && (defined(REFRACTIONS) || defined(BLEND_NORMALS) || defined(DEPTH) || NUM_SPECULAR_LIGHTS == 0)) +# if defined(NORMAL_TEXCOORD) float3 normalsScale = 0.001 * NormalsScale.xyz; - if (ObjectUV.x) - { + if (ObjectUV.x) { scrollAdjust1 = input.TexCoord0.xy / normalsScale.xx; scrollAdjust2 = input.TexCoord0.xy / normalsScale.yy; scrollAdjust3 = input.TexCoord0.xy / normalsScale.zz; } -#else - if (ObjectUV.x) - { +# else + if (ObjectUV.x) { scrollAdjust1 = 0.0; scrollAdjust2 = 0.0; scrollAdjust3 = 0.0; - } -#endif -#endif + } +# endif +# endif vsout.TexCoord1 = 0.0; vsout.TexCoord2 = 0.0; -#if defined(FLOWMAP) -#if !(((defined(SPECULAR) || NUM_SPECULAR_LIGHTS == 0) || (defined(UNDERWATER) && defined(REFRACTIONS))) && !defined(NORMAL_TEXCOORD)) -#if defined(BLEND_NORMALS) +# if defined(FLOWMAP) +# if !(((defined(SPECULAR) || NUM_SPECULAR_LIGHTS == 0) || (defined(UNDERWATER) && defined(REFRACTIONS))) && !defined(NORMAL_TEXCOORD)) +# if defined(BLEND_NORMALS) vsout.TexCoord1.xy = NormalsScroll0.xy + scrollAdjust1; vsout.TexCoord1.zw = NormalsScroll0.zw + scrollAdjust2; vsout.TexCoord2.xy = NormalsScroll1.xy + scrollAdjust3; -#else +# else vsout.TexCoord1.xy = NormalsScroll0.xy + scrollAdjust1; vsout.TexCoord1.zw = 0.0; vsout.TexCoord2.xy = 0.0; -#endif -#endif -#if !defined(NORMAL_TEXCOORD) +# endif +# endif +# if !defined(NORMAL_TEXCOORD) vsout.TexCoord3 = 0.0; -#elif defined(WADING) +# elif defined(WADING) vsout.TexCoord2.zw = ((-0.5 + input.TexCoord0.xy) * 0.1 + CellTexCoordOffset.xy) + - float2(CellTexCoordOffset.z, -CellTexCoordOffset.w + ObjectUV.x) / ObjectUV.xx; + float2(CellTexCoordOffset.z, -CellTexCoordOffset.w + ObjectUV.x) / ObjectUV.xx; vsout.TexCoord3.xy = -0.25 + (input.TexCoord0.xy * 0.5 + ObjectUV.yz); vsout.TexCoord3.zw = input.TexCoord0.xy; -#elif (defined(REFRACTIONS) || NUM_SPECULAR_LIGHTS == 0 || defined(BLEND_NORMALS)) +# elif (defined(REFRACTIONS) || NUM_SPECULAR_LIGHTS == 0 || defined(BLEND_NORMALS)) vsout.TexCoord2.zw = (CellTexCoordOffset.xy + input.TexCoord0.xy) / ObjectUV.xx; vsout.TexCoord3.xy = (CellTexCoordOffset.zw + input.TexCoord0.xy); vsout.TexCoord3.zw = input.TexCoord0.xy; -#endif - vsout.TexCoord4 = ObjectUV.x; -#else +# endif + vsout.TexCoord4 = ObjectUV.x; +# else vsout.TexCoord1.xy = NormalsScroll0.xy + scrollAdjust1; vsout.TexCoord1.zw = NormalsScroll0.zw + scrollAdjust2; vsout.TexCoord2.xy = NormalsScroll1.xy + scrollAdjust3; - vsout.TexCoord2.z = worldViewPos.w; - vsout.TexCoord2.w = 0; -#if (defined(WADING) || (defined(VERTEX_ALPHA_DEPTH) && defined(VC))) - vsout.TexCoord3 = 0.0; -#if (defined(NORMAL_TEXCOORD) && ((!defined(BLEND_NORMALS) && !defined(VERTEX_ALPHA_DEPTH)) || defined(WADING))) - vsout.TexCoord3.xy = input.TexCoord0; -#endif -#if defined(VERTEX_ALPHA_DEPTH) && defined(VC) - vsout.TexCoord3.z = input.Color.w; -#endif -#endif -#endif -#endif -#endif - - return vsout; + vsout.TexCoord2.z = worldViewPos.w; + vsout.TexCoord2.w = 0; +# if (defined(WADING) || (defined(VERTEX_ALPHA_DEPTH) && defined(VC))) + vsout.TexCoord3 = 0.0; +# if (defined(NORMAL_TEXCOORD) && ((!defined(BLEND_NORMALS) && !defined(VERTEX_ALPHA_DEPTH)) || defined(WADING))) + vsout.TexCoord3.xy = input.TexCoord0; +# endif +# if defined(VERTEX_ALPHA_DEPTH) && defined(VC) + vsout.TexCoord3.z = input.Color.w; +# endif +# endif +# endif +# endif +# endif + + return vsout; } #endif @@ -210,81 +208,81 @@ typedef VS_OUTPUT PS_INPUT; struct PS_OUTPUT { #if defined(UNDERWATER) || defined(SIMPLE) || defined(LOD) || defined(SPECULAR) - float4 Lighting : SV_Target0; + float4 Lighting : SV_Target0; #endif #if defined(STENCIL) - float4 WaterMask : SV_Target0; - float2 MotionVector : SV_Target1; + float4 WaterMask : SV_Target0; + float2 MotionVector : SV_Target1; #endif }; #ifdef PSHADER -SamplerState ReflectionSampler : register(s0); -SamplerState RefractionSampler : register(s1); -SamplerState DisplacementSampler : register(s2); -SamplerState CubeMapSampler : register(s3); -SamplerState Normals01Sampler : register(s4); -SamplerState Normals02Sampler : register(s5); -SamplerState Normals03Sampler : register(s6); -SamplerState DepthSampler : register(s7); -SamplerState FlowMapSampler : register(s8); -SamplerState FlowMapNormalsSampler : register(s9); -SamplerState SSRReflectionSampler : register(s10); -SamplerState RawSSRReflectionSampler : register(s11); - -Texture2D ReflectionTex : register(t0); -Texture2D RefractionTex : register(t1); -Texture2D DisplacementTex : register(t2); -TextureCube CubeMapTex : register(t3); -Texture2D Normals01Tex : register(t4); -Texture2D Normals02Tex : register(t5); -Texture2D Normals03Tex : register(t6); -Texture2D DepthTex : register(t7); -Texture2D FlowMapTex : register(t8); -Texture2D FlowMapNormalsTex : register(t9); -Texture2D SSRReflectionTex : register(t10); -Texture2D RawSSRReflectionTex : register(t11); - -cbuffer PerTechnique : register(b0) +SamplerState ReflectionSampler : register(s0); +SamplerState RefractionSampler : register(s1); +SamplerState DisplacementSampler : register(s2); +SamplerState CubeMapSampler : register(s3); +SamplerState Normals01Sampler : register(s4); +SamplerState Normals02Sampler : register(s5); +SamplerState Normals03Sampler : register(s6); +SamplerState DepthSampler : register(s7); +SamplerState FlowMapSampler : register(s8); +SamplerState FlowMapNormalsSampler : register(s9); +SamplerState SSRReflectionSampler : register(s10); +SamplerState RawSSRReflectionSampler : register(s11); + +Texture2D ReflectionTex : register(t0); +Texture2D RefractionTex : register(t1); +Texture2D DisplacementTex : register(t2); +TextureCube CubeMapTex : register(t3); +Texture2D Normals01Tex : register(t4); +Texture2D Normals02Tex : register(t5); +Texture2D Normals03Tex : register(t6); +Texture2D DepthTex : register(t7); +Texture2D FlowMapTex : register(t8); +Texture2D FlowMapNormalsTex : register(t9); +Texture2D SSRReflectionTex : register(t10); +Texture2D RawSSRReflectionTex : register(t11); + +cbuffer PerTechnique : register(b0) { - float4 VPOSOffset : packoffset(c0); // inverse main render target width and height in xy, 0 in zw - float4 PosAdjust : packoffset(c1); // inverse framebuffer range in w - float4 CameraData : packoffset(c2); - float4 SunDir : packoffset(c3); - float4 SunColor : packoffset(c4); + float4 VPOSOffset : packoffset(c0); // inverse main render target width and height in xy, 0 in zw + float4 PosAdjust : packoffset(c1); // inverse framebuffer range in w + float4 CameraData : packoffset(c2); + float4 SunDir : packoffset(c3); + float4 SunColor : packoffset(c4); } -cbuffer PerMaterial : register(b1) +cbuffer PerMaterial : register(b1) { - float4 ShallowColor : packoffset(c0); - float4 DeepColor : packoffset(c1); - float4 ReflectionColor : packoffset(c2); - float4 FresnelRI : packoffset(c3); // Fresnel amount in x, specular power in z - float4 BlendRadius : packoffset(c4); // flowmap scale in y, specular radius in z - float4 VarAmounts : packoffset(c5); // Sun specular power in x, reflection amount in y, alpha in z, refraction magnitude in w - float4 NormalsAmplitude : packoffset(c6); - float4 WaterParams : packoffset(c7); // noise falloff in x, reflection magnitude in y, sun sparkle power in z, framebuffer range in w - float4 FogNearColor : packoffset(c8); // above water fog amount in w - float4 FogFarColor : packoffset(c9); - float4 FogParam : packoffset(c10); // above water fog distance far in z, above water fog range in w - float4 DepthControl : packoffset(c11); // depth reflections factor in x, depth refractions factor in y, depth normals factor in z, depth specular lighting factor in w - float4 SSRParams : packoffset(c12); // fWaterSSRIntensity in x, fWaterSSRBlurAmount in y, inverse main render target width and height in zw - float4 SSRParams2 : packoffset(c13); // fWaterSSRNormalPerturbationScale in x + float4 ShallowColor : packoffset(c0); + float4 DeepColor : packoffset(c1); + float4 ReflectionColor : packoffset(c2); + float4 FresnelRI : packoffset(c3); // Fresnel amount in x, specular power in z + float4 BlendRadius : packoffset(c4); // flowmap scale in y, specular radius in z + float4 VarAmounts : packoffset(c5); // Sun specular power in x, reflection amount in y, alpha in z, refraction magnitude in w + float4 NormalsAmplitude : packoffset(c6); + float4 WaterParams : packoffset(c7); // noise falloff in x, reflection magnitude in y, sun sparkle power in z, framebuffer range in w + float4 FogNearColor : packoffset(c8); // above water fog amount in w + float4 FogFarColor : packoffset(c9); + float4 FogParam : packoffset(c10); // above water fog distance far in z, above water fog range in w + float4 DepthControl : packoffset(c11); // depth reflections factor in x, depth refractions factor in y, depth normals factor in z, depth specular lighting factor in w + float4 SSRParams : packoffset(c12); // fWaterSSRIntensity in x, fWaterSSRBlurAmount in y, inverse main render target width and height in zw + float4 SSRParams2 : packoffset(c13); // fWaterSSRNormalPerturbationScale in x } -cbuffer PerGeometry : register(b2) +cbuffer PerGeometry : register(b2) { - float4x4 TextureProj : packoffset(c0); - float4 ReflectPlane : packoffset(c4); - float4 ProjData : packoffset(c5); - float4 LightPos[8] : packoffset(c6); - float4 LightColor[8] : packoffset(c14); + float4x4 TextureProj : packoffset(c0); + float4 ReflectPlane : packoffset(c4); + float4 ProjData : packoffset(c5); + float4 LightPos[8] : packoffset(c6); + float4 LightColor[8] : packoffset(c14); } -#if defined(SIMPLE) || defined(UNDERWATER) || defined(LOD) || defined(SPECULAR) -#if defined(FLOWMAP) +# if defined(SIMPLE) || defined(UNDERWATER) || defined(LOD) || defined(SPECULAR) +# if defined(FLOWMAP) float3 GetFlowmapNormal(PS_INPUT input, float2 uvShift, float multiplier, float offset) { float4 flowmapColor = FlowMapTex.Sample(FlowMapSampler, input.TexCoord2.zw + uvShift); @@ -296,11 +294,11 @@ float3 GetFlowmapNormal(PS_INPUT input, float2 uvShift, float multiplier, float rotatedFlowVector); return float3(FlowMapNormalsTex.Sample(FlowMapNormalsSampler, uv).xy, flowmapColor.z); } -#endif +# endif float3 GetWaterNormal(PS_INPUT input, float distanceFactor, float normalsDepthFactor) { -#if defined(FLOWMAP) +# if defined(FLOWMAP) float2 normalMul = 0.5 + -(-0.5 + abs(frac(input.TexCoord2.zw * (64 * input.TexCoord4)) * 2 - 1)); float uvShift = 1 / (128 * input.TexCoord4); @@ -321,15 +319,15 @@ float3 GetWaterNormal(PS_INPUT input, float distanceFactor, float normalsDepthFa 0); flowmapNormal.z = sqrt(1 - flowmapNormal.x * flowmapNormal.x - flowmapNormal.y * flowmapNormal.y); -#endif +# endif float3 normals1 = Normals01Tex.Sample(Normals01Sampler, input.TexCoord1.xy).xyz * 2.0 + float3(-1, -1, -2); -#if defined (FLOWMAP) && !defined(BLEND_NORMALS) +# if defined(FLOWMAP) && !defined(BLEND_NORMALS) float3 finalNormal = normalize(lerp(normals1 + float3(0, 0, 1), flowmapNormal, distanceFactor)); -#elif !defined(LOD) +# elif !defined(LOD) float3 normals2 = Normals02Tex.Sample(Normals02Sampler, input.TexCoord1.zw).xyz * 2.0 - 1.0; float3 normals3 = @@ -337,33 +335,33 @@ float3 GetWaterNormal(PS_INPUT input, float distanceFactor, float normalsDepthFa float3 blendedNormal = normalize(float3(0, 0, 1) + NormalsAmplitude.x * normals1 + NormalsAmplitude.y * normals2 + NormalsAmplitude.z * normals3); -#if defined (UNDERWATER) +# if defined(UNDERWATER) float3 finalNormal = blendedNormal; -#else +# else float3 finalNormal = normalize(lerp(float3(0, 0, 1), blendedNormal, normalsDepthFactor)); -#endif +# endif -#if defined(FLOWMAP) +# if defined(FLOWMAP) float normalBlendFactor = normalMul.y * ((1 - normalMul.x) * flowmapNormal3.z + normalMul.x * flowmapNormal2.z) + (1 - normalMul.y) * (normalMul.x * flowmapNormal1.z + (1 - normalMul.x) * flowmapNormal0.z); finalNormal = normalize(lerp(normals1 + float3(0, 0, 1), normalize(lerp(finalNormal, flowmapNormal, normalBlendFactor)), distanceFactor)); -#endif -#else +# endif +# else float3 finalNormal = normalize(float3(0, 0, 1) + NormalsAmplitude.xxx * normals1); -#endif +# endif -#if defined(WADING) -#if defined(FLOWMAP) +# if defined(WADING) +# if defined(FLOWMAP) float2 displacementUv = input.TexCoord3.zw; -#else +# else float2 displacementUv = input.TexCoord3.xy; -#endif +# endif float3 displacement = normalize(float3(NormalsAmplitude.w * (-0.5 + DisplacementTex.Sample(DisplacementSampler, displacementUv).zw), - 0.04)); + 0.04)); finalNormal = lerp(displacement, finalNormal, displacement.z); -#endif +# endif return finalNormal; } @@ -371,30 +369,30 @@ float3 GetWaterNormal(PS_INPUT input, float distanceFactor, float normalsDepthFa float3 GetWaterSpecularColor(PS_INPUT input, float3 normal, float3 viewDirection, float distanceFactor, float refractionsDepthFactor) { -#if defined(REFLECTIONS) +# if defined(REFLECTIONS) float3 finalSsrReflectionColor = 0.0.xxx; float ssrFraction = 0; -#if defined(CUBEMAP) +# if defined(CUBEMAP) float3 cubemapUV = reflect(viewDirection, WaterParams.y * normal + float3(0, 0, 1 - WaterParams.y)); float3 reflectionColor = CubeMapTex.Sample(CubeMapSampler, cubemapUV).xyz; -#else +# else -#if NUM_SPECULAR_LIGHTS == 0 +# if NUM_SPECULAR_LIGHTS == 0 float4 reflectionNormalRaw = float4((VarAmounts.w * refractionsDepthFactor) * normal.xy + input.MPosition.xy, input.MPosition.z, 1); -#else +# else float4 reflectionNormalRaw = float4(VarAmounts.w * normal.xy, reflectionNormalZ, 1); -#endif +# endif float4 reflectionNormal = mul(transpose(TextureProj), reflectionNormalRaw); float3 reflectionColor = ReflectionTex.Sample(ReflectionSampler, reflectionNormal.xy / reflectionNormal.ww).xyz; -#endif +# endif -#if defined(CUBEMAP) && NUM_SPECULAR_LIGHTS == 0 +# if defined(CUBEMAP) && NUM_SPECULAR_LIGHTS == 0 float2 ssrReflectionUv = GetDynamicResolutionAdjustedScreenPosition( (DynamicResolutionParams2.xy * input.HPosition.xy) * SSRParams.zw + SSRParams2.x * normal.xy); @@ -404,41 +402,41 @@ float3 GetWaterSpecularColor(PS_INPUT input, float3 normal, float3 viewDirection finalSsrReflectionColor = ssrReflectionColor.xyz; ssrFraction = saturate(ssrReflectionColor.w * (SSRParams.x * distanceFactor)); -#endif +# endif float3 finalReflectionColor = lerp(reflectionColor * WaterParams.w, finalSsrReflectionColor, ssrFraction); return lerp(ReflectionColor.xyz, finalReflectionColor, VarAmounts.y); -#else +# else return ReflectionColor.xyz * VarAmounts.y; -#endif +# endif } -#if defined(DEPTH) +# if defined(DEPTH) float GetScreenDepth(float2 screenPosition) { float depth = DepthTex.Load(float3(screenPosition, 0)).x; return (CameraData.w / (-depth * CameraData.z + CameraData.x)); } -#endif +# endif float3 GetLdotN(float3 normal) { -#if defined(INTERIOR) || defined(UNDERWATER) +# if defined(INTERIOR) || defined(UNDERWATER) return 1; -#else +# else return saturate(dot(SunDir.xyz, normal)); -#endif +# endif } float GetFresnelValue(float3 normal, float3 viewDirection) { -#if defined(UNDERWATER) +# if defined(UNDERWATER) float3 actualNormal = -normal; -#else +# else float3 actualNormal = normal; -#endif +# endif float viewAngle = 1 - saturate(dot(-viewDirection, actualNormal)); return (1 - FresnelRI.x) * pow(viewAngle, 5) + FresnelRI.x; } @@ -446,7 +444,7 @@ float GetFresnelValue(float3 normal, float3 viewDirection) float3 GetWaterDiffuseColor(PS_INPUT input, float3 normal, float3 viewDirection, float4 distanceMul, float refractionsDepthFactor, float fresnel) { -#if defined(REFRACTIONS) +# if defined(REFRACTIONS) float4 refractionNormal = mul(transpose(TextureProj), float4((VarAmounts.w * refractionsDepthFactor).xx * normal.xy + input.MPosition.xy, input.MPosition.z, 1)); @@ -454,7 +452,7 @@ float3 GetWaterDiffuseColor(PS_INPUT input, float3 normal, float3 viewDirection, float2 refractionUvRaw = float2(refractionNormal.x, refractionNormal.w - refractionNormal.y) / refractionNormal.ww; -#if defined(DEPTH) +# if defined(DEPTH) float depth = GetScreenDepth(DynamicResolutionParams1.xy * (DynamicResolutionParams2.xy * input.HPosition.xy)); float refractionDepth = GetScreenDepth(DynamicResolutionParams1.xy * (refractionUvRaw / VPOSOffset.xy)); @@ -469,33 +467,32 @@ float3 GetWaterDiffuseColor(PS_INPUT input, float3 normal, float3 viewDirection, float refractionPlaneMul = sign(refractionViewSurfaceAngle) * (1 - ReflectPlane.w / refractionViewSurfaceAngle); - if (refractionPlaneMul < 0) - { + if (refractionPlaneMul < 0) { refractionUvRaw = DynamicResolutionParams2.xy * input.HPosition.xy * VPOSOffset.xy + VPOSOffset.zw; } -#endif +# endif float2 refractionUV = GetDynamicResolutionAdjustedScreenPosition(refractionUvRaw); float3 refractionColor = RefractionTex.Sample(RefractionSampler, refractionUV).xyz; float3 refractionDiffuseColor = lerp(ShallowColor.xyz, DeepColor.xyz, distanceMul.y); -#if defined (UNDERWATER) +# if defined(UNDERWATER) float refractionMul = 0; -#else +# else float refractionMul = 1 - pow(saturate((-distanceMul.x * FogParam.z + FogParam.z) / FogParam.w), FogNearColor.w); -#endif +# endif return lerp(refractionColor * WaterParams.w, refractionDiffuseColor, refractionMul); -#else +# else return lerp(ShallowColor.xyz, DeepColor.xyz, fresnel) * GetLdotN(normal); -#endif +# endif } float3 GetSunColor(float3 normal, float3 viewDirection) { -#if defined(INTERIOR) || defined(UNDERWATER) +# if defined(INTERIOR) || defined(UNDERWATER) return 0.0.xxx; -#else +# else float3 reflectionDirection = reflect(viewDirection, normal); float reflectionMul = exp2(VarAmounts.x * log2(saturate(dot(reflectionDirection, SunDir.xyz)))); @@ -503,30 +500,30 @@ float3 GetSunColor(float3 normal, float3 viewDirection) float3 sunDirection = SunColor.xyz * SunDir.w; float sunMul = pow(saturate(dot(normal, float3(-0.099, -0.099, 0.99))), ShallowColor.w); return (reflectionMul * sunDirection) * DeepColor.w + WaterParams.z * (sunMul * sunDirection); -#endif +# endif } -#endif +# endif -#if defined(WATER_BLENDING) -#include "WaterBlending/WaterBlending.hlsli" -#endif +# if defined(WATER_BLENDING) +# include "WaterBlending/WaterBlending.hlsli" +# endif PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; -#if defined(SIMPLE) || defined(UNDERWATER) || defined(LOD) || defined(SPECULAR) +# if defined(SIMPLE) || defined(UNDERWATER) || defined(LOD) || defined(SPECULAR) float3 viewDirection = normalize(input.WPosition.xyz); - float distanceFactor = saturate(lerp(FrameParams.w, 1, (input.WPosition.w - 8192) / (WaterParams.x - 8192))); + float distanceFactor = saturate(lerp(FrameParams.w, 1, (input.WPosition.w - 8192) / (WaterParams.x - 8192))); float4 distanceMul = saturate(lerp(VarAmounts.z, 1, -(distanceFactor - 1))).xxxx; bool isSpecular = false; -#if defined(DEPTH) -#if defined(VERTEX_ALPHA_DEPTH) +# if defined(DEPTH) +# if defined(VERTEX_ALPHA_DEPTH) distanceMul = input.TexCoord3.z; -#else +# else float depth = GetScreenDepth( DynamicResolutionParams1.xy * (DynamicResolutionParams2.xy * input.HPosition.xy)); float2 depthOffset = @@ -540,28 +537,27 @@ PS_OUTPUT main(PS_INPUT input) distanceMul = saturate( planeMul * float4(length(depthAdjustedViewDirection).xx, abs(viewSurfaceAngle).xx) / FogParam.z); -#endif -#endif +# endif +# endif -#if defined(UNDERWATER) +# if defined(UNDERWATER) float4 depthControl = float4(0, 1, 1, 0); -#elif defined(LOD) +# elif defined(LOD) float4 depthControl = float4(1, 0, 0, 1); -#elif defined(SPECULAR) && (NUM_SPECULAR_LIGHTS != 0) +# elif defined(SPECULAR) && (NUM_SPECULAR_LIGHTS != 0) float4 depthControl = float4(0, 0, 1, 0); -#else +# else float4 depthControl = DepthControl * (distanceMul - 1) + 1; -#endif +# endif float3 normal = GetWaterNormal(input, distanceFactor, depthControl.z); - + float fresnel = GetFresnelValue(normal, viewDirection); -#if defined(SPECULAR) && (NUM_SPECULAR_LIGHTS != 0) +# if defined(SPECULAR) && (NUM_SPECULAR_LIGHTS != 0) float3 finalColor = 0.0.xxx; - for (int lightIndex = 0; lightIndex < NUM_SPECULAR_LIGHTS; ++lightIndex) - { + for (int lightIndex = 0; lightIndex < NUM_SPECULAR_LIGHTS; ++lightIndex) { float3 lightVector = LightPos[lightIndex].xyz - (PosAdjust.xyz + input.WPosition.xyz); float3 lightDirection = normalize(normalize(lightVector) - viewDirection); float lightFade = saturate(length(lightVector) / LightPos[lightIndex].w); @@ -574,65 +570,63 @@ PS_OUTPUT main(PS_INPUT input) finalColor *= fresnel; isSpecular = true; -#else +# else float3 specularColor = GetWaterSpecularColor(input, normal, viewDirection, distanceFactor, depthControl.y); float3 diffuseColor = GetWaterDiffuseColor(input, normal, viewDirection, distanceMul, depthControl.y, fresnel); -#if defined (UNDERWATER) +# if defined(UNDERWATER) float3 finalSpecularColor = lerp(ShallowColor.xyz, specularColor, 0.5); float3 finalColor = saturate(1 - input.WPosition.w * 0.002) * ((1 - fresnel) * (diffuseColor - finalSpecularColor)) + finalSpecularColor; -#else +# else float3 sunColor = GetSunColor(normal, viewDirection); float specularFraction = lerp(1, fresnel * depthControl.x, distanceFactor); float3 finalColorPreFog = lerp(diffuseColor, specularColor, specularFraction) + sunColor * depthControl.w; float3 finalColor = lerp(finalColorPreFog, input.FogParam.xyz, input.FogParam.w); -#endif -#endif +# endif +# endif psout.Lighting = saturate(float4(finalColor * PosAdjust.w, isSpecular)); -#if defined(WATER_BLENDING) -#if defined(DEPTH) - if (perPassWaterBlending[0].EnableWaterBlending){ - #if defined(VERTEX_ALPHA_DEPTH) - float blendFactor = 1 - smoothstep(0.0, 0.025 * perPassWaterBlending[0].WaterBlendRange, input.TexCoord3.z); - if (blendFactor > 0.0) - { - float4 background = RefractionTex.Load(float3(DynamicResolutionParams1.xy * (DynamicResolutionParams2.xy * input.HPosition.xy), 0)); - psout.Lighting.xyz = lerp(psout.Lighting.xyz, background.xyz, blendFactor); - psout.Lighting.w = lerp(psout.Lighting.w, background.w, blendFactor); - } - #else - float blendFactor = 1 - smoothstep(0.0, 0.025 * perPassWaterBlending[0].WaterBlendRange, distanceMul.z ); - - if (blendFactor > 0.0) - { - float4 background = RefractionTex.Load(float3(DynamicResolutionParams1.xy * (DynamicResolutionParams2.xy * input.HPosition.xy), 0)); - psout.Lighting.xyz = lerp(psout.Lighting.xyz, background.xyz, blendFactor); - psout.Lighting.w = lerp(psout.Lighting.w, background.w, blendFactor); - } - #endif +# if defined(WATER_BLENDING) +# if defined(DEPTH) + if (perPassWaterBlending[0].EnableWaterBlending) { +# if defined(VERTEX_ALPHA_DEPTH) + float blendFactor = 1 - smoothstep(0.0, 0.025 * perPassWaterBlending[0].WaterBlendRange, input.TexCoord3.z); + if (blendFactor > 0.0) { + float4 background = RefractionTex.Load(float3(DynamicResolutionParams1.xy * (DynamicResolutionParams2.xy * input.HPosition.xy), 0)); + psout.Lighting.xyz = lerp(psout.Lighting.xyz, background.xyz, blendFactor); + psout.Lighting.w = lerp(psout.Lighting.w, background.w, blendFactor); + } +# else + float blendFactor = 1 - smoothstep(0.0, 0.025 * perPassWaterBlending[0].WaterBlendRange, distanceMul.z); + + if (blendFactor > 0.0) { + float4 background = RefractionTex.Load(float3(DynamicResolutionParams1.xy * (DynamicResolutionParams2.xy * input.HPosition.xy), 0)); + psout.Lighting.xyz = lerp(psout.Lighting.xyz, background.xyz, blendFactor); + psout.Lighting.w = lerp(psout.Lighting.w, background.w, blendFactor); + } +# endif } -#endif -#endif +# endif +# endif -#endif +# endif -#if defined(STENCIL) +# if defined(STENCIL) float3 viewDirection = normalize(input.WorldPosition.xyz); - float3 normal = + float3 normal = normalize(cross(ddx_coarse(input.WorldPosition.xyz), ddy_coarse(input.WorldPosition.xyz))); float VdotN = dot(viewDirection, normal); psout.WaterMask = float4(0, 0, VdotN, 0); psout.MotionVector = GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition); -#endif +# endif return psout; } diff --git a/src/Buffer.h b/src/Buffer.h index 1ba490d44..70903cb54 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include diff --git a/src/Feature.cpp b/src/Feature.cpp index 4c876a202..96e1bbd40 100644 --- a/src/Feature.cpp +++ b/src/Feature.cpp @@ -1,10 +1,10 @@ #include "Feature.h" #include "Features/DistantTreeLighting.h" +#include "Features/ExtendedMaterials.h" #include "Features/GrassCollision.h" #include "Features/GrassLighting.h" #include "Features/ScreenSpaceShadows.h" -#include "Features/ExtendedMaterials.h" #include "Features/WaterBlending.h" void Feature::Load(json&) diff --git a/src/Features/ExtendedMaterials.h b/src/Features/ExtendedMaterials.h index 909084012..14f1836c7 100644 --- a/src/Features/ExtendedMaterials.h +++ b/src/Features/ExtendedMaterials.h @@ -10,7 +10,7 @@ struct ExtendedMaterials : Feature static ExtendedMaterials singleton; return &singleton; } - + virtual inline std::string GetName() { return "Complex Parallax Materials"; } virtual inline std::string GetShortName() { return "ComplexParallaxMaterials"; } @@ -19,7 +19,7 @@ struct ExtendedMaterials : Feature uint32_t EnableComplexMaterial = 1; uint32_t EnableParallax = 1; - uint32_t EnableTerrain =0; + uint32_t EnableTerrain = 0; uint32_t EnableHighQuality = 0; uint32_t MaxDistance = 2048; @@ -43,7 +43,7 @@ struct ExtendedMaterials : Feature std::unique_ptr perPass = nullptr; ID3D11SamplerState* terrainSampler = nullptr; - + virtual void SetupResources(); virtual inline void Reset() {} @@ -55,4 +55,3 @@ struct ExtendedMaterials : Feature virtual void Load(json& o_json); virtual void Save(json& o_json); }; - diff --git a/src/Features/GrassLighting.h b/src/Features/GrassLighting.h index 5c4d7beb6..ece32edb1 100644 --- a/src/Features/GrassLighting.h +++ b/src/Features/GrassLighting.h @@ -55,5 +55,4 @@ struct GrassLighting : Feature virtual void Load(json& o_json); virtual void Save(json& o_json); - }; diff --git a/src/Features/WaterBlending.h b/src/Features/WaterBlending.h index 23c9a7d31..6dba2ffaf 100644 --- a/src/Features/WaterBlending.h +++ b/src/Features/WaterBlending.h @@ -34,14 +34,13 @@ struct WaterBlending : Feature std::unique_ptr perPass = nullptr; - virtual void SetupResources(); virtual inline void Reset() {} virtual void DrawSettings(); virtual void Draw(const RE::BSShader* shader, const uint32_t descriptor); - + virtual void Load(json& o_json); virtual void Save(json& o_json); }; diff --git a/src/ShaderCache.cpp b/src/ShaderCache.cpp index a1cc8f34f..0fd72e584 100644 --- a/src/ShaderCache.cpp +++ b/src/ShaderCache.cpp @@ -6,11 +6,11 @@ #include #include -#include "State.h" +#include "Features/ExtendedMaterials.h" #include "Features/GrassCollision.h" #include "Features/ScreenSpaceShadows.h" #include "Features/WaterBlending.h" -#include "Features/ExtendedMaterials.h" +#include "State.h" namespace SIE { @@ -1104,13 +1104,12 @@ namespace SIE logger::debug("Compiled {} shader {}::{}", magic_enum::enum_name(shaderClass), magic_enum::enum_name(type), descriptor); - ID3DBlob* strippedShaderBlob = nullptr; const uint32_t stripFlags = D3DCOMPILER_STRIP_DEBUG_INFO | - D3DCOMPILER_STRIP_REFLECTION_DATA | - D3DCOMPILER_STRIP_TEST_BLOBS | - D3DCOMPILER_STRIP_PRIVATE_DATA; + D3DCOMPILER_STRIP_REFLECTION_DATA | + D3DCOMPILER_STRIP_TEST_BLOBS | + D3DCOMPILER_STRIP_PRIVATE_DATA; D3DStripShader(shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), stripFlags, &strippedShaderBlob); std::swap(shaderBlob, strippedShaderBlob); @@ -1119,8 +1118,6 @@ namespace SIE if (useDiskCache) { auto directoryPath = std::format("Data/ShaderCache/{}", shader.fxpFilename); if (!std::filesystem::is_directory(directoryPath)) { - - try { std::filesystem::create_directories(directoryPath); } catch (std::filesystem::filesystem_error const& ex) { @@ -1301,10 +1298,9 @@ namespace SIE return nullptr; } - if (shader.shaderType.get() == RE::BSShader::Type::Water) - { + if (shader.shaderType.get() == RE::BSShader::Type::Water) { const auto technique = (descriptor >> 11) & 0xF; - if (technique == 9) { // LOD + if (technique == 9) { // LOD return nullptr; } } diff --git a/src/ShaderCache.h b/src/ShaderCache.h index 42e558344..7b75bf365 100644 --- a/src/ShaderCache.h +++ b/src/ShaderCache.h @@ -85,7 +85,7 @@ namespace SIE type == RE::BSShader::Type::Water; return type == RE::BSShader::Type::Grass; } - + inline static bool IsSupportedShader(const RE::BSShader& shader) { return IsSupportedShader(shader.shaderType.get()); diff --git a/src/State.cpp b/src/State.cpp index fd1a3d139..1a4bdf41f 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -8,7 +8,7 @@ #include "Feature.h" #include "Features/Clustered.h" - void State::Draw() +void State::Draw() { auto& shaderCache = SIE::ShaderCache::Instance(); if (shaderCache.IsEnabled() && currentShader) { diff --git a/src/State.h b/src/State.h index 66ca94993..37ef5a4be 100644 --- a/src/State.h +++ b/src/State.h @@ -31,6 +31,4 @@ class State void SetLogLevel(spdlog::level::level_enum a_level = spdlog::level::info); spdlog::level::level_enum GetLogLevel(); - }; - diff --git a/src/Util.cpp b/src/Util.cpp index 9091858c3..6d3eb4ce5 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -61,7 +61,7 @@ namespace Util std::string GetNameFromSRV(ID3D11ShaderResourceView* a_srv) { using RENDER_TARGET = RE::RENDER_TARGETS::RENDER_TARGET; - + if (a_srv) { if (auto r = RE::BSGraphics::Renderer::GetSingleton()) { for (int i = 0; i < RENDER_TARGET::kTOTAL; i++) {