Sign in to follow this  
akira32

Can I change the color of Shadow map

Recommended Posts

"Programming Vertex and Pixel Shaders" Chapter 24 - Shadow Mapping\Shadow Map Aliased The color of shadow map of the sample is blue. Can I change the color of Shadow map to be red or green? float4 PSCreateShadowMap(float Depth : TEXCOORD0) : COLOR { return Depth; } I tried to modify the color as red(1,0,0,1), but it does not work (become white). Why? float4 PSCreateShadowMap(float Depth : TEXCOORD0) : COLOR { return float4(1,0,0,1); }

Share this post


Link to post
Share on other sites
Where can you see that the shadow map is blue? If you save shadow map to dds file and then you open it in DirectX Texture Tool then shadow map can appear as blue colored.
Shadow map format is specified as D3DFMT_R32F in this sample so this texture has only red color channel. So it does not matter what values do you output from pixel shader in other channels.
Shadow map is not used as color texture so the color of shadow map does not matter. There is important that you have to save depth to red channel and read red channel value when applying shadow map.
Why do you need to change color of shadow map?

Share this post


Link to post
Share on other sites
Quote:
Original post by Augi
Why do you need to change color of shadow map?


That is my curious think. Because I always don't see the red shadow map, even I change the PS return color to be red. My problem is how to just generate a red shadow map(texture) in Shader.

float4 PSCreateShadowMap(float Depth : TEXCOORD0) : COLOR
{
return float4(1,0,0,1);//<== SM should to be red, but I still don't see the red SM
}

//There are some code about the texture as below:

//Create Texture for shadow map

// setup shadow map objects
V_RETURN(pd3dDevice->CreateTexture(
SHADOW_MAP_SIZE,
SHADOW_MAP_SIZE,
1,
D3DUSAGE_RENDERTARGET,
SHADOW_MAP_FORMAT,
D3DPOOL_DEFAULT,
&m_pShadowMap,
NULL
));

V_RETURN(m_pShadowMap->GetSurfaceLevel(0, &m_pShadowMapSurf));

V_RETURN(pd3dDevice->CreateDepthStencilSurface(
SHADOW_MAP_SIZE,
SHADOW_MAP_SIZE,
D3DFMT_D24S8,
D3DMULTISAMPLE_NONE,
0,
TRUE,
&m_pShadowMapZ,
NULL
));

// save old render target and set new render target with depth/stencil buffer
pd3dDevice->GetRenderTarget(0, &pOldBackBuffer);
pd3dDevice->GetDepthStencilSurface(&pOldZBuffer);
pd3dDevice->SetRenderTarget(0, m_pShadowMapSurf);
pd3dDevice->SetDepthStencilSurface(m_pShadowMapZ);

HRESULT DrawShadowMapPreview()
{
DXUTGetD3DDevice()->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1);
DXUTGetD3DDevice()->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
DXUTGetD3DDevice()->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE);

float scale = 128;

typedef struct
{
FLOAT p[4];
FLOAT tu, tv;
} TVERTEX;

TVERTEX Vertex[4] =
{
// x y z rhw tu tv
{ 0, 0,0, 1, 0, 0,},
{scale, 0,0, 1, 1, 0,},
{scale,scale,0, 1, 1, 1,},
{ 0,scale,0, 1, 0, 1,},
};

DXUTGetD3DDevice()->SetTexture(0, m_pShadowMap);
DXUTGetD3DDevice()->SetVertexShader(NULL);
DXUTGetD3DDevice()->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
DXUTGetD3DDevice()->SetPixelShader(0);
DXUTGetD3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, Vertex, sizeof(TVERTEX));

return (S_OK);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by akira32
... Because I always don't see the red shadow map...

Where do you want to see the red shadow map? Do you store shadow map to file or do you display shadow map using your pixel shader? I would like to help you but I need more information :)

Share this post


Link to post
Share on other sites
Quote:
Original post by akira32
My problem is how to just generate a red shadow map(texture) in Shader.
OK. But you are using probably texture that has only red channel. So this texture does not hold complete color information (it require 3 color channels). So in shadow map there is only one one value (in red channel) and so color representation of this ONE value depends on this value interpretation.

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