Permalink
Browse files

Depth testing works now

  • Loading branch information...
1 parent 5b95f1e commit 28d4b904c59966fd1fe48a2e744c371d98d22918 @liquidmetal committed Apr 2, 2012
@@ -25,7 +25,7 @@
<Processor>EffectProcessor</Processor>
<Options>None</Options>
<Output>D:\Projects\ChipsChallenge\LevelEditorXna\LevelEditorXna\bin\x86\Debug\Content\shaders\DepthSprite.xnb</Output>
- <Time>2012-04-01T15:23:05.7320894-07:00</Time>
+ <Time>2012-04-01T22:32:07.8594738-07:00</Time>
</Item>
<Item>
<Source>shaders\ClearBuffers.fx</Source>
@@ -9,40 +9,39 @@ float4 PixelShaderFunction(float2 uv : TEXCOORD0, float4 col : COLOR0) : COLOR0
{
float4 ret;
- float2 newPosition;
- float newHeight;
-
float2 shifted;
+ float2 shiftedUnnormalized;
- float2 existingPosition;
- float existingHeight;
+ float3 bufferPos;
+ float3 texturePos;
- float separation;
- float pyth;
- float thresh;
-
- //newHeight = tex2D(currentHeightMap, uv);
- //newPosition = float2(uv.x, uv.y - newHeight);
+ shiftedUnnormalized = float2((position.x + uv.x*texSize.x), (position.y + uv.y*texSize.y));
+ shifted = float2(shiftedUnnormalized.x/bufferSize.x, shiftedUnnormalized.y/bufferSize.y);
-
- shifted = float2((uv.x*texSize.x + position.x)/bufferSize.x, (uv.y*texSize.y + position.y)/bufferSize.y);
- //existingHeight = tex2D(heightBuffer, shifted);
- //existingPosition = float2(uv.x, uv.y - existingHeight);
+ float4 currentColor = tex2D(currentHeightMap, uv);
+ float4 bufferColor = tex2D(heightBuffer, shifted);
- //separation = (existingPosition.y-position.y) - newPosition.y;
+ bufferPos = float3(shiftedUnnormalized.x, shiftedUnnormalized.y+bufferColor.r, bufferColor.r);
+ texturePos = float3(uv.x*texSize.x, uv.y*texSize.y+currentColor.r, currentColor.r);
- //pyth = (separation*separation) + (existingHeight-newHeight)*(existingHeight-newHeight);
- //thresh = (existingHeight-newHeight)*(existingHeight-newHeight) + (existingHeight-newHeight)*(existingHeight-newHeight);
+ float pyth;
+ float thresh;
- /*if(pyth>=thresh)
- {
- ret.rgba = tex2D(currentHeightMap, uv);
+ //thresh = 2*(texturePos.z-bufferPos.z)*(texturePos.z-bufferPos.z);
+ //pyth = (texturePos.z-bufferPos.z)*(texturePos.z-bufferPos.z) + ((texturePos.y+position.y)-bufferPos.y)*((texturePos.y+position.y)-bufferPos.y);
- return ret;
- }*/
+ if(bufferPos.y<=texturePos.y+position.y)
+ {
+ ret = currentColor;
+ ret.a = 0;
+ }
+ else
+ {
+ ret = bufferColor;
+ ret.a = 1;
+ }
+
- ret.rgb = tex2D(currentHeightMap, uv)*col;
- ret.a=tex2D(currentHeightMap, uv).a;
return ret;
}
View
@@ -96,6 +96,9 @@ public bool RenderWorld(World world)
RenderTarget2D finalResult = new RenderTarget2D(graphicsDevice, graphicsDevice.PresentationParameters.BackBufferWidth, graphicsDevice.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.PreserveContents);
RenderTarget2D temp = new RenderTarget2D(graphicsDevice, graphicsDevice.PresentationParameters.BackBufferWidth, graphicsDevice.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.DiscardContents);
+ graphicsDevice.SetRenderTarget(finalResult);
+ graphicsDevice.Clear(Color.Black);
+
List<Entity> lstEntities = world.GetEntities();
foreach (Entity ent in lstEntities)
{
@@ -114,11 +117,24 @@ public bool RenderWorld(World world)
// Pass 1: Generate a good height map
// No stencil as of now
+
+ // Draw the current sprite's heightmap
+ // It uses the heightmap generated till now
+ // to compute whether a particular point should
graphicsDevice.SetRenderTarget(temp);
+ graphicsDevice.Clear(Color.Transparent);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
+
+ depthSpriteShader.Parameters["position"].SetValue(pos);
+ depthSpriteShader.Parameters["bufferSize"].SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
+ depthSpriteShader.Parameters["texSize"].SetValue(new Vector2(texHeightmap.Width, texHeightmap.Height));
+ graphicsDevice.Textures[1] = finalResult;
+
+ depthSpriteShader.Techniques[0].Passes[0].Apply();
spriteBatch.Draw(texHeightmap, pos, t[i]);
spriteBatch.End();
+ // Comp it all together
graphicsDevice.SetRenderTarget(finalResult);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
spriteBatch.Draw(temp, Vector2.Zero, Color.White);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 28d4b90

Please sign in to comment.