• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Matthew Meeks  Members

Posted 07 January 2013 - 03:09 PM

Back again with a new problem, I'm having issues rendering a shadow map and then using it in another shader.

I create a 256x256 texture here with R32_Float as the format:

            Texture2D shadowBuffer = new Texture2D(device, new Texture2DDescription()
{
ArraySize = 1,
CpuAccessFlags = CpuAccessFlags.None,
Format = Format.R32_Float,
Height = 256,
Width = 256,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default
});
{
Format = Format.R32_Float,
Dimension = RenderTargetViewDimension.Texture2D,
MipSlice = 0,
});
{
Format = Format.R32_Float,
MostDetailedMip = 0,
MipLevels = 1,
});

I then render depth values to this texture and use it in another shader.  My problem is that when the values are sampled from the texture, they are clamped to 0-1.

Any help is appreciated.

EDIT: It has occured to me that the problem may lie in light matrices.  I create a orthographic projection and view matrix to act as a view from the sun:

        private static void SetUpSun()
{
SunProj = Matrix.OrthoLH(512, 512, 256, 1024);
}

{
Vector3 SunPos = new Vector3((float)Math.Sin(wt / 1f) * -512, (float)Math.Cos(wt / 1f) * -512, 0) + Camera.Position;
SunView = Matrix.LookAtLH(SunPos, Camera.Position, Vector3.UnitY);
}

Edited by Matthew Meeks, 07 January 2013 - 04:32 PM.

### #2kauna  Members

Posted 08 January 2013 - 03:53 AM

Typically the depth values stored in the shadow map are in range 0..1.

I don't understand from your post what is the actual problem.

Best regards!

### #3Matthew Meeks  Members

Posted 08 January 2013 - 03:45 PM

Yeah sorry wrote that with a migraine and tried to do it as fast as possible, it didn't work.  I've changed some things around and got closer to what I wanted, getting values in-between 0 and 1, except now the farther objects are 0 and the closer are 1.  My understanding is that farther objects return depths closer to 1.

In the vs:

float4 worldPosition = mul(Output.position, World);
float4 viewPosition = mul(worldPosition, View);
Output.position = mul(viewPosition, Projection);

In the ps:

return input.position.z / input.position.w;

Really simple yet I still can't figure out why.

And just in case the problem lies in the matrices:

View:

View = Matrix.LookAtLH(Position, cameraFinalTarget, up);

Projection:

Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)Width / (float)Height, 0.01f, 800f);

Thanks for the help and apologies for the vagueness of the original post.

Edited by Matthew Meeks, 08 January 2013 - 03:50 PM.

### #4kauna  Members

Posted 08 January 2013 - 04:32 PM

Yeah the z-values should be in between 0..1 where 0 is closer and 1 is further.

Why are you dividing your z-value by w? Isn't the division by w done automatically?

If you are doing basic shadow mapping, you may even disable your pixel shader if you are outputting to a depth-stencil buffer.

Best regards!

### #5Matthew Meeks  Members

Posted 08 January 2013 - 05:05 PM

I have tried both with and without dividing by w with the same result.  I had placed the division of w to ensure that w was always one as it should have been.  I am not outputting to a depth-stencil buffer but rather a Texture2D render target.  Not sure if this is the preferred method but i choose this because I eventually want to do more with the shadow map (different levels of light from the same source for semitransparent objects).

EDIT: I will try binding a depth buffer and attempt that way.

Thanks for the help!

Edited by Matthew Meeks, 08 January 2013 - 05:13 PM.

### #6Matthew Meeks  Members

Posted 08 January 2013 - 07:11 PM

Nevermind passed the wrong description.

Edited by Matthew Meeks, 08 January 2013 - 08:23 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.