Skip to content

Commit

Permalink
Merge github.com:kevingadd/Fracture
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Feb 25, 2013
2 parents 346e4c4 + 02c6063 commit 8b9ec20
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 130 deletions.
23 changes: 5 additions & 18 deletions Squared/RenderLib/Content/BitmapCommon.fxh
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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);
}
3 changes: 0 additions & 3 deletions Squared/RenderLib/Content/SquaredBitmapShader.fx
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions 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
Expand Down
4 changes: 1 addition & 3 deletions Squared/RenderLib/PSM/generated/shaders/Bitmap.fcgh
Expand Up @@ -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;
Expand Down
20 changes: 5 additions & 15 deletions Squared/RenderLib/PSM/generated/shaders/Bitmap.vcgh
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 5 additions & 12 deletions Squared/RenderLib/PSM/generated/shaders/Geometry.vcgh
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Expand Up @@ -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;
Expand Down
20 changes: 5 additions & 15 deletions Squared/RenderLib/PSM/generated/shaders/ScreenSpaceBitmap.vcg
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 5 additions & 12 deletions Squared/RenderLib/PSM/generated/shaders/ScreenSpaceGeometry.vcg
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.fcg
Expand Up @@ -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;
Expand Down
20 changes: 5 additions & 15 deletions Squared/RenderLib/PSM/generated/shaders/WorldSpaceBitmap.vcg
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 5 additions & 12 deletions Squared/RenderLib/PSM/generated/shaders/WorldSpaceGeometry.vcg
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions Squared/RenderLib/PSM/shaders/Bitmap.fcgh
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions Squared/RenderLib/PSM/shaders/Bitmap.vcgh
Expand Up @@ -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;
Expand Down

0 comments on commit 8b9ec20

Please sign in to comment.