• Advertisement
Sign in to follow this  

problems with a simple post shader

This topic is 2771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


First off, the project uses dx10, feb 2010 sdk.
Im trying learn how handle shading, i have got several standard shaders to work with out any complaints. Now i would like to start on the post shaders, i found a very simple shader to try.
It is nvidia's sepia shader, it is nothing fancy, cut and dry. I can not seem to figure out how to grab the current RenderTargetView, and retrieve a SRV for input for the scene texture input.

i have tried many things, closest is what i have posted. CopyResource complains that it cant copy multi sampled so, i removed multi sampling still no go. All get is complaints or i crash the graphics card. fairly consently, starting get a little upset with it at this point.




the code


this is the entry point for the rendering

void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) {
HRESULT hr;

float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_D3DSettingsDlg.IsActive() ) {
g_D3DSettingsDlg.OnRender( fElapsedTime );
return;
}


CboDataStruct *cboData = NULL;
cboData = (CboDataStruct *)g_SampleUI.GetComboBox( IDC_TECHNIQUE_STD )->GetSelectedData();

if ( cboData && cboData->pshader )
cboData->pshader->OnD3D10FrameRender( pd3dDevice, fTime, fElapsedTime, pUserContext );

cboData = (CboDataStruct *)g_SampleUI.GetComboBox( IDC_TECHNIQUE_POST )->GetSelectedData();
if ( cboData && cboData->pshader )
cboData->pshader->OnD3D10FrameRender( pd3dDevice, fTime, fElapsedTime, pUserContext );

DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
g_HUD.OnRender( fElapsedTime );
g_SampleUI.OnRender( fElapsedTime );
RenderText();
DXUT_EndPerfEvent();
}



my shader code

struct QUAD_VERTEX {
D3DXVECTOR3 Pos;
D3DXVECTOR2 UV;
};
const D3D10_INPUT_ELEMENT_DESC layoutquad[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};

class PostSepiaShader {
public: /* only showing the var members */
ID3D10Texture2D* pRenderTarget;
ID3D10RenderTargetView* pRTRV;

ID3D10Texture2D* pDSTarget;
ID3D10DepthStencilView* pDSRV;


ID3D10InputLayout *pQuadLayout;
ID3D10Buffer *pQuadVB;
};

HRESULT PostSepiaShader::OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) {
dwShaderFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3D10_SHADER_DEBUG;
#endif

HRESULT hr = ShaderClass::OnD3D10CreateDevice( pd3dDevice, pBackBufferSurfaceDesc, pUserContext);

if ( state == sseErrored )
return S_FALSE;

pRenderTech = pEffect10->GetTechniqueByName( "Main10" );

pvClearColor = pEffect10->GetVariableByName( "gClearColor" )->AsVector();
pvLightColor = pEffect10->GetVariableByName( "gLightColor" )->AsVector();
pvDarkColor = pEffect10->GetVariableByName( "gDarkColor" )->AsVector();

pScalarClearDepth = pEffect10->GetVariableByName( "gClearDepth" )->AsScalar();
pScalarDesat = pEffect10->GetVariableByName( "gDesat" )->AsScalar();
pScalarToned = pEffect10->GetVariableByName( "gToned" )->AsScalar();

ptexScene = pEffect10->GetVariableByName( "gSceneTexture" )->AsShaderResource();
pSamplerStateScene = pEffect10->GetVariableByName( "gSceneSampler" )->AsSampler();

D3D10_PASS_DESC PassDesc;
pRenderTech->GetPassByIndex( 0 )->GetDesc( &PassDesc );
hr = pd3dDevice->CreateInputLayout( layoutquad, sizeof( layoutquad ) / sizeof( layoutquad[0] ), PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &pQuadLayout );
V_RETURN( hr );

// Create a screen quad for all render to texture operations
QUAD_VERTEX verts[4] = {
{ D3DXVECTOR3( -1, -1, 0.5f), D3DXVECTOR2(0, 0) },
{ D3DXVECTOR3( -1, 1, 0.5f), D3DXVECTOR2(0, 1) },
{ D3DXVECTOR3( 1, -1, 0.5f), D3DXVECTOR2(1, 0) },
{ D3DXVECTOR3( 1, 1, 0.5f), D3DXVECTOR2(1, 1) },
};

D3D10_BUFFER_DESC vbdesc = {
4 * sizeof( QUAD_VERTEX ),
D3D10_USAGE_DEFAULT,
D3D10_BIND_VERTEX_BUFFER,
0,
0
};

D3D10_SUBRESOURCE_DATA InitData;
InitData.pSysMem = verts;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
V_RETURN( pd3dDevice->CreateBuffer( &vbdesc, &InitData, &pQuadVB ) );
return S_OK;
}
HRESULT PostSepiaShader::OnD3D10ResizedSwapChain( ID3D10Device* pd3dDevice, IDXGISwapChain *pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) {
HRESULT hr = S_OK; //c:\C\Samples\C++\Direct3D10\Motionblur10\MotionBlur10.cpp
// Track the backbuffer height/width for fullscreen effects
g_fRTWidth = (float)pBackBufferSurfaceDesc->Width;
g_fRTHeight = (float)pBackBufferSurfaceDesc->Height;

UINT uiWidth = g_fRTWidth;
UINT uiHeight = g_fRTHeight;
UINT uiSampleCount = 8;
UINT uiSampleQuality = 0;

ID3D10RenderTargetView* pOrigRT = NULL;
ID3D10DepthStencilView* pOrigDS = NULL;
pd3dDevice->OMGetRenderTargets( 1, &pOrigRT, &pOrigDS );

D3D10_RENDER_TARGET_VIEW_DESC DescRTVInUse;
pOrigRT->GetDesc( &DescRTVInUse );
SAFE_RELEASE( pOrigRT );
SAFE_RELEASE( pOrigDS );


SAFE_RELEASE( pRenderTarget );
SAFE_RELEASE( pRTRV );
SAFE_RELEASE( pDSTarget );
SAFE_RELEASE( pDSRV );



D3D10_TEXTURE2D_DESC dstex;
dstex.Width = uiWidth;
dstex.Height = uiHeight;
dstex.MipLevels = 1;
dstex.Format = DescRTVInUse.Format;
dstex.SampleDesc.Count = uiSampleCount;
dstex.SampleDesc.Quality = uiSampleQuality;
dstex.Usage = D3D10_USAGE_DEFAULT;
dstex.BindFlags = D3D10_BIND_RENDER_TARGET;
dstex.CPUAccessFlags = 0;
dstex.MiscFlags = 0;
dstex.ArraySize = 1;
V_RETURN( pd3dDevice->CreateTexture2D( &dstex, NULL, &pRenderTarget ) );

// Create the render target view
D3D10_RENDER_TARGET_VIEW_DESC DescRT;
DescRT.Format = dstex.Format;
DescRT.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
V_RETURN( pd3dDevice->CreateRenderTargetView( pRenderTarget, &DescRT, &pRTRV ) );

//
// Create depth stencil texture.
//
dstex.Width = uiWidth;
dstex.Height = uiHeight;
dstex.MipLevels = 1;
dstex.Format =DXGI_FORMAT_D24_UNORM_S8_UINT;// DXGI_FORMAT_D32_FLOAT;
dstex.SampleDesc.Count = uiSampleCount;
dstex.SampleDesc.Quality = uiSampleQuality;
dstex.Usage = D3D10_USAGE_DEFAULT;
dstex.BindFlags = D3D10_BIND_DEPTH_STENCIL;
dstex.CPUAccessFlags = 0;
dstex.MiscFlags = 0;
V_RETURN( pd3dDevice->CreateTexture2D( &dstex, NULL, &pDSTarget ) );

// Create the depth stencil view
D3D10_DEPTH_STENCIL_VIEW_DESC DescDS;
DescDS.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;//DXGI_FORMAT_D32_FLOAT;
DescDS.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMS;
V_RETURN( pd3dDevice->CreateDepthStencilView( pDSTarget, &DescDS, &pDSRV ) );

return S_OK;
}
void PostSepiaShader::OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) {
HRESULT hr = S_OK;
ID3D10RenderTargetView* pOldRTV = NULL;
ID3D10DepthStencilView* pOldDSV = NULL;
D3D10_RENDER_TARGET_VIEW_DESC DescRTVO;
float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.5f };
pd3dDevice->OMGetRenderTargets( 1, &pOldRTV, &pOldDSV );
pOldRTV->GetDesc( &DescRTVO );
pd3dDevice->ClearRenderTargetView( pRTRV, ClearColor );
pd3dDevice->ClearDepthStencilView( pDSRV, D3D10_CLEAR_DEPTH, 1.0, 0 );
ID3D10ShaderResourceView *srv = NULL;
ID3D10Resource* pRT = NULL;
ID3D10Resource *pOldRTV_Res = NULL;

pd3dDevice->OMSetRenderTargets( 1, &pRTRV, this->pDSRV );

pOldRTV->GetResource( &pRT );
pd3dDevice->ResolveSubresource( pRT, D3D10CalcSubresource( 0, 0, 1 ), pRenderTarget, D3D10CalcSubresource( 0, 0, 1 ), DescRTVO.Format );

ID3D10Resource* pRT_Local = NULL;
/*
//pRenderTarget->GetDesc(
pd3dDevice->CopyResource( pRenderTarget, pRT );
D3D10_SHADER_RESOURCE_VIEW_DESC DescResView;
DescResView.Format = DescRTVO.Format;
DescResView.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DMS;
DescResView.Texture2D.MipLevels = 1;
DescResView.Texture2D.MostDetailedMip = 0;
hr = pd3dDevice->CreateShaderResourceView( pRenderTarget, &DescResView, &srv );
SAFE_RELEASE(pRT);
/**/

this->ptexScene->SetResource( srv );

DrawFullScreenQuad10( pd3dDevice, pRenderTech, g_fRTWidth, g_fRTHeight);
this->ptexScene->SetResource( NULL );

// Reset the old RT
pd3dDevice->OMSetRenderTargets( 1, &pOldRTV, pOldDSV );
SAFE_RELEASE( pOldRTV );
SAFE_RELEASE( pOldDSV );

// Reset to NULL to avoid any hazard tracking that D3D might do if a buffer is bound to both input and output
ID3D10ShaderResourceView* pViews[4] = {0,0,0,0};
pd3dDevice->PSSetShaderResources( 0, 4, pViews );
}





Thanks for taking a look, any thoughts?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement