Sign in to follow this  

Pixel Shader Iteration Issue

Recommended Posts

ChristOwnsMe    374
So I am creating a geometry map using a pixel shader. I iterate over the texture coordinates using the pixel shader and calculate noise, then output this final noise value. This is for a chunked lod planet system. The noise works fine with the first patch, however when you zoom in and it tries to generate a new heightmap, ALL texture coordinates x and y in the pixel shader are the same.

My main question is what would cause all the pixel shader texture coordinates to be the same for every pixel when it runs this a second time. The vertices and texture coordinates never change, so I don't understand why the pixel shader doesn't return the same values.

Here is the code.I am using c# and XNA.

[color=#526569][font=Verdana, Arial, Helvetica, sans-serif][size=3][left][background=rgb(244, 247, 245)]SHADER:[/background][/left][/size][/font][/color]

[color=#526569][font=Verdana, Arial, Helvetica, sans-serif][size=3][left]
float4 PS_INoise(float2 inTexCoords : TEXCOORD0) : COLOR0
float land0 = (float)0;

// Get the direction, from the origin (top-left) to the end vector (bottom-right)
float3 xDirection = xNE - xNW;
float3 zDirection = xSW - xNW;

// Scale the distance by the texture coordinate (which is between 0 and 1)
xDirection *= inTexCoords.x;
zDirection *= 1 - inTexCoords.y;

// Lerp outward from the originSY (top-left) in the direction of the end vector (bottom-right)
float3 lerpedWorldPos = xNW + xDirection + zDirection;
land0 = inoise(lerpedWorldPos);
land0 = inTexCoords.y;

return land0;


//pre-transformed quad
m_Vertices[0] = new VertexPositionTexture(new Vector3(-1, 1, 0f), new Vector2(0, 1));
m_Vertices[1] = new VertexPositionTexture(new Vector3(1, 1, 0f), new Vector2(1 , 1));
m_Vertices[2] = new VertexPositionTexture(new Vector3(-1, -1, 0f), new Vector2(0, 0));
m_Vertices[3] = new VertexPositionTexture(new Vector3(1, -1, 0f), new Vector2(1 , 0 ));

perlinCombined.Parameters["xNW"].SetValue(new Vector3(-1, 1, 0f));
perlinCombined.Parameters["xNE"].SetValue(new Vector3(1, 1, 0f));
perlinCombined.Parameters["xSW"].SetValue(new Vector3(-1, -1, 0f));
perlinCombined.Parameters["xSE"].SetValue(new Vector3(1, -1, 0f));

CRenderManager.Singleton.GetGD().BlendState = BlendState.Opaque;
foreach (EffectPass pass in perlinCombined.CurrentTechnique.Passes)
CRenderManager.Singleton.GetGD().DrawUserPrimitives(PrimitiveType.TriangleStrip, m_Vertices, 0,2);

CRenderManager.Singleton.GetGD().SetRenderTarget(null); Edited by ShadowMan777

Share this post

Link to post
Share on other sites
ChristOwnsMe    374
I have still been unable to fix this. Forgot to add also, anytime I zoom int o the planet and it starts creating children and calling the pixel shader more, the ENTIRE SCREEN is purple, like the clearing color switched somehow. It goes way when I disable setting a render target.
Any help would be appreciated. Thanks. Edited by ShadowMan777

Share this post

Link to post
Share on other sites
ChristOwnsMe    374
Somewhat solved. For some reason, by setting the RasterizationState(), it is making all future pixel shader calls not iterate.

RasterizerState rs = new RasterizerState();

rs.FillMode = FillMode.WireFrame;
rs.CullMode = CullMode.CullClockwiseFace;
GraphicsDevice.RasterizerState = rs;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this