Working with the first pass scene render here, I'm doing exactly as the HDRLighting app has, the problem is when I should be getting this:

I'm getting this:

This is the code from the HDR Lighting app:
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
// If the settings dialog is being shown, then
// render it instead of rendering the app's scene
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
HRESULT hr;
PDIRECT3DSURFACE9 pSurfLDR; // Low dynamic range surface for final output
PDIRECT3DSURFACE9 pSurfDS; // Low dynamic range depth stencil surface
PDIRECT3DSURFACE9 pSurfHDR; // High dynamic range surface to store
// intermediate floating point color values
// Store the old render target
V( g_pd3dDevice->GetRenderTarget( 0, &pSurfLDR ) );
V( g_pd3dDevice->GetDepthStencilSurface( &pSurfDS ) );
// Setup HDR render target
V( g_pTexScene->GetSurfaceLevel( 0, &pSurfHDR ) );
if( g_bUseMultiSampleFloat16 )
{
V( g_pd3dDevice->SetRenderTarget( 0, g_pFloatMSRT ) );
V( g_pd3dDevice->SetDepthStencilSurface( g_pFloatMSDS ) );
}
else
{
V( g_pd3dDevice->SetRenderTarget( 0, pSurfHDR ) );
}
// Clear the viewport
V( g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA( 0, 0, 0, 0 ), 1.0f, 0L ) );
// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
// Render the HDR Scene
{
CDXUTPerfEventGenerator g( DXUT_PERFEVENTCOLOR, L"Scene" );
RenderScene();
if(g_bScreenHasBeenTaken != TRUE)
{
if(FAILED(ScreenGrabSurface(pSurfHDR)))
MessageBox(NULL, L"ScreenGrabSurface failed", NULL, MB_OK | MB_ICONERROR);
else g_bScreenHasBeenTaken = TRUE;
}
}
}
V( pd3dDevice->EndScene() );
}
// Release surfaces
SAFE_RELEASE( pSurfHDR );
SAFE_RELEASE( pSurfLDR );
SAFE_RELEASE( pSurfDS );
}
// and the code for render scene
//-----------------------------------------------------------------------------
// Name: RenderScene()
// Desc: Render the world objects and lights
//-----------------------------------------------------------------------------
HRESULT RenderScene()
{
HRESULT hr = S_OK;
UINT uiPassCount, uiPass;
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mTrans;
D3DXMATRIXA16 mRotate;
D3DXMATRIXA16 mObjectToView;
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
D3DXMATRIX mView = *g_Camera.GetViewMatrix();
g_pEffect->SetTechnique( "RenderScene" );
g_pEffect->SetMatrix( "g_mObjectToView", &mView );
hr = g_pEffect->Begin( &uiPassCount, 0 );
if( FAILED( hr ) )
return hr;
for( uiPass = 0; uiPass < uiPassCount; uiPass++ )
{
g_pEffect->BeginPass( uiPass );
// Turn off emissive lighting
D3DXVECTOR4 vNull( 0.0f, 0.0f, 0.0f, 0.0f );
g_pEffect->SetVector( "g_vEmissive", &vNull );
// Enable texture
g_pEffect->SetBool( "g_bEnableTexture", true );
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
// Render walls and columns
g_pEffect->SetFloat( "g_fPhongExponent", 5.0f );
g_pEffect->SetFloat( "g_fPhongCoefficient", 1.0f );
g_pEffect->SetFloat( "g_fDiffuseCoefficient", 0.5f );
g_pd3dDevice->SetTexture( 0, g_pTexWall );
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset( 0 );
// Render floor
g_pEffect->SetFloat( "g_fPhongExponent", 50.0f );
g_pEffect->SetFloat( "g_fPhongCoefficient", 3.0f );
g_pEffect->SetFloat( "g_fDiffuseCoefficient", 1.0f );
g_pd3dDevice->SetTexture( 0, g_pTexFloor );
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset( 1 );
// Render ceiling
g_pEffect->SetFloat( "g_fPhongExponent", 5.0f );
g_pEffect->SetFloat( "g_fPhongCoefficient", 0.3f );
g_pEffect->SetFloat( "g_fDiffuseCoefficient", 0.3f );
g_pd3dDevice->SetTexture( 0, g_pTexCeiling );
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset( 2 );
// Render paintings
g_pEffect->SetFloat( "g_fPhongExponent", 5.0f );
g_pEffect->SetFloat( "g_fPhongCoefficient", 0.3f );
g_pEffect->SetFloat( "g_fDiffuseCoefficient", 1.0f );
g_pd3dDevice->SetTexture( 0, g_pTexPainting );
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset( 3 );
// Draw the light spheres.
g_pEffect->SetFloat( "g_fPhongExponent", 5.0f );
g_pEffect->SetFloat( "g_fPhongCoefficient", 1.0f );
g_pEffect->SetFloat( "g_fDiffuseCoefficient", 1.0f );
g_pEffect->SetBool( "g_bEnableTexture", false );
for( int iLight = 0; iLight < NUM_LIGHTS; iLight++ )
{
// Just position the point light -- no need to orient it
D3DXMATRIXA16 mScale;
D3DXMatrixScaling( &mScale, 0.05f, 0.05f, 0.05f );
mView = *g_Camera.GetViewMatrix();
D3DXMatrixTranslation( &mWorld, g_avLightPosition[iLight].x, g_avLightPosition[iLight].y,
g_avLightPosition[iLight].z );
mWorld = mScale * mWorld;
mObjectToView = mWorld * mView;
g_pEffect->SetMatrix( "g_mObjectToView", &mObjectToView );
// A light which illuminates objects at 80 lum/sr should be drawn
// at 3183 lumens/meter^2/steradian, which equates to a multiplier
// of 39.78 per lumen.
D3DXVECTOR4 vEmissive = EMISSIVE_COEFFICIENT * g_avLightIntensity[iLight];
g_pEffect->SetVector( "g_vEmissive", &vEmissive );
g_pEffect->CommitChanges();
g_pmeshSphere->DrawSubset( 0 );
}
g_pEffect->EndPass();
}
g_pEffect->End();
return S_OK;
}
And here's what I've done to get my black screen:
//--------------------------------------------------------------------------------------
// Name: Render
// Desc: Render frame
//--------------------------------------------------------------------------------------
HRESULT Render()
{
HRESULT hr;
PDIRECT3DSURFACE9 pSurfLDR; // Low dynamic range surface for final output
PDIRECT3DSURFACE9 pSurfDS; // Low dynamic range depth stencil surface
PDIRECT3DSURFACE9 pSurfHDR; // High dynamic range surface to store
// intermediate floating point color values
// Store the old render target
hr = g_pd3dDevice->GetRenderTarget(0, &pSurfLDR);
if(FAILED(hr)) return hr;
hr = g_pd3dDevice->GetDepthStencilSurface(&pSurfDS);
if(FAILED(hr)) return hr;
// Setup HDR render target
g_pTexScene->GetSurfaceLevel(0, &pSurfHDR);
if(g_bUseMultiSampleFloat16)
{
hr = g_pd3dDevice->SetRenderTarget(0, g_pFloatMSRT);
if(FAILED(hr)) return hr;
hr = g_pd3dDevice->SetDepthStencilSurface(g_pFloatMSDS);
if(FAILED(hr)) return hr;
}
else
{
hr = g_pd3dDevice->SetRenderTarget(0, pSurfHDR);
if(FAILED(hr)) return hr;
}
// Clear the viewport
hr = g_pd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0, 0, 0, 0), 1.0f, 0L);
if(FAILED(hr)) return hr;
// Render the scene
if(SUCCEEDED(g_pd3dDevice->BeginScene()))
{
// Render the HDR Scene
{
if(FAILED(RenderScene()))
return hr;
if(g_bScreenHasBeenTaken != TRUE)
{
if(FAILED(ScreenGrabSurface(pSurfHDR)))
MessageBox(NULL, "ScreenGrabSurface failed", NULL, MB_OK | MB_ICONERROR);
else g_bScreenHasBeenTaken = TRUE;
}
}
// If using floating point multi sampling, stretchrect to the rendertarget
if( g_bUseMultiSampleFloat16 )
{
hr = g_pd3dDevice->StretchRect(g_pFloatMSRT, NULL, pSurfHDR, NULL, D3DTEXF_NONE);
if(FAILED(hr)) return hr;
hr = g_pd3dDevice->SetRenderTarget(0, pSurfHDR);
if(FAILED(hr)) return hr;
hr = g_pd3dDevice->SetDepthStencilSurface(pSurfDS);
if(FAILED(hr)) return hr;
}
g_pd3dDevice->EndScene();
}
// Release surfaces
SAFE_RELEASE(pSurfHDR);
SAFE_RELEASE(pSurfLDR);
SAFE_RELEASE(pSurfDS);
return hr;
}
//-----------------------------------------------------------------------------
// Name: RenderScene()
// Desc: Render the world objects and lights
//-----------------------------------------------------------------------------
HRESULT RenderScene()
{
HRESULT hr = S_OK;
UINT uiPassCount, uiPass;
D3DXMATRIXA16 mObjectToView;
g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
g_pEffect->SetTechnique("RenderScene");
g_pEffect->SetMatrix("g_mObjectToView", &g_mView);
hr = g_pEffect->Begin(&uiPassCount, 0);
if(FAILED(hr))
return hr;
for(uiPass = 0; uiPass < uiPassCount; uiPass++)
{
g_pEffect->BeginPass(uiPass);
// Turn off emissive lighting
D3DXVECTOR4 vNull(0.0f, 0.0f, 0.0f, 0.0f);
g_pEffect->SetVector("g_vEmissive", &vNull);
// Enable texture
g_pEffect->SetBool("g_bEnableTexture", true);
g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
// Render walls and columns
g_pEffect->SetFloat("g_fPhongExponent", 5.0f);
g_pEffect->SetFloat("g_fPhongCoefficient", 1.0f);
g_pEffect->SetFloat("g_fDiffuseCoefficient", 0.5f);
g_pd3dDevice->SetTexture(0, g_pTexWall);
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset(0);
// Render floor
g_pEffect->SetFloat("g_fPhongExponent", 50.0f);
g_pEffect->SetFloat("g_fPhongCoefficient", 3.0f);
g_pEffect->SetFloat("g_fDiffuseCoefficient", 1.0f);
g_pd3dDevice->SetTexture(0, g_pTexFloor);
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset(1);
// Render ceiling
g_pEffect->SetFloat("g_fPhongExponent", 5.0f);
g_pEffect->SetFloat("g_fPhongCoefficient", 0.3f);
g_pEffect->SetFloat("g_fDiffuseCoefficient", 0.3f);
g_pd3dDevice->SetTexture(0, g_pTexCeiling);
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset(2);
// Render paintings
g_pEffect->SetFloat("g_fPhongExponent", 5.0f);
g_pEffect->SetFloat("g_fPhongCoefficient", 0.3f);
g_pEffect->SetFloat("g_fDiffuseCoefficient", 1.0f);
g_pd3dDevice->SetTexture(0, g_pTexPainting);
g_pEffect->CommitChanges();
g_pWorldMesh->DrawSubset(3);
// Draw the light spheres.
g_pEffect->SetFloat("g_fPhongExponent", 5.0f);
g_pEffect->SetFloat("g_fPhongCoefficient", 1.0f);
g_pEffect->SetFloat("g_fDiffuseCoefficient", 1.0f);
g_pEffect->SetBool("g_bEnableTexture", false);
for(int iLight = 0; iLight < NUM_LIGHTS; iLight++)
{
// Just position the point light -- no need to orient it
D3DXMATRIXA16 mScale;
D3DXMatrixScaling( &mScale, 0.05f, 0.05f, 0.05f );
D3DXMatrixTranslation(&g_mWorld,
g_avLightPosition[iLight].x,
g_avLightPosition[iLight].y,
g_avLightPosition[iLight].z );
g_mWorld = mScale * g_mWorld;
mObjectToView = g_mWorld * g_mView;
g_pEffect->SetMatrix("g_mObjectToView", &mObjectToView);
// A light which illuminates objects at 80 lum/sr should be drawn
// at 3183 lumens/meter^2/steradian, which equates to a multiplier
// of 39.78 per lumen.
D3DXVECTOR4 vEmissive = EMISSIVE_COEFFICIENT * g_avLightIntensity[iLight];
g_pEffect->SetVector("g_vEmissive", &vEmissive);
g_pEffect->CommitChanges();
g_pmeshSphere->DrawSubset(0);
}
g_pEffect->EndPass();
}
g_pEffect->End();
return S_OK;
}
The odd thing is that I capture exactly the same surface which is declared as such in both source snippets:
g_pTexScene->GetSurfaceLevel( 0, &pSurfHDR )
Both of the above images are this exact same surface, although mine does not work, if anyone can help, I would be greatly appreciative.












