Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Sep 2012
Offline Last Active Sep 18 2012 10:47 AM

Posts I've Made

In Topic: Point Light Issue With Deferred Rendering

14 September 2012 - 08:14 AM

Right I feel like a complete idiot now but I've found the problem.

I was certain the pixel shader was getting garbage data for gInvViewProjection but equally sure that the matrix in the application code was fine.

I thought I'd double checked my shader handles as well but I think this is a good example of why coding when you're tired is a bad idea. Turns out I was passing in mhInvViewProjection to my shader which is the handle for a different shader to the one I'm using for the point light. What I should have been passing in was mhPLightInvViewProjection. I knew I was doing something stupid just couldn't figure out what!

Anyway I now have all sorts of new problems but the lighting value is now correct :)

Thanks again for the help!

In Topic: Point Light Issue With Deferred Rendering

13 September 2012 - 09:05 AM

For me all I can think of is that it must have something to do with this line

position = mul(position, gInvViewProjection);

Before that the values seem normal and after that everything seems to be zeroed out. But I'm sure I'm setting that parameter properly in the application code. And the handles are set up ok as well for the effect. I can't think of anywhere else which could be causing the problem but at the same time can't see how it could be wrong either.

In Topic: Point Light Issue With Deferred Rendering

13 September 2012 - 08:38 AM

I suppose I should post my C++ code as well as it's definitely possible I've made a mistake here.

[source lang="cpp"]void DeferredRenderer::drawPointLight(D3DXVECTOR3& lightPos, D3DXVECTOR3& lightCol, float lightRadius, float lightIntensity){ HR(mPLightFX->SetTexture(mhColourMap, mColourRT)); HR(mPLightFX->SetTexture(mhNormalMap, mNormalRT)); HR(mPLightFX->SetTexture(mhDepthMap, mDepthRT)); D3DXMATRIX sphereWorld, S, T; D3DXMatrixScaling(&S, lightRadius, lightRadius, lightRadius); D3DXMatrixTranslation(&T, lightPos.x, lightPos.y, lightPos.z); sphereWorld = S*T; D3DXMATRIX view, proj; view = gCamera->view(); proj = gCamera->proj(); HR(mPLightFX->SetMatrix(mhPLightWorld, &sphereWorld)); HR(mPLightFX->SetMatrix(mhPLightView, &view)); HR(mPLightFX->SetMatrix(mhPLightProjection, &proj)); HR(mPLightFX->SetValue(mhPLightLightPosition, &lightPos, sizeof(D3DXVECTOR3))); HR(mPLightFX->SetValue(mhPLightLightColour, &lightCol, sizeof(D3DXVECTOR3))); HR(mPLightFX->SetFloat(mhPLightLightRadius, lightRadius)); HR(mPLightFX->SetFloat(mhPLightLightIntensity, lightIntensity)); HR(mPLightFX->SetValue(mhEyePosition, &gCamera->pos(), sizeof(D3DXVECTOR3))); D3DXMATRIX inverseVP = gCamera->viewProj(); D3DXMatrixInverse(&inverseVP, 0, &inverseVP); HR(mPLightFX->SetMatrix(mhInvViewProjection, &inverseVP)); HR(mPLightFX->SetValue(mhHalfPixel, &mHalfPixel, sizeof(D3DXVECTOR2))); float camToCentre = sqrt(pow(gCamera->pos().x - lightPos.x, 2) + pow(gCamera->pos().y - lightPos.y, 2) + pow(gCamera->pos().z - lightPos.z, 2)); if (camToCentre < lightRadius) { HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)); } else { HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW)); } HR(gd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false)); UINT numPasses = 0; HR(mPLightFX->Begin(&numPasses, 0)); HR(mPLightFX->BeginPass(0)); HR(mPLightFX->CommitChanges()); drawObject(mSphere, sphereWorld); HR(mPLightFX->EndPass()); HR(mPLightFX->End()); HR(gd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW));}[/source]

drawObject() simply calls DrawSubset(0) on the sphere mesh at the moment.

In Topic: Point Light Issue With Deferred Rendering

13 September 2012 - 08:31 AM

Also outputting my position information after it has been transformed results in a black screen which must mean 0s for the x, y and z values which surely can't be right.

In Topic: Point Light Issue With Deferred Rendering

13 September 2012 - 08:27 AM

I'm sure the values for texCoord are ok as are the various values I extract from my textures like the depth value because when I output that information to the screen it matches up with my depth buffer, normal buffer and so on. I reckon I must be doing something stupid when transforming my position to world space, because I can't think what else it could be.