Right now im simply trying to clear a texture color using a pixel shader using shader model 2.0. i can get the render to texture to work using clear i can clear it to whatever color i want, but my pixel shader isnt doing anything.
what its doing is rendering both passes with the same world / view / proj matrices, and the pixel shader is returning 1.0 green for the color, but all i get is the quad with my clear color. here is my code, i would greatly appreciate any help or links to a good sample. thanks
surface / texture creation
m_pDevice->CreateTexture(m_nWindowWidth, m_nWindowHeight, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_A16B16G16R16F,
D3DPOOL_DEFAULT,
&m_pTexRender,
NULL);
m_pTexRender->GetSurfaceLevel(0, &m_pTexSurface);
Rendering
m_pDevice->SetVertexDeclaration(m_pCubeDecl);
m_pDevice->SetStreamSource(0, m_pCubeVB, 0, sizeof(tCubeVert));
//snag the old color buffer
IDirect3DSurface9 *oldColorBuffer = 0;
m_pDevice->GetRenderTarget(0, &oldColorBuffer);
unsigned int nPasses = 0;
m_pEffect->SetTechnique("Pong");
m_pEffect->Begin(&nPasses, 0);
//render to texture pass
m_pEffect->SetMatrix("World", &matWorld);
m_pEffect->SetMatrix("View", &matView);
m_pEffect->SetMatrix("Projection", &matProj);
//set texture surface as render target
m_pDevice->SetRenderTarget(0, m_pTexSurface);
m_pDevice->BeginScene();
m_pDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,255),1.0f,0);
m_pEffect->BeginPass(0);
m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
m_pEffect->EndPass();
m_pDevice->EndScene();
m_pEffect->SetMatrix("World", &matWorld);
m_pEffect->SetMatrix("View", &matView);
m_pEffect->SetMatrix("Projection", &matProj);
m_pDevice->SetTransform(D3DTS_VIEW, &matView);
m_pDevice->SetTransform(D3DTS_WORLD, &matWorld);
m_pDevice->SetTransform(D3DTS_PROJECTION, &matProj );
m_pDevice->SetRenderTarget(0, oldColorBuffer);
m_pDevice->BeginScene();
m_pDevice->Clear ( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, m_dwClearColor, 1.0f, 0);
m_pEffect->SetTexture("baseMap", m_pTexRender);
m_pEffect->BeginPass(1);
m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
m_pEffect->EndPass();
m_pEffect->End();
m_pDevice->EndScene();
//Flip Back Buffer
m_pDevice->Present( NULL, NULL, NULL, NULL );
}
hlsl shader
//calculate this outside later...
matrix World : WORLD;
matrix Projection : PROJECTION;
matrix View : VIEW;
matrix WorldView : WORLDVIEW;
matrix WorldViewProject : WORLDVIEWPROJECT;
texture baseMap;
sampler BaseMap = sampler_state
{
Texture = (baseMap);
magfilter = linear;
minfilter = linear;
mipfilter = linear;
AddressU = wrap;
AddressV = wrap;
};
struct VS_INPUT
{
float4 pos : POSITION;
float2 texCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 pos : POSITION;
float2 texCoord : TEXCOORD0;
};
VS_OUTPUT VSRenderToTexture( VS_INPUT vs_in)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
//move this to outside the shader later...
WorldView = mul(World, View);
WorldViewProject = mul(WorldView, Projection);
Out.pos = mul(vs_in.pos, WorldViewProject);
return Out;
}
float4 PSRenderToTexture( VS_OUTPUT ps_in) : COLOR
{
return float4(0.0f, 1.0f, 0.0f, 1.0f);
}
VS_OUTPUT VSCube( VS_INPUT vs_in)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
WorldView = mul(World, View);
WorldViewProject = mul(WorldView, Projection);
Out.pos = mul(vs_in.pos, WorldViewProject);
Out.texCoord = vs_in.texCoord;
return Out;
}
float4 PSCube( VS_OUTPUT ps_in) : COLOR
{
return tex2D(BaseMap, ps_in.texCoord);
}
technique Pong
{
pass RenderToTex
{
VertexShader = compile vs_2_0 VSRenderToTexture();
PixelShader = compile ps_2_0 PSRenderToTexture();
}
pass RenderCube
{
VertexShader = compile vs_2_0 VSCube();
PixelShader = compile ps_2_0 PSCube();
}
}
[Edited by - kajjait on May 21, 2007 2:10:27 PM]