diff --git a/Squared/RenderLib/Content/BitmapCommon.fxh b/Squared/RenderLib/Content/BitmapCommon.fxh index e4fd267a9..e4c5b9e38 100644 --- a/Squared/RenderLib/Content/BitmapCommon.fxh +++ b/Squared/RenderLib/Content/BitmapCommon.fxh @@ -41,7 +41,9 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 texRgn : POSITION1 ) { - return (texRgn.xy + corner); + float2 texTL = min(texRgn.xy, texRgn.zw); + float2 texBR = max(texRgn.xy, texRgn.zw); + return clamp(texRgn.xy + corner, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -62,15 +64,6 @@ inline float2 ComputeRotatedCorner( ); } -inline void OutputRegions( - in float4 texRgn : POSITION1, - out float2 texTL : TEXCOORD1, - out float2 texBR : TEXCOORD2 -) { - texTL = min(texRgn.xy, texRgn.zw); - texBR = max(texRgn.xy, texRgn.zw); -} - void ScreenSpaceVertexShader( in float3 position : POSITION0, // x, y in float4 texRgn : POSITION1, // x1, y1, x2, y2 @@ -80,9 +73,7 @@ void ScreenSpaceVertexShader( inout float4 addColor : COLOR1, in int2 cornerIndex : BLENDINDICES0, // 0-3 out float2 texCoord : TEXCOORD0, - out float4 result : POSITION0, - out float2 texTL : TEXCOORD1, - out float2 texBR : TEXCOORD2 + out float4 result : POSITION0 ) { float2 regionSize = ComputeRegionSize(texRgn); float2 corner = ComputeCorner(cornerIndex, regionSize); @@ -92,7 +83,6 @@ void ScreenSpaceVertexShader( position.xy += rotatedCorner; result = TransformPosition(float4(position.xy, position.z, 1), 0.5); - OutputRegions(texRgn, texTL, texBR); } void WorldSpaceVertexShader( @@ -104,9 +94,7 @@ void WorldSpaceVertexShader( inout float4 addColor : COLOR1, in int2 cornerIndex : BLENDINDICES0, // 0-3 out float2 texCoord : TEXCOORD0, - out float4 result : POSITION0, - out float2 texTL : TEXCOORD1, - out float2 texBR : TEXCOORD2 + out float4 result : POSITION0 ) { float2 regionSize = ComputeRegionSize(texRgn); float2 corner = ComputeCorner(cornerIndex, regionSize); @@ -116,5 +104,4 @@ void WorldSpaceVertexShader( position.xy += rotatedCorner - ViewportPosition; result = TransformPosition(float4(position.xy * ViewportScale, position.z, 1), 0.5); - OutputRegions(texRgn, texTL, texBR); } \ No newline at end of file diff --git a/Squared/RenderLib/Content/SquaredBitmapShader.fx b/Squared/RenderLib/Content/SquaredBitmapShader.fx index be85e2db4..516d4572e 100644 --- a/Squared/RenderLib/Content/SquaredBitmapShader.fx +++ b/Squared/RenderLib/Content/SquaredBitmapShader.fx @@ -4,11 +4,8 @@ void BasicPixelShader( in float4 multiplyColor : COLOR0, in float4 addColor : COLOR1, in float2 texCoord : TEXCOORD0, - in float2 texTL : TEXCOORD1, - in float2 texBR : TEXCOORD2, out float4 result : COLOR0 ) { - texCoord = clamp(texCoord, texTL, texBR); addColor.rgb *= addColor.a; addColor.a = 0; diff --git a/Squared/RenderLib/PSM/generate_shaders.bat b/Squared/RenderLib/PSM/generate_shaders.bat index c17c10a14..1019a5372 100644 --- a/Squared/RenderLib/PSM/generate_shaders.bat +++ b/Squared/RenderLib/PSM/generate_shaders.bat @@ -1,4 +1,5 @@ @echo Generating shaders... +@rmdir /s/q generated @mkdir generated @mkdir generated\shaders @for %%f IN (shaders\*.fcg) DO tcc.exe -E %%f -o generated\%%f diff --git a/Squared/RenderLib/PSM/generated/shaders/Bitmap.fcgh b/Squared/RenderLib/PSM/generated/shaders/Bitmap.fcgh index 928558256..e85ee6f2f 100644 --- a/Squared/RenderLib/PSM/generated/shaders/Bitmap.fcgh +++ b/Squared/RenderLib/PSM/generated/shaders/Bitmap.fcgh @@ -11,9 +11,7 @@ void main( in float2 texBR : TEXCOORD2, out float4 result : COLOR ) { - float2 texCoord = clamp(texCoordOut, texTL, texBR); - - float4 texColor = tex2D(BitmapTexture, texCoord); + float4 texColor = tex2D(BitmapTexture, texCoordOut); addColorOut.rgb *= addColorOut.a; addColorOut.a = 0; diff --git a/Squared/RenderLib/PSM/generated/shaders/Bitmap.vcgh b/Squared/RenderLib/PSM/generated/shaders/Bitmap.vcgh index 659a9089a..001199f5f 100644 --- a/Squared/RenderLib/PSM/generated/shaders/Bitmap.vcgh +++ b/Squared/RenderLib/PSM/generated/shaders/Bitmap.vcgh @@ -4,7 +4,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -34,7 +34,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -56,16 +59,6 @@ inline float2 ComputeRotatedCorner( (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; } - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} # 3 "shaders/Bitmap.vcgh" void main( in uniform float4x4 ProjectionMatrix, @@ -108,9 +101,6 @@ void main( transformedPosition = TransformPosition(ProjectionMatrix, ModelViewMatrix, float4(position.xy, position.z, 1)); transformedPosition2 = transformedPosition; - OutputRegions( - HalfTexel, textureRegion, texTL, texBR - ); multiplyColorOut = multiplyColor; addColorOut = addColor; diff --git a/Squared/RenderLib/PSM/generated/shaders/Geometry.vcgh b/Squared/RenderLib/PSM/generated/shaders/Geometry.vcgh index fd75378fe..c924e0dea 100644 --- a/Squared/RenderLib/PSM/generated/shaders/Geometry.vcgh +++ b/Squared/RenderLib/PSM/generated/shaders/Geometry.vcgh @@ -4,7 +4,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -34,7 +34,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -56,16 +59,6 @@ inline float2 ComputeRotatedCorner( (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; } - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} # 3 "shaders/Geometry.vcgh" void main( in uniform float4x4 ProjectionMatrix, diff --git a/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.fcg b/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.fcg index 928558256..e85ee6f2f 100644 --- a/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.fcg +++ b/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.fcg @@ -11,9 +11,7 @@ void main( in float2 texBR : TEXCOORD2, out float4 result : COLOR ) { - float2 texCoord = clamp(texCoordOut, texTL, texBR); - - float4 texColor = tex2D(BitmapTexture, texCoord); + float4 texColor = tex2D(BitmapTexture, texCoordOut); addColorOut.rgb *= addColorOut.a; addColorOut.a = 0; diff --git a/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.vcg b/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.vcg index 659a9089a..001199f5f 100644 --- a/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.vcg +++ b/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.vcg @@ -4,7 +4,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -34,7 +34,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -56,16 +59,6 @@ inline float2 ComputeRotatedCorner( (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; } - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} # 3 "shaders/Bitmap.vcgh" void main( in uniform float4x4 ProjectionMatrix, @@ -108,9 +101,6 @@ void main( transformedPosition = TransformPosition(ProjectionMatrix, ModelViewMatrix, float4(position.xy, position.z, 1)); transformedPosition2 = transformedPosition; - OutputRegions( - HalfTexel, textureRegion, texTL, texBR - ); multiplyColorOut = multiplyColor; addColorOut = addColor; diff --git a/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceGeometry.vcg b/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceGeometry.vcg index fd75378fe..c924e0dea 100644 --- a/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceGeometry.vcg +++ b/Squared/RenderLib/PSM/generated/shaders/ScreenSpaceGeometry.vcg @@ -4,7 +4,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -34,7 +34,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -56,16 +59,6 @@ inline float2 ComputeRotatedCorner( (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; } - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} # 3 "shaders/Geometry.vcgh" void main( in uniform float4x4 ProjectionMatrix, diff --git a/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.fcg b/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.fcg index 928558256..e85ee6f2f 100644 --- a/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.fcg +++ b/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.fcg @@ -11,9 +11,7 @@ void main( in float2 texBR : TEXCOORD2, out float4 result : COLOR ) { - float2 texCoord = clamp(texCoordOut, texTL, texBR); - - float4 texColor = tex2D(BitmapTexture, texCoord); + float4 texColor = tex2D(BitmapTexture, texCoordOut); addColorOut.rgb *= addColorOut.a; addColorOut.a = 0; diff --git a/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.vcg b/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.vcg index 5ed0e50ee..1f1703c28 100644 --- a/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.vcg +++ b/Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.vcg @@ -4,7 +4,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -34,7 +34,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -56,16 +59,6 @@ inline float2 ComputeRotatedCorner( (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; } - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} # 3 "shaders/Bitmap.vcgh" void main( in uniform float4x4 ProjectionMatrix, @@ -108,9 +101,6 @@ void main( transformedPosition = TransformPosition(ProjectionMatrix, ModelViewMatrix, float4(position.xy, position.z, 1)); transformedPosition2 = transformedPosition; - OutputRegions( - HalfTexel, textureRegion, texTL, texBR - ); multiplyColorOut = multiplyColor; addColorOut = addColor; diff --git a/Squared/RenderLib/PSM/generated/shaders/WorldSpaceGeometry.vcg b/Squared/RenderLib/PSM/generated/shaders/WorldSpaceGeometry.vcg index 8126b3a2f..db5af80a0 100644 --- a/Squared/RenderLib/PSM/generated/shaders/WorldSpaceGeometry.vcg +++ b/Squared/RenderLib/PSM/generated/shaders/WorldSpaceGeometry.vcg @@ -4,7 +4,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -34,7 +34,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -56,16 +59,6 @@ inline float2 ComputeRotatedCorner( (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; } - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} # 3 "shaders/Geometry.vcgh" void main( in uniform float4x4 ProjectionMatrix, diff --git a/Squared/RenderLib/PSM/shaders/Bitmap.fcgh b/Squared/RenderLib/PSM/shaders/Bitmap.fcgh index ead286a22..6580471ea 100644 --- a/Squared/RenderLib/PSM/shaders/Bitmap.fcgh +++ b/Squared/RenderLib/PSM/shaders/Bitmap.fcgh @@ -10,9 +10,7 @@ void main( in float2 texBR : TEXCOORD2, out float4 result : COLOR ) { - float2 texCoord = clamp(texCoordOut, texTL, texBR); - - float4 texColor = tex2D(BitmapTexture, texCoord); + float4 texColor = tex2D(BitmapTexture, texCoordOut); addColorOut.rgb *= addColorOut.a; addColorOut.a = 0; diff --git a/Squared/RenderLib/PSM/shaders/Bitmap.vcgh b/Squared/RenderLib/PSM/shaders/Bitmap.vcgh index 172d45de9..2251cbb85 100644 --- a/Squared/RenderLib/PSM/shaders/Bitmap.vcgh +++ b/Squared/RenderLib/PSM/shaders/Bitmap.vcgh @@ -41,9 +41,6 @@ void main( transformedPosition = TransformPosition(ProjectionMatrix, ModelViewMatrix, float4(position.xy, position.z, 1)); transformedPosition2 = transformedPosition; - OutputRegions( - HalfTexel, textureRegion, texTL, texBR - ); multiplyColorOut = multiplyColor; addColorOut = addColor; diff --git a/Squared/RenderLib/PSM/shaders/VertexCommon.cgh b/Squared/RenderLib/PSM/shaders/VertexCommon.cgh index bafc5f392..ae3af7758 100644 --- a/Squared/RenderLib/PSM/shaders/VertexCommon.cgh +++ b/Squared/RenderLib/PSM/shaders/VertexCommon.cgh @@ -3,7 +3,7 @@ float4 TransformPosition ( in float4x4 ProjectionMatrix, float4 position ) { - return mul(mul(position, ModelViewMatrix), ProjectionMatrix); + return mul(mul(position, ProjectionMatrix), ModelViewMatrix); } inline float2 ComputeRegionSize( @@ -33,7 +33,10 @@ inline float2 ComputeTexCoord( in float2 corner, in float4 textureRegion ) { - return (textureRegion.xy + corner) + halfTexel; + float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel; + float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel; + + return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR); } inline float2 ComputeRotatedCorner( @@ -54,14 +57,4 @@ inline float2 ComputeRotatedCorner( (sinCos.y * corner.x) - (sinCos.x * corner.y), (sinCos.x * corner.x) + (sinCos.y * corner.y) ) - halfTexel; -} - -inline void OutputRegions( - in uniform float2 halfTexel, - in float4 textureRegion, - out float2 texTL, - out float2 texBR -) { - texTL = min(textureRegion.xy, textureRegion.zw) + halfTexel; - texBR = max(textureRegion.xy, textureRegion.zw) - halfTexel; -} +} \ No newline at end of file