Can I change the color of Shadow map

Started by
3 comments, last by Augi 16 years, 3 months ago
"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); }
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
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?
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);
}

akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
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 :)
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.

This topic is closed to new replies.

Advertisement