From a76c0234d448706aca0e93dd9c146b275ee1e263 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Sat, 12 Dec 2020 01:09:44 -0800 Subject: [PATCH 1/5] experimenting with g buffer sprites --- Effects/DeferredPBR_GBufferEffect.cs | 14 ++++++++++++++ Effects/DeferredPBR_PointLightEffect.cs | 16 ++++++++++++++-- Effects/FXB/DeferredPBR_GBufferEffect.fxb | 4 ++-- Effects/FXB/DeferredPBR_PointLightEffect.fxb | 4 ++-- Effects/HLSL/DeferredPBR_GBufferEffect.fx | 17 +++++++++-------- Effects/HLSL/DeferredPBR_PointLightEffect.fx | 20 ++++++++++++++------ Renderer.cs | 4 ++++ 7 files changed, 59 insertions(+), 20 deletions(-) diff --git a/Effects/DeferredPBR_GBufferEffect.cs b/Effects/DeferredPBR_GBufferEffect.cs index aa7c769..3c480ca 100644 --- a/Effects/DeferredPBR_GBufferEffect.cs +++ b/Effects/DeferredPBR_GBufferEffect.cs @@ -17,6 +17,7 @@ namespace Kav EffectParameter roughnessParam; EffectParameter uvOffsetAndDimensionsParam; + EffectParameter isSpriteParam; EffectParameter numTextureRowsParam; EffectParameter numTextureColumnsParam; @@ -35,6 +36,8 @@ namespace Kav Vector2 uvOffset; Vector2 subTextureDimensions; + bool isSprite = false; + int numTextureRows = 1; int numTextureColumns = 1; @@ -178,6 +181,16 @@ namespace Kav } } + public bool IsSprite + { + get { return isSprite; } + set + { + isSprite = value; + isSpriteParam.SetValue(isSprite ? 1f : 0f); + } + } + public bool HardwareInstancingEnabled { get { return hardwareInstancingEnabled; } @@ -313,6 +326,7 @@ namespace Kav numTextureColumnsParam = Parameters["NumTextureColumns"]; uvOffsetAndDimensionsParam = Parameters["UVOffsetAndDimensions"]; + isSpriteParam = Parameters["IsSprite"]; shaderIndexParam = Parameters["PixelShaderIndex"]; vertexShaderIndexParam = Parameters["VertexShaderIndex"]; diff --git a/Effects/DeferredPBR_PointLightEffect.cs b/Effects/DeferredPBR_PointLightEffect.cs index b792ae0..6a85806 100644 --- a/Effects/DeferredPBR_PointLightEffect.cs +++ b/Effects/DeferredPBR_PointLightEffect.cs @@ -18,6 +18,8 @@ namespace Kav EffectParameter farPlaneParam; + EffectParameter worldParam; + EffectParameter worldInverseParam; EffectParameter worldViewProjectionParam; public Texture2D GPosition { get; set; } @@ -45,7 +47,7 @@ namespace Kav set { world = value; - dirtyFlags |= EffectDirtyFlags.WorldViewProj; + dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World; } } @@ -77,7 +79,7 @@ namespace Kav public DeferredPBR_PointLightEffect(DeferredPBR_PointLightEffect cloneSource) : base(cloneSource) { CacheEffectParameters(); - + GPosition = cloneSource.GPosition; GAlbedo = cloneSource.GAlbedo; GNormal = cloneSource.GNormal; @@ -112,6 +114,14 @@ namespace Kav farPlaneParam.SetValue(FarPlane); + if ((dirtyFlags & EffectDirtyFlags.World) != 0) + { + worldParam.SetValue(world); + worldInverseParam.SetValue(Matrix.Invert(world)); + + dirtyFlags &= ~EffectDirtyFlags.World; + } + if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0) { worldViewProjectionParam.SetValue(world * view * projection); @@ -135,6 +145,8 @@ namespace Kav farPlaneParam = Parameters["FarPlane"]; + worldParam = Parameters["World"]; + worldInverseParam = Parameters["WorldInverse"]; worldViewProjectionParam = Parameters["WorldViewProjection"]; } } diff --git a/Effects/FXB/DeferredPBR_GBufferEffect.fxb b/Effects/FXB/DeferredPBR_GBufferEffect.fxb index 192aa11..634fc74 100644 --- a/Effects/FXB/DeferredPBR_GBufferEffect.fxb +++ b/Effects/FXB/DeferredPBR_GBufferEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0c58e459d43bf43461f48bc4986b7c923fc63c319fd68f074bb1cddc4c8b564f -size 9564 +oid sha256:e5dcaaa764a1d8429b57e96e50b28b16f46152cf2ae8db9ee3ae957da842fbad +size 10916 diff --git a/Effects/FXB/DeferredPBR_PointLightEffect.fxb b/Effects/FXB/DeferredPBR_PointLightEffect.fxb index a05cd21..f7cfc76 100644 --- a/Effects/FXB/DeferredPBR_PointLightEffect.fxb +++ b/Effects/FXB/DeferredPBR_PointLightEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9a30fb7bc8d5af4490f415509711762aa45ee8d5ef4c67d01eb8ae6af10778a0 -size 4076 +oid sha256:19dd54568190283d2d0137af4489bc1478fc4901f62dd64421bceb4f2980645c +size 5192 diff --git a/Effects/HLSL/DeferredPBR_GBufferEffect.fx b/Effects/HLSL/DeferredPBR_GBufferEffect.fx index c546e01..f5666ab 100644 --- a/Effects/HLSL/DeferredPBR_GBufferEffect.fx +++ b/Effects/HLSL/DeferredPBR_GBufferEffect.fx @@ -5,6 +5,7 @@ DECLARE_TEXTURE(NormalTexture, 1); DECLARE_TEXTURE(MetallicRoughnessTexture, 2); float4 UVOffsetAndDimensions; +float IsSprite; BEGIN_CONSTANTS @@ -119,7 +120,7 @@ PixelOutput NonePS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(normalize(input.NormalWorld), 1.0); + output.gNormal = float4(normalize(input.NormalWorld), IsSprite); output.gAlbedo = float4(AlbedoValue, 1.0); output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0); @@ -131,7 +132,7 @@ PixelOutput AlbedoPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(normalize(input.NormalWorld), 1.0); + output.gNormal = float4(normalize(input.NormalWorld), IsSprite); output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord); output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0); @@ -145,7 +146,7 @@ PixelOutput MetallicRoughnessPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(normalize(input.NormalWorld), 1.0); + output.gNormal = float4(normalize(input.NormalWorld), IsSprite); output.gAlbedo = float4(AlbedoValue, 1.0); output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord); @@ -157,7 +158,7 @@ PixelOutput NormalPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0); + output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite); output.gAlbedo = float4(AlbedoValue, 1.0); output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0); @@ -169,7 +170,7 @@ PixelOutput AlbedoMetallicRoughnessPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(normalize(input.NormalWorld), 1.0); + output.gNormal = float4(normalize(input.NormalWorld), IsSprite); output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord); output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord); @@ -183,7 +184,7 @@ PixelOutput AlbedoNormalPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0); + output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite); output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord); output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0); @@ -197,7 +198,7 @@ PixelOutput MetallicRoughnessNormalPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0); + output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite); output.gAlbedo = float4(AlbedoValue, 1.0); output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord); @@ -209,7 +210,7 @@ PixelOutput AlbedoMetallicRoughnessNormalMapPS(PixelInput input) PixelOutput output; output.gPosition = float4(input.PositionWorld, 1.0); - output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0); + output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite); output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord); output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord); diff --git a/Effects/HLSL/DeferredPBR_PointLightEffect.fx b/Effects/HLSL/DeferredPBR_PointLightEffect.fx index 0195594..c9d5643 100644 --- a/Effects/HLSL/DeferredPBR_PointLightEffect.fx +++ b/Effects/HLSL/DeferredPBR_PointLightEffect.fx @@ -1,7 +1,7 @@ // Assumes you are drawing a sphere!! #include "Macros.fxh" //from FNA -#include "Lighting.fxh" +#include "Lighting.fxh" #include "Shadow.fxh" DECLARE_TEXTURE(gPosition, 0); @@ -13,7 +13,7 @@ DECLARE_CUBEMAP(shadowMap, 4); BEGIN_CONSTANTS float3 EyePosition _ps(c0) _cb(c0); - + float3 PointLightPosition _ps(c1) _cb(c1); float3 PointLightColor _ps(c2) _cb(c2); @@ -21,6 +21,8 @@ BEGIN_CONSTANTS MATRIX_CONSTANTS + float4x4 WorldInverse _ps(c4) _cb(c8); + float4x4 World _ps(c8) _cb(c12); float4x4 WorldViewProjection _vs(c0) _cb(c4); END_CONSTANTS @@ -42,7 +44,7 @@ PixelInput main_vs(VertexInput input) output.Position = mul(input.Position, WorldViewProjection); output.ScreenPosition = output.Position; - + return output; } @@ -78,19 +80,25 @@ float4 main_ps(PixelInput input) : SV_TARGET0 { input.ScreenPosition.xy /= input.ScreenPosition.w; float2 texCoord = 0.5f * float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 0.5f; - + float3 worldPosition = SAMPLE_TEXTURE(gPosition, texCoord).rgb; - float3 normal = SAMPLE_TEXTURE(gNormal, texCoord).xyz; + float4 normalSample = SAMPLE_TEXTURE(gNormal, texCoord); + float3 normal = normalSample.xyz; + float isSprite = normalSample.a; float3 albedo = SAMPLE_TEXTURE(gAlbedo, texCoord).rgb; float2 metallicRoughness = SAMPLE_TEXTURE(gMetallicRoughness, texCoord).rg; + float3 objectZNormal = mul(normal, WorldInverse); + objectZNormal.xz *= -1; + float3 invertedZNormalWorld = mul(objectZNormal, World); + return ComputeColor( worldPosition, normal, albedo, metallicRoughness.r, metallicRoughness.g - ); + ) + (isSprite * ComputeColor(worldPosition, invertedZNormalWorld, albedo, metallicRoughness.r, metallicRoughness.g)); } Technique DeferredPBR_Point diff --git a/Renderer.cs b/Renderer.cs index 154b6da..203c265 100644 --- a/Renderer.cs +++ b/Renderer.cs @@ -207,6 +207,8 @@ namespace Kav GraphicsDevice.BlendState = BlendState.AlphaBlend; Deferred_GBufferEffect.HardwareInstancingEnabled = false; + Deferred_GBufferEffect.IsSprite = true; + Deferred_GBufferEffect.View = camera.View; Deferred_GBufferEffect.Projection = camera.Projection; @@ -418,6 +420,7 @@ namespace Kav GraphicsDevice.BlendState = BlendState.Opaque; Deferred_GBufferEffect.HardwareInstancingEnabled = true; + Deferred_GBufferEffect.IsSprite = false; Deferred_GBufferEffect.Albedo = drawable.Albedo; Deferred_GBufferEffect.Metallic = drawable.Metallic; @@ -465,6 +468,7 @@ namespace Kav GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; + Deferred_GBufferEffect.IsSprite = false; Deferred_GBufferEffect.HardwareInstancingEnabled = false; Deferred_GBufferEffect.View = camera.View; Deferred_GBufferEffect.Projection = camera.Projection; -- 2.25.1 From 9bd7f84d26066ebca392afe031d08a9d58505b7e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Sat, 12 Dec 2020 02:36:53 -0800 Subject: [PATCH 2/5] flat sprite lighting in deferred pipeline --- Effects/DeferredPBR_PointLightEffect.cs | 14 +-------- Effects/FXB/DeferredPBR_PointLightEffect.fxb | 4 +-- Effects/HLSL/DeferredPBR_PointLightEffect.fx | 31 ++++++++++++-------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/Effects/DeferredPBR_PointLightEffect.cs b/Effects/DeferredPBR_PointLightEffect.cs index 6a85806..63e4af2 100644 --- a/Effects/DeferredPBR_PointLightEffect.cs +++ b/Effects/DeferredPBR_PointLightEffect.cs @@ -18,8 +18,6 @@ namespace Kav EffectParameter farPlaneParam; - EffectParameter worldParam; - EffectParameter worldInverseParam; EffectParameter worldViewProjectionParam; public Texture2D GPosition { get; set; } @@ -47,7 +45,7 @@ namespace Kav set { world = value; - dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World; + dirtyFlags |= EffectDirtyFlags.WorldViewProj; } } @@ -114,14 +112,6 @@ namespace Kav farPlaneParam.SetValue(FarPlane); - if ((dirtyFlags & EffectDirtyFlags.World) != 0) - { - worldParam.SetValue(world); - worldInverseParam.SetValue(Matrix.Invert(world)); - - dirtyFlags &= ~EffectDirtyFlags.World; - } - if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0) { worldViewProjectionParam.SetValue(world * view * projection); @@ -145,8 +135,6 @@ namespace Kav farPlaneParam = Parameters["FarPlane"]; - worldParam = Parameters["World"]; - worldInverseParam = Parameters["WorldInverse"]; worldViewProjectionParam = Parameters["WorldViewProjection"]; } } diff --git a/Effects/FXB/DeferredPBR_PointLightEffect.fxb b/Effects/FXB/DeferredPBR_PointLightEffect.fxb index f7cfc76..010f5d6 100644 --- a/Effects/FXB/DeferredPBR_PointLightEffect.fxb +++ b/Effects/FXB/DeferredPBR_PointLightEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:19dd54568190283d2d0137af4489bc1478fc4901f62dd64421bceb4f2980645c -size 5192 +oid sha256:b98c96aaebb45d196293e1be3716517eaca204dd83eb17768653bd060954ec45 +size 4144 diff --git a/Effects/HLSL/DeferredPBR_PointLightEffect.fx b/Effects/HLSL/DeferredPBR_PointLightEffect.fx index c9d5643..5e7eed1 100644 --- a/Effects/HLSL/DeferredPBR_PointLightEffect.fx +++ b/Effects/HLSL/DeferredPBR_PointLightEffect.fx @@ -21,8 +21,6 @@ BEGIN_CONSTANTS MATRIX_CONSTANTS - float4x4 WorldInverse _ps(c4) _cb(c8); - float4x4 World _ps(c8) _cb(c12); float4x4 WorldViewProjection _vs(c0) _cb(c4); END_CONSTANTS @@ -88,17 +86,26 @@ float4 main_ps(PixelInput input) : SV_TARGET0 float3 albedo = SAMPLE_TEXTURE(gAlbedo, texCoord).rgb; float2 metallicRoughness = SAMPLE_TEXTURE(gMetallicRoughness, texCoord).rg; - float3 objectZNormal = mul(normal, WorldInverse); - objectZNormal.xz *= -1; - float3 invertedZNormalWorld = mul(objectZNormal, World); + if (isSprite == 1.0) + { + float3 lightDir = PointLightPosition - worldPosition; + float3 L = normalize(lightDir); + float distance = length(lightDir); + float attenuation = 1.0 / (distance * distance); + float3 radiance = PointLightColor * attenuation; - return ComputeColor( - worldPosition, - normal, - albedo, - metallicRoughness.r, - metallicRoughness.g - ) + (isSprite * ComputeColor(worldPosition, invertedZNormalWorld, albedo, metallicRoughness.r, metallicRoughness.g)); + return float4(albedo * radiance * 0.1, 1.0); + } + else + { + return ComputeColor( + worldPosition, + normal, + albedo, + metallicRoughness.r, + metallicRoughness.g + ); + } } Technique DeferredPBR_Point -- 2.25.1 From c69e659ba56c06268cace0f405ef57bb11f8db12 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Sat, 12 Dec 2020 03:20:55 -0800 Subject: [PATCH 3/5] more sprite mesh rendering --- Renderer.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Renderer.cs b/Renderer.cs index 203c265..5c9935d 100644 --- a/Renderer.cs +++ b/Renderer.cs @@ -199,11 +199,12 @@ namespace Kav public void RenderMeshSpriteGBuffer( RenderTargetBinding[] gBuffer, PerspectiveCamera camera, - IEnumerable meshSpriteDrawDatas + IEnumerable meshSpriteDrawDatas, + DepthStencilState depthStencilState ) { GraphicsDevice.SetRenderTargets(gBuffer); GraphicsDevice.RasterizerState = RasterizerState.CullNone; - GraphicsDevice.DepthStencilState = DepthStencilState.Default; + GraphicsDevice.DepthStencilState = depthStencilState; GraphicsDevice.BlendState = BlendState.AlphaBlend; Deferred_GBufferEffect.HardwareInstancingEnabled = false; @@ -377,6 +378,21 @@ namespace Kav ); } + public void RenderDepthIndexed( + RenderTarget2D renderTarget, + PerspectiveCamera camera, + T drawable, + DepthStencilState depthStencilState + ) where T : IIndexDrawable { + GraphicsDevice.SetRenderTarget(renderTarget); + GraphicsDevice.DepthStencilState = depthStencilState; + + SimpleDepthEffect.View = camera.View; + SimpleDepthEffect.Projection = camera.Projection; + + RenderIndexed(GraphicsDevice, drawable, SimpleDepthEffect); + } + public void RenderSkybox( RenderTarget2D renderTarget, PerspectiveCamera camera, -- 2.25.1 From 4ee7c53907967fb60253f79a7c6be96a34834c24 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Sat, 12 Dec 2020 01:23:08 -0800 Subject: [PATCH 4/5] fix diffuse lit effect not discarding transparency --- Effects/FXB/DiffuseLitSpriteEffect.fxb | 4 ++-- Effects/HLSL/DiffuseLitSpriteEffect.fx | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Effects/FXB/DiffuseLitSpriteEffect.fxb b/Effects/FXB/DiffuseLitSpriteEffect.fxb index 6611fbc..5902373 100644 --- a/Effects/FXB/DiffuseLitSpriteEffect.fxb +++ b/Effects/FXB/DiffuseLitSpriteEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:739429f89531ea53a1eebb8e19d43615af2b6d4ee80102f18dce969b8dfcc6af -size 7340 +oid sha256:cba6863140b91a4dd83f10bc7e1acaf3ab317d5a77e9deea5102723bfe805ab9 +size 7396 diff --git a/Effects/HLSL/DiffuseLitSpriteEffect.fx b/Effects/HLSL/DiffuseLitSpriteEffect.fx index bdc2504..6173e4e 100644 --- a/Effects/HLSL/DiffuseLitSpriteEffect.fx +++ b/Effects/HLSL/DiffuseLitSpriteEffect.fx @@ -98,6 +98,9 @@ float4 LightColor(float3 worldPosition, float3 worldNormal) float4 WithoutNormalMap(PixelShaderInput input) : COLOR0 { float4 tex = SAMPLE_TEXTURE(Texture, input.TexCoord); + + if (tex.a == 0.0) { discard; } + float3 normalWS = normalize(input.NormalWS); return tex * LightColor(input.PositionWS, normalWS); @@ -106,6 +109,9 @@ float4 WithoutNormalMap(PixelShaderInput input) : COLOR0 float4 WithNormalMap(PixelShaderInput input) : COLOR0 { float4 tex = SAMPLE_TEXTURE(Texture, input.TexCoord); + + if (tex.a == 0.0) { discard; } + float3 normalWS = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS); return tex * LightColor(input.PositionWS, normalWS); -- 2.25.1 From b964af26bd5dbcd16f3a7b278996cc8b5858d832 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Sat, 12 Dec 2020 21:07:22 -0800 Subject: [PATCH 5/5] fix bad palette crush FLT_MAX --- Effects/FXB/PaletteCrushEffect.fxb | 4 ++-- Effects/HLSL/PaletteCrushEffect.fx | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Effects/FXB/PaletteCrushEffect.fxb b/Effects/FXB/PaletteCrushEffect.fxb index dfb94e4..ac29c12 100644 --- a/Effects/FXB/PaletteCrushEffect.fxb +++ b/Effects/FXB/PaletteCrushEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:601be54d2ff0278fd16cffd6954d26694c370f7356a715498d94932fe77e3a2f -size 1432 +oid sha256:6cdabdcd65c5293be1d7fe304dcd390f7b5fd3065f1c2135697de09873bc3c9b +size 1448 diff --git a/Effects/HLSL/PaletteCrushEffect.fx b/Effects/HLSL/PaletteCrushEffect.fx index 6126199..23143af 100644 --- a/Effects/HLSL/PaletteCrushEffect.fx +++ b/Effects/HLSL/PaletteCrushEffect.fx @@ -1,7 +1,5 @@ #include "Macros.fxh" -#define FLT_MAX 3.402823466e+38 - DECLARE_TEXTURE(Texture, 0); DECLARE_TEXTURE(Palette, 1); @@ -40,11 +38,12 @@ float4 main_ps(PixelInput input) : SV_TARGET0 float3 sampled_color = sampled.rgb; float3 closest_color = float3(0, 0, 0); - float closest_dist = FLT_MAX; + float closest_dist = 100000; for (int i = 0; i < PaletteWidth; i++) { - float3 palette_color = SAMPLE_TEXTURE(Palette, float2(i / (float)PaletteWidth, 0)); + float texX = (i / (float)PaletteWidth); + float3 palette_color = SAMPLE_TEXTURE(Palette, float2(texX, 0)); float dist = distance(palette_color, sampled_color); if (dist < closest_dist) { -- 2.25.1