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,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = Format.R32_Float,
Height = 256,
Width = 256,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default
});
var shadowView = new RenderTargetView(device, shadowBuffer, new RenderTargetViewDescription()
{
Format = Format.R32_Float,
Dimension = RenderTargetViewDimension.Texture2D,
MipSlice = 0,
});
shadowSView = new ShaderResourceView(device, shadowBuffer, new ShaderResourceViewDescription()
{
Format = Format.R32_Float,
Dimension = ShaderResourceViewDimension.Texture2D,
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);
}
private static void UpdateSun()
{
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);
}