Skip to content

Commit

Permalink
Modified decal shader to extract some helper functions to DepthHeader…
Browse files Browse the repository at this point in the history
….fxh

Signed-off-by: Martin Evans <martindevans@gmail.com>
  • Loading branch information
martindevans committed Feb 26, 2015
1 parent 03b71f9 commit 1eea8cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
12 changes: 3 additions & 9 deletions Myre/Myre.Graphics.Content/Decal.fx
Expand Up @@ -82,19 +82,13 @@ float3 CalculatePixelWorldPosition(in float4 positionCS, in float4 positionVS, i
);
float4 sampledDepth = tex2D(depthSampler, texCoord);

//Clip this pixel if it fails the Z test
//Z clip this pixel
if (zTest)
{
float depthDelta = sampledDepth - depth;
clip(depthDelta);
}
ZTest(sampledDepth, depth);

//Calculate view position of this pixel
float3 frustumRay = positionVS.xyz * (FarClip / -positionVS.z);
float3 viewPosition = frustumRay * sampledDepth.x;

//Calculate world position of this pixel
return mul(float4(viewPosition, 1), InvView).xyz;
return ReconstructWorldPosition(frustumRay, sampledDepth.x, InvView);
}

float3 ClipPixelNormal(float3 worldPosition, out float3 tangent, out float3 binormal)
Expand Down
11 changes: 11 additions & 0 deletions Myre/Myre.Graphics.Content/DepthHeader.fxh
@@ -1,3 +1,14 @@
float CalculateDepth(float4 viewPosition, float farClip) {
return -viewPosition.z / farClip;
}

void ZTest(float zBufferDepth, float pixelDepth) {
clip(zBufferDepth - pixelDepth);
}

float3 ReconstructWorldPosition(float3 viewRay, float depth, float4x4 InverseView) {
float3 viewPosition = viewRay * depth;

//Calculate world position of this pixel
return mul(float4(viewPosition, 1), InverseView).xyz;
}
Binary file modified Myre/Myre.Graphics/Resources/Decal.xnb
Binary file not shown.
6 changes: 3 additions & 3 deletions Myre/Myre.Graphics/x86Resources.resx
Expand Up @@ -193,10 +193,10 @@
<data name="FXAA" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\FXAA.xnb;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Decal" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Decal.xnb;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="DecalBufferMix" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\DecalBufferMix.xnb;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Decal" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Decal.xnb;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

0 comments on commit 1eea8cf

Please sign in to comment.