Phlex
12-15-2008, 07:29 AM
Right, I've come into a spot of bother that I can't seem to solve. I have a function as shown below:
HRESULT RenderScene()
{
UINT uiPassCount, uiPass;
HRESULT hr;
// Set up Teapot matricies
D3DXMatrixIdentity(&m_matTeapot);
D3DXMatrixRotationYawPitchRoll(&m_matTeapot,
D3DXToRadian(g_fSpinX),
D3DXToRadian(g_fSpinY),
0.0f);
GetRealTimeUserInput();
UpdateViewMatrix();
// Render the teapot mesh
g_pd3dDevice->SetTransform(D3DTS_WORLD, &m_matTeapot);
for(unsigned long n = 0; n < g_dwTeapotNumMtrls; ++n)
{
g_pd3dDevice->SetMaterial(&g_pTeapotMtrls[n]);
g_pd3dDevice->SetTexture(0, g_pTeapotTextures[n]);
g_pTeapotMesh->DrawSubset(n);
}
// Draw the floor by rendering a 25 x 25 grouping of textured quads.
g_pd3dDevice->SetTexture(0, g_pFloorTex);
g_pd3dDevice->SetMaterial(&g_pFloorMtrl);
g_pd3dDevice->SetStreamSource(0, g_pFloorVB, 0, sizeof(FloorVertex));
g_pd3dDevice->SetFVF(FloorVertex::FVF_Flags);
D3DXMATRIX matFloor;
float x = 0.0f;
float z = 0.0f;
for(int i = 0; i < 25; ++i)
{
for(int j = 0; j < 25; ++j)
{
D3DXMatrixTranslation( &matFloor, x - 25.0f, -3.0f, z - 25.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matFloor );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);
x += 2.0f;
}
x = 0.0f;
z += 2.0f;
}
// Sample textures with anisotropic filtering 8x
for(DWORD i = 0; i < 8; i++)
{
g_pd3dDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
g_pd3dDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
g_pd3dDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_ANISOTROPIC);
}
return S_OK;
}
This function is called from another function (Render) as there are several render stages and post process effects to deal with. Any way, I want to replace the D3DLIGH9 struct that I was using with HLSL programmed lighting, so I've started with a simple ambient light rendering algorithm which is contained in the following hlsl code:
float4x4 matWorldViewProj;
struct VS_OUTPUT
{
float4 Pos: POSITION;
};
VS_OUTPUT TransformScene( float4 Pos: POSITION )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position
return Out;
}
float4 AmbientLight() : COLOR
{
return float4(0.5, 0.075, 0.075, 1.0);
}
/************************************************** ********************************
Techniques
************************************************** ********************************/
/************************************************** ********************************
RenderScene
************************************************** ********************************/
technique RenderScene
{
pass P0
{
VertexShader = compile vs_2_0 TransformScene();
PixelShader = compile ps_2_0 AmbientLight();
}
}
I set up my effect like this
g_pEffect->SetTechnique("RenderScene");
g_pEffect->SetMatrix("matWorldViewProj", &view);
hr = g_pEffect->Begin(&uiPassCount, 0);
if(FAILED(hr))
return hr;
for(uiPass = 0; uiPass < uiPassCount; uiPass++)
{
g_pEffect->BeginPass(uiPass);
// what goes here though?!
g_pEffect->EndPass();
}
g_pEffect->End();
I don't know where to put stuff so that it will render the goemetry with the ambient light specified in the shader, it all compiles fine, but after searching and trying for around 3 hours, I've given up trying on my own. All and any help would be much appreciated.
HRESULT RenderScene()
{
UINT uiPassCount, uiPass;
HRESULT hr;
// Set up Teapot matricies
D3DXMatrixIdentity(&m_matTeapot);
D3DXMatrixRotationYawPitchRoll(&m_matTeapot,
D3DXToRadian(g_fSpinX),
D3DXToRadian(g_fSpinY),
0.0f);
GetRealTimeUserInput();
UpdateViewMatrix();
// Render the teapot mesh
g_pd3dDevice->SetTransform(D3DTS_WORLD, &m_matTeapot);
for(unsigned long n = 0; n < g_dwTeapotNumMtrls; ++n)
{
g_pd3dDevice->SetMaterial(&g_pTeapotMtrls[n]);
g_pd3dDevice->SetTexture(0, g_pTeapotTextures[n]);
g_pTeapotMesh->DrawSubset(n);
}
// Draw the floor by rendering a 25 x 25 grouping of textured quads.
g_pd3dDevice->SetTexture(0, g_pFloorTex);
g_pd3dDevice->SetMaterial(&g_pFloorMtrl);
g_pd3dDevice->SetStreamSource(0, g_pFloorVB, 0, sizeof(FloorVertex));
g_pd3dDevice->SetFVF(FloorVertex::FVF_Flags);
D3DXMATRIX matFloor;
float x = 0.0f;
float z = 0.0f;
for(int i = 0; i < 25; ++i)
{
for(int j = 0; j < 25; ++j)
{
D3DXMatrixTranslation( &matFloor, x - 25.0f, -3.0f, z - 25.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matFloor );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);
x += 2.0f;
}
x = 0.0f;
z += 2.0f;
}
// Sample textures with anisotropic filtering 8x
for(DWORD i = 0; i < 8; i++)
{
g_pd3dDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
g_pd3dDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
g_pd3dDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_ANISOTROPIC);
}
return S_OK;
}
This function is called from another function (Render) as there are several render stages and post process effects to deal with. Any way, I want to replace the D3DLIGH9 struct that I was using with HLSL programmed lighting, so I've started with a simple ambient light rendering algorithm which is contained in the following hlsl code:
float4x4 matWorldViewProj;
struct VS_OUTPUT
{
float4 Pos: POSITION;
};
VS_OUTPUT TransformScene( float4 Pos: POSITION )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position
return Out;
}
float4 AmbientLight() : COLOR
{
return float4(0.5, 0.075, 0.075, 1.0);
}
/************************************************** ********************************
Techniques
************************************************** ********************************/
/************************************************** ********************************
RenderScene
************************************************** ********************************/
technique RenderScene
{
pass P0
{
VertexShader = compile vs_2_0 TransformScene();
PixelShader = compile ps_2_0 AmbientLight();
}
}
I set up my effect like this
g_pEffect->SetTechnique("RenderScene");
g_pEffect->SetMatrix("matWorldViewProj", &view);
hr = g_pEffect->Begin(&uiPassCount, 0);
if(FAILED(hr))
return hr;
for(uiPass = 0; uiPass < uiPassCount; uiPass++)
{
g_pEffect->BeginPass(uiPass);
// what goes here though?!
g_pEffect->EndPass();
}
g_pEffect->End();
I don't know where to put stuff so that it will render the goemetry with the ambient light specified in the shader, it all compiles fine, but after searching and trying for around 3 hours, I've given up trying on my own. All and any help would be much appreciated.