void Scene::Draw(float fDeltaTime) { if (GetAsyncKeyState('R') < 0 && GetForegroundWindow() == hWnd) { Reset(); } device->SetRenderTarget(0, rtMain); device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( rand(), rand(), rand() ), 1.0f, 0 ); device->BeginScene(); IDirect3DTexture9 * src = NULL; IDirect3DSurface9 * dest = NULL; IDirect3DTexture9 * res = NULL; if (parity == 0) { src = state0; dest = rtState1; res = state1; parity = 1; } else { src = state1; dest = rtState0; res = state0; parity = 0; } //step DrawFullScreenQuad(dest, stepVS, stepPS, src); //show to screen DrawFullScreenQuad(rtMain, copyVS, copyPS, res); device->EndScene(); device->Present( NULL, NULL, NULL, NULL ); //Simplest file watcher DWORD waitStatus = WaitForSingleObject(shaderDirWatcherHandle, 0); if (waitStatus == WAIT_OBJECT_0) { LoadShaders(); FindNextChangeNotification(shaderDirWatcherHandle); } }
//-------------------------------------------------------------------------------------- // Name: Downsample4x4Texture() // Desc: Scale down pSrcTexture by 1/4 x 1/4 and place the result in pDstTexture //-------------------------------------------------------------------------------------- VOID PostProcess::Downsample4x4Texture( LPDIRECT3DTEXTURE9 pSrcTexture, LPDIRECT3DTEXTURE9 pDstTexture ) { // Make sure that the required shaders and objects exist assert( m_pDownScale4x4PS ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pDstTexture ) ); // Get the sample offsets used within the pixel shader XMVECTOR avSampleOffsets[MAX_SAMPLES]; GetSampleOffsets_DownScale4x4( SrcDesc.Width, SrcDesc.Height, avSampleOffsets ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShader( m_pDownScale4x4PS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // Draw a fullscreen quad DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
void AutoExposure(void) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); D3DXHANDLE shader = g_pExposureEffect->GetTechniqueByName("AutoExposure"); g_pExposureEffect->SetTechnique(shader); Vector4 vMiddleGray(0.5f); Vector4 vMultiplierClamp(0.2f, 3.0f, 0.0f, 0.0f); D3DXHANDLE middlegray_var = g_pExposureEffect->GetParameterByName(NULL, "vMiddleGray"); D3DXHANDLE clamp_var = g_pExposureEffect->GetParameterByName(NULL, "vMultiplierClamp"); D3DXHANDLE image0_var = g_pExposureEffect->GetParameterByName(NULL, "Image"); D3DXHANDLE image1_var = g_pExposureEffect->GetParameterByName(NULL, "Image2"); g_pExposureEffect->SetVector(middlegray_var, (D3DXVECTOR4*)&vMiddleGray); g_pExposureEffect->SetVector(clamp_var, (D3DXVECTOR4*)&vMultiplierClamp); g_pExposureEffect->SetTexture(image0_var, g_pFrameBuffer[FULLSIZE]); g_pExposureEffect->SetTexture(image1_var, g_pFrameBuffer[LUMINANCE_TEMP]); g_pExposureEffect->Begin(NULL, 0); g_pExposureEffect->BeginPass(0); DrawFullScreenQuad(&g_ImageInfo); g_pExposureEffect->EndPass(); g_pExposureEffect->End(); }
void DrawImage(ID3D10ShaderResourceView *pTexture, float x=-1, float y=-1, float w=2, float h=2) { Vector4 vtable[4]; vtable[0].Set(x, y, 0.0f, 1.0f); vtable[1].Set(x+w, y, 0.0f, 1.0f); vtable[2].Set(x, y+h, 0.0f, 1.0f); vtable[3].Set(x+w, y+h, 0.0f, 1.0f); Vector4 ttable[4] = { Vector4(0.0f, 1.0f, 0.0f, 1.0f), Vector4(1.0f, 1.0f, 0.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f), Vector4(1.0f, 0.0f, 0.0f, 1.0f) }; ID3D10EffectTechnique *pShader = g_pPostFX->GetTechniqueByName("DrawIcon"); ID3D10EffectShaderResourceVariable *pInputTexture = g_pPostFX->GetVariableByName("Image")->AsShaderResource(); ID3D10EffectVectorVariable *vertex_table = g_pPostFX->GetVariableByName("vertex_table")->AsVector(); ID3D10EffectVectorVariable *texcoord_table = g_pPostFX->GetVariableByName("texcoord_table")->AsVector(); pInputTexture->SetResource(pTexture); vertex_table->SetFloatVectorArray( (float*)vtable, 0, 4); texcoord_table->SetFloatVectorArray( (float*)ttable, 0, 4); pShader->GetPassByIndex(0)->Apply(0); DrawFullScreenQuad(); }
void ConverToLogLuminance(LPDIRECT3DTEXTURE9 pSource, sImageInfo *pInfo) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->SetRenderTarget(0, g_pFrameSurface[DOWNSAMPLED_256x256]); device->SetDepthStencilSurface(NULL); D3DXHANDLE shader = g_pExposureEffect->GetTechniqueByName("LogLuminance"); g_pExposureEffect->SetTechnique(shader); D3DXHANDLE tablevar = g_pExposureEffect->GetParameterByName(NULL, "vLuminanceTable"); D3DXHANDLE imagevar = g_pExposureEffect->GetParameterByName(NULL, "Image"); Vector4 vTable(0.21f, 0.71f, 0.072f); g_pExposureEffect->SetVector(tablevar, (D3DXVECTOR4*)&vTable); g_pExposureEffect->SetTexture(imagevar, pSource); g_pExposureEffect->Begin(NULL, 0); g_pExposureEffect->BeginPass(0); DrawFullScreenQuad(pInfo); g_pExposureEffect->EndPass(); g_pExposureEffect->End(); }
void Scene::Reset() { device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 255, 0, 0 ), 1.0f, 0 ); device->BeginScene(); DrawFullScreenQuad(rtState0, copyVS, copyPS, initialState); device->EndScene(); }
//-------------------------------------------------------------------------------------- // Name: SampleLuminance() // Desc: Measure the average log luminance in the scene. //-------------------------------------------------------------------------------------- VOID PostProcess::SampleLuminance( LPDIRECT3DTEXTURE9 pSrcTexture, BOOL bInitial, LPDIRECT3DTEXTURE9 pDstTexture ) { // Make sure that the required shaders and objects exist assert( m_pSampleLumInitialPS ); assert( m_pSampleLumFinalPS ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pDstTexture ) ); // Sample initial luminance if( bInitial ) { // Initialize the sample offsets for the initial luminance pass. XMVECTOR avSampleOffsets[MAX_SAMPLES]; GetSampleOffsets_DownScale3x3( SrcDesc.Width, SrcDesc.Height, avSampleOffsets ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShader( m_pSampleLumInitialPS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); } else // ( bIntial == FALSE ) { // Perform the final pass of the average luminance calculation. This pass // performs an exp() operation to return a single texel cooresponding to the // average luminance of the scene in m_pToneMapTexture. XMVECTOR avSampleOffsets[MAX_SAMPLES]; GetSampleOffsets_DownScale4x4( SrcDesc.Width, SrcDesc.Height, avSampleOffsets ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShader( m_pSampleLumFinalPS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); } // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
/** Copies the given texture to the given RTV */ XRESULT D3D11PfxRenderer::CopyTextureToRTV(ID3D11ShaderResourceView* texture, ID3D11RenderTargetView* rtv, INT2 targetResolution, bool useCustomPS, INT2 offset) { D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; D3D11_VIEWPORT oldVP; if(targetResolution.x != 0 && targetResolution.y != 0) { UINT n=1; engine->GetContext()->RSGetViewports(&n, &oldVP); D3D11_VIEWPORT vp; vp.TopLeftX = (float)offset.x; vp.TopLeftY = (float)offset.y; vp.MinDepth = 0.0f; vp.MaxDepth = 0.0f; vp.Width = (float)targetResolution.x; vp.Height = (float)targetResolution.y; engine->GetContext()->RSSetViewports(1, &vp); } // Save old rendertargets ID3D11RenderTargetView* oldRTV = NULL; ID3D11DepthStencilView* oldDSV = NULL; engine->GetContext()->OMGetRenderTargets(1, &oldRTV, &oldDSV); // Bind shaders if(!useCustomPS) { D3D11PShader* simplePS = engine->GetShaderManager()->GetPShader("PS_PFX_Simple"); simplePS->Apply(); } engine->GetShaderManager()->GetVShader("VS_PFX")->Apply(); ID3D11ShaderResourceView* srv = NULL; engine->GetContext()->PSSetShaderResources(0,1,&srv); engine->GetContext()->OMSetRenderTargets(1, &rtv, NULL); if(texture) engine->GetContext()->PSSetShaderResources(0,1, &texture); DrawFullScreenQuad(); engine->GetContext()->PSSetShaderResources(0,1,&srv); engine->GetContext()->OMSetRenderTargets(1, &oldRTV, oldDSV); if(oldRTV)oldRTV->Release(); if(oldDSV)oldDSV->Release(); if(targetResolution.x != 0 && targetResolution.y != 0) { engine->GetContext()->RSSetViewports(1, &oldVP); } return XR_SUCCESS; }
// Post-Process Drawing Pass.... TODO: idk what to do with it... maybe make passes count in value? void DrawPostProcessPass(CEffect *m_pEffect) { DWORD dwOldFVF; const DWORD dwFVF_POST = D3DFVF_XYZRHW | D3DFVF_TEX1; g_Device->GetFVF(&dwOldFVF); g_Device->SetFVF(dwFVF_POST); m_pEffect->Begin(); // This function begins pass(here we use only first pass for now). DrawFullScreenQuad(); // Call Full-Screen Quad Drawing Function to draw Full-Screen Quad! m_pEffect->End(); // This function ends current pass. Don't forget it! g_Device->SetFVF(dwOldFVF); }
//-------------------------------------------------------------------------------------- // Name: RenderStarLine() // Desc: Merge the ppSrcTextures and place the result in pDstTexture //-------------------------------------------------------------------------------------- VOID PostProcess::RenderStarLine( LPDIRECT3DTEXTURE9 pSrcTexture, DWORD dwNumSamples, FLOAT fAttenuation, FLOAT fAttnPowScale, XMVECTOR* colors, DWORD pass, FLOAT fStepU, FLOAT fStepV, LPDIRECT3DTEXTURE9 pDstTexture ) { // Make sure that the required shaders and objects exist assert( m_pStarPS ); assert( pSrcTexture && pDstTexture ); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pDstTexture ) ); XMVECTOR avSampleOffsets[MAX_SAMPLES]; XMVECTOR avSampleWeights[MAX_SAMPLES]; // Sampling configration for each stage for( DWORD i = 0; i < dwNumSamples; i++ ) { FLOAT lum = powf( fAttenuation, fAttnPowScale * i ); avSampleWeights[i] = colors[i] * lum * ( pass + 1.0f ) * 0.5f; // Offset of sampling coordinate avSampleOffsets[i].x = fStepU * i; avSampleOffsets[i].y = fStepV * i; if( fabs( avSampleOffsets[i].x ) >= 0.9f || fabs( avSampleOffsets[i].y ) >= 0.9f ) { avSampleOffsets[i].x = 0.0f; avSampleOffsets[i].y = 0.0f; avSampleWeights[i] *= 0.0f; } } g_pd3dDevice->SetPixelShader( m_pStarPS ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleWeights, ( FLOAT* )avSampleWeights, MAX_SAMPLES ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
void DirectionalLightPass::HandleDrawScene(_In_ const std::shared_ptr<IGraphicsScene>& scene, _In_ const XMFLOAT4X4& view, _In_ const XMFLOAT4X4& projection) { XMVECTOR det; XMStoreFloat4x4(&_vsPerFrame.InvProjection, XMMatrixInverse(&det, XMLoadFloat4x4(&projection))); UpdateVSConstantBuffer(0, &_vsPerFrame, sizeof(_vsPerFrame)); XMMATRIX v = XMLoadFloat4x4(&view); auto theScene = static_cast<GraphicsScene*>(scene.get()); theScene->GetAllDirectionalLights(_lights); // Draw lights in batches of 'LightsPerDraw' (8) uint32_t numLights = 0; for (auto light : _lights) { auto color = light->GetColor(); auto direction = light->GetPosition(); _psPerDraw.Color[numLights] = XMFLOAT4(color.x, color.y, color.z, 1.0f); _psPerDraw.Direction[numLights] = XMFLOAT4(direction.x, direction.y, direction.z, 0.0f); XMStoreFloat4(&_psPerDraw.Direction[numLights], XMVector3TransformNormal(XMLoadFloat4(&_psPerDraw.Direction[numLights]), v)); if (++numLights == LightsPerDraw) { // Draw the batch _psPerDraw.NumLights = numLights; UpdatePSConstantBuffer(0, &_psPerDraw, sizeof(_psPerDraw)); DrawFullScreenQuad(); numLights = 0; } } if (numLights > 0) { // Draw remaining lights that didn't fit into a full batch _psPerDraw.NumLights = numLights; UpdatePSConstantBuffer(0, &_psPerDraw, sizeof(_psPerDraw)); DrawFullScreenQuad(); } _lights.clear(); }
//-------------------------------------------------------------------------------------- // Name: CopyTexture() // Desc: Copy the src texture to the dst texture. The scale can (and should) be changed. //-------------------------------------------------------------------------------------- VOID PostProcess::CopyTexture( LPDIRECT3DTEXTURE9 pSrcTexture, LPDIRECT3DTEXTURE9 pDstTexture, LPDIRECT3DPIXELSHADER9 pPixelShader, DWORD dwEdramOffset ) { if( NULL == pPixelShader ) pPixelShader = m_pCopyTexturePS; // Make sure that the required shaders and objects exist assert( pPixelShader ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target D3DSURFACE_PARAMETERS surfaceParams = { 0 }; surfaceParams.Base = dwEdramOffset; PushRenderTarget( 0L, CreateRenderTarget( pDstTexture, &surfaceParams ) ); // Scale and copy the src texture g_pd3dDevice->SetPixelShader( pPixelShader ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); XGTEXTURE_DESC DstDesc; XGGetTextureDesc( pDstTexture, 0, &DstDesc ); DWORD ColorExpBias = 0; if( DstDesc.Format == D3DFMT_G16R16_SIGNED_INTEGER ) ColorExpBias = ( DWORD ) D3DRESOLVE_EXPONENTBIAS( 10 ); else if( DstDesc.Format == D3DFMT_A16B16G16R16_SIGNED_INTEGER ) ColorExpBias = ( DWORD ) D3DRESOLVE_EXPONENTBIAS( 10 ); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0 | ColorExpBias, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
//-------------------------------------------------------------------------------------- // Name: BuildMipMaps() // Desc: Generate mip maps from the base texture //-------------------------------------------------------------------------------------- VOID PostProcess::BuildMipMaps( LPDIRECT3DTEXTURE9 pTexture ) { // Make sure that the required shaders and objects exist assert( m_pCopyTexturePS ); assert( pTexture ); DWORD dwNumMipLevels = pTexture->GetLevelCount(); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pTexture ) ); // Scale and copy the src texture g_pd3dDevice->SetPixelShader( m_pCopyTexturePS ); g_pd3dDevice->SetTexture( 0, pTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); D3DVIEWPORT9 vp; g_pd3dDevice->GetViewport( &vp ); for( DWORD i = 1; i < dwNumMipLevels; i++ ) { XGTEXTURE_DESC Desc; XGGetTextureDesc( pTexture, i, &Desc ); vp.Width = Desc.Width; vp.Height = Desc.Height; g_pd3dDevice->SetViewport( &vp ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINMIPLEVEL, i - 1 ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); DWORD ColorExpBias = 0; if( Desc.Format == D3DFMT_G16R16_SIGNED_INTEGER ) ColorExpBias = (DWORD) D3DRESOLVE_EXPONENTBIAS(10); else if( Desc.Format == D3DFMT_A16B16G16R16_SIGNED_INTEGER ) ColorExpBias = (DWORD) D3DRESOLVE_EXPONENTBIAS(10); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0 | ColorExpBias, NULL, pTexture, NULL, i, 0, NULL, 1.0f, 0L, NULL ); } // Cleanup and return g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINMIPLEVEL, 13 ); PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
static void ExpLuminance(void) { ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("ExpLuminance"); ID3D10EffectShaderResourceVariable *pImage0_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource(); g_pDevice->OMSetRenderTargets(1, &g_pRTView[LUMINANCE_TEMP], NULL); pImage0_var->SetResource(g_pSRView[LUMINANCE_CURRENT]); pShader->GetPassByIndex(0)->Apply(0); DrawFullScreenQuad(); SwapRenderTarget(LUMINANCE_CURRENT, LUMINANCE_TEMP); }
void DrawImage(LPDIRECT3DTEXTURE9 pSource1, sImageInfo *pInfo) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); g_pEffect->SetTechnique(g_pAddImageShader); D3DXHANDLE pTexture1Var = g_pEffect->GetParameterByName(NULL, "Image"); g_pEffect->SetTexture(pTexture1Var, pSource1); g_pEffect->Begin(NULL, 0); g_pEffect->BeginPass(0); DrawFullScreenQuad(pInfo); g_pEffect->EndPass(); g_pEffect->End(); }
static void ConvertToLogLuminance(void) { g_pDevice->OMSetRenderTargets(1, &g_pRTView[DOWNSAMPLED_256x256], NULL); SetViewport(DOWNSAMPLED_256x256); ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("LogLuminance"); ID3D10EffectShaderResourceVariable *pImage_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource(); ID3D10EffectVectorVariable *pLuminanceTable_var = g_pExposureFX->GetVariableByName("vLuminanceTable")->AsVector(); pImage_var->SetResource(g_pSRView[FULLSIZE]); pLuminanceTable_var->SetFloatVector( &vLuminanceTable[0] ); pShader->GetPassByIndex(0)->Apply(0); DrawFullScreenQuad(); }
//-------------------------------------------------------------------------------------- // Name: Downsample2x2Texture() // Desc: Scale down pSrcTexture by 1/2 x 1/2 and place the result in pDstTexture //-------------------------------------------------------------------------------------- VOID PostProcess::Downsample2x2Texture( LPDIRECT3DTEXTURE9 pSrcTexture, LPDIRECT3DTEXTURE9 pDstTexture, DWORD dwEdramOffset ) { // Make sure that the required shaders and objects exist assert( m_pDownScale2x2PS ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target D3DSURFACE_PARAMETERS surfaceParams = { 0 }; surfaceParams.Base = dwEdramOffset; PushRenderTarget( 0L, CreateRenderTarget( pDstTexture, &surfaceParams ) ); XMVECTOR avSampleOffsets[MAX_SAMPLES]; GetSampleOffsets_DownScale2x2( SrcDesc.Width, SrcDesc.Height, avSampleOffsets ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); // Create an exact 1/2 x 1/2 copy of the source texture g_pd3dDevice->SetPixelShader( m_pDownScale2x2PS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // TODO: This should use border addressing with a black border! //m_pStarSourceTexture->Format.ClampX = GPUCLAMP_CLAMP_TO_BORDER; //m_pStarSourceTexture->Format.ClampY = GPUCLAMP_CLAMP_TO_BORDER; //m_pStarSourceTexture->Format.BorderColor = GPUBORDERCOLOR_ABGR_BLACK; //g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER ); //g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
//-------------------------------------------------------------------------------------- // Name: BloomTexture() // Desc: Bloom the pSrcTexture and place the result in pDstTexture //-------------------------------------------------------------------------------------- VOID PostProcess::BloomTexture( LPDIRECT3DTEXTURE9 pSrcTexture, BOOL bBloomAcrossWidth, LPDIRECT3DTEXTURE9 pDstTexture, FLOAT fSize, FLOAT fBrightness ) { // Make sure that the required shaders and objects exist assert( m_pBloomPS ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pDstTexture ) ); XMVECTOR avSampleOffsets[MAX_SAMPLES]; XMVECTOR avSampleWeights[MAX_SAMPLES]; if( bBloomAcrossWidth ) GetSampleOffsets_Bloom( SrcDesc.Width, SrcDesc.Height, 0.0f * XM_PIDIV2, avSampleOffsets, avSampleWeights, fSize, fBrightness ); else GetSampleOffsets_Bloom( SrcDesc.Width, SrcDesc.Height, 1.0f * XM_PIDIV2, avSampleOffsets, avSampleWeights, fSize, fBrightness ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleWeights, ( FLOAT* )avSampleWeights, MAX_SAMPLES ); g_pd3dDevice->SetPixelShader( m_pBloomPS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
//-------------------------------------------------------------------------------------- // Name: BrightPassFilterTexture() // Desc: Run the bright-pass filter on m_pScaledSceneTexture and place the result // in m_pBrightPassTexture //-------------------------------------------------------------------------------------- VOID PostProcess::BrightPassFilterTexture( LPDIRECT3DTEXTURE9 pSrcTexture, LPDIRECT3DTEXTURE9 pAdaptedLuminanceTexture, FLOAT fMiddleGrayKeyValue, LPDIRECT3DTEXTURE9 pDstTexture ) { // Make sure that the required shaders and objects exist assert( m_pBrightPassFilterPS ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pDstTexture ) ); // Get the offsets to be used within the GaussBlur5x5 pixel shader XMVECTOR avSampleOffsets[MAX_SAMPLES]; XMVECTOR avSampleWeights[MAX_SAMPLES]; GetSampleOffsets_GaussBlur5x5( SrcDesc.Width, SrcDesc.Height, avSampleOffsets, avSampleWeights ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleWeights, ( FLOAT* )avSampleWeights, MAX_SAMPLES ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_fMiddleGray, &fMiddleGrayKeyValue, 1 ); g_pd3dDevice->SetPixelShader( m_pBrightPassFilterPS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetTexture( 1, pAdaptedLuminanceTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
void HDRLight::_calculateAdaptation() { UINT uiPass, uiPassCount; // Swap current & last luminance PDIRECT3DTEXTURE9 pTexSwap = g_pTexAdaptedLuminanceLast; g_pTexAdaptedLuminanceLast = g_pTexAdaptedLuminanceCur; g_pTexAdaptedLuminanceCur = pTexSwap; PDIRECT3DSURFACE9 pSurfAdaptedLum = NULL; g_pTexAdaptedLuminanceCur->GetSurfaceLevel( 0, &pSurfAdaptedLum); // This simulates the light adaptation that occurs when moving from a // dark area to a bright area, or vice versa. The g_pTexAdaptedLuminance // texture stores a single texel cooresponding to the user's adapted // level. g_HDREffect->SetTechnique( "CalculateAdaptedLum" ); g_HDREffect->SetFloat( "g_fElapsedTime", 0.5); g_pd3dDevice->SetRenderTarget( 0, pSurfAdaptedLum ); g_pd3dDevice->SetTexture( 0, g_pTexAdaptedLuminanceLast ); g_pd3dDevice->SetTexture( 1, g_apTexToneMap[0] ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(g_pd3dDevice, 0.0f, 0.0f, 1.0f, 1.0f ); g_HDREffect->EndPass(); } g_HDREffect->End(); SAFE_RELEASE( pSurfAdaptedLum ); }
//-------------------------------------------------------------------------------------- // Name: GaussBlur5x5Texture() // Desc: Perform a 5x5 gaussian blur on pSrcTexture and place the result in pDstTexture //-------------------------------------------------------------------------------------- VOID PostProcess::GaussBlur5x5Texture( LPDIRECT3DTEXTURE9 pSrcTexture, LPDIRECT3DTEXTURE9 pDstTexture, DWORD dwEdramOffset ) { // Make sure that the required shaders and objects exist assert( m_pGaussBlur5x5PS ); assert( pSrcTexture && pDstTexture ); XGTEXTURE_DESC SrcDesc; XGGetTextureDesc( pSrcTexture, 0, &SrcDesc ); // Create and set a render target D3DSURFACE_PARAMETERS surfaceParams = { 0 }; surfaceParams.Base = dwEdramOffset; PushRenderTarget( 0L, CreateRenderTarget( pDstTexture, &surfaceParams ) ); XMVECTOR avSampleOffsets[MAX_SAMPLES]; XMVECTOR avSampleWeights[MAX_SAMPLES]; GetSampleOffsets_GaussBlur5x5( SrcDesc.Width, SrcDesc.Height, avSampleOffsets, avSampleWeights ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES ); g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleWeights, ( FLOAT* )avSampleWeights, MAX_SAMPLES ); g_pd3dDevice->SetPixelShader( m_pGaussBlur5x5PS ); g_pd3dDevice->SetTexture( 0, pSrcTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
void HDRLight::Render() { _scene_to_sceneScaled(); _measureLuminance(); _calculateAdaptation(); _sceneScaled_To_BrightPass(); _brightSource_ToBloomSource(); _renderBloom(); UINT uiPassCount, uiPass; g_HDREffect->SetTechnique( "FinalScenePass" ); g_HDREffect->SetFloat( "g_fMiddleGray", 0.18); g_pd3dDevice->SetRenderTarget( 0, pSurfLDR ); g_pd3dDevice->SetTexture( 0, g_pTexScene ) ; g_pd3dDevice->SetTexture( 1, g_apTexBloom[0] ); g_pd3dDevice->SetTexture( 2, g_pTexAdaptedLuminanceCur ) ; g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ) ; g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ) ; g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ) ; g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ) ; g_pd3dDevice->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_POINT ) ; g_pd3dDevice->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_POINT); g_HDREffect->Begin( &uiPassCount, 0 ); { for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); DrawFullScreenQuad(g_pd3dDevice, 0.0f, 0.0f, 1.0f, 1.0f ); g_HDREffect->EndPass(); } } g_HDREffect->End(); }
static void AdaptiveLuminance(void) { ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("AdaptiveLuminance"); ID3D10EffectShaderResourceVariable *pImage0_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource(); ID3D10EffectShaderResourceVariable *pImage1_var = g_pExposureFX->GetVariableByName("Image1")->AsShaderResource(); ID3D10EffectVectorVariable *pAdaptiveSpeed_var = g_pExposureFX->GetVariableByName("vAdaptiveSpeed")->AsVector(); Vector4 vSpeed(0.1f); pImage0_var->SetResource(g_pSRView[LUMINANCE_PREVIOUS]); pImage1_var->SetResource(g_pSRView[LUMINANCE_CURRENT]); pAdaptiveSpeed_var->SetFloatVector( (float*)&vSpeed[0] ); g_pDevice->OMSetRenderTargets(1, &g_pRTView[LUMINANCE_TEMP], NULL); pShader->GetPassByIndex(0)->Apply(0); DrawFullScreenQuad(); SwapRenderTarget(LUMINANCE_TEMP, LUMINANCE_PREVIOUS); }
void ExpLuminance(LPDIRECT3DSURFACE9 pSurace, LPDIRECT3DTEXTURE9 pTexture, sImageInfo *pInfo) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->SetRenderTarget(0, pSurace); D3DXHANDLE shader = g_pExposureEffect->GetTechniqueByName("ExpLuminance"); D3DXHANDLE image_var = g_pExposureEffect->GetParameterByName(NULL, "Image"); g_pExposureEffect->SetTechnique(shader); g_pExposureEffect->SetTexture(image_var, pTexture); g_pExposureEffect->Begin(NULL, 0); g_pExposureEffect->BeginPass(0); DrawFullScreenQuad(pInfo); g_pExposureEffect->EndPass(); g_pExposureEffect->End(); }
void HDRLight::_scene_to_sceneScaled() { PDIRECT3DSURFACE9 pSurfScaledScene = NULL; g_pTexSceneScaled->GetSurfaceLevel( 0, &pSurfScaledScene ); g_HDREffect->SetTechnique("DownScale4x4"); RECT rectSrc; rectSrc.left = 0; rectSrc.top = 0; rectSrc.right = g_D3dpp.BackBufferWidth; rectSrc.bottom = g_D3dpp.BackBufferHeight; CoordRect coords; GetTextureCoords( g_pTexScene, &rectSrc, g_pTexSceneScaled, NULL, &coords ); D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES]; GetSampleOffsets_DownScale4x4(g_D3dpp.BackBufferWidth,g_D3dpp.BackBufferHeight,avSampleOffsets); g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) ); g_pd3dDevice->SetRenderTarget( 0, pSurfScaledScene ); g_pd3dDevice->SetTexture( 0, g_pTexScene ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); UINT uiPassCount, uiPass; g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV, coords.fRightU,coords.fBottomV); g_HDREffect->EndPass(); } g_HDREffect->End(); SAFE_RELEASE(pSurfScaledScene); }
void AdaptiveLuminance(void) { static int count = 0; LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); if ( count ) { device->SetRenderTarget(0, g_pFrameSurface[LUMINANCE_TEMP]); D3DXHANDLE shader = g_pExposureEffect->GetTechniqueByName("AdaptiveLuminance"); g_pExposureEffect->SetTechnique(shader); Vector4 vSpeed(0.03f); D3DXHANDLE speed_var = g_pExposureEffect->GetParameterByName(NULL, "vAdaptiveSpeed"); D3DXHANDLE image0_var = g_pExposureEffect->GetParameterByName(NULL, "Image"); D3DXHANDLE image1_var = g_pExposureEffect->GetParameterByName(NULL, "Image2"); g_pExposureEffect->SetVector(speed_var, (D3DXVECTOR4*)&vSpeed); g_pExposureEffect->SetTexture(image0_var, g_pFrameBuffer[LUMINANCE_PREVIOUS]); g_pExposureEffect->SetTexture(image1_var, g_pFrameBuffer[LUMINANCE_CURRENT]); g_pExposureEffect->Begin(NULL, 0); g_pExposureEffect->BeginPass(0); DrawFullScreenQuad(&g_Image1x1); g_pExposureEffect->EndPass(); g_pExposureEffect->End(); } else { device->StretchRect(g_pFrameSurface[LUMINANCE_CURRENT], NULL, g_pFrameSurface[LUMINANCE_TEMP], NULL, D3DTEXF_POINT); } // copy //device->StretchRect(g_pFrameSurface[LUMINANCE_TEMP], NULL, g_pFrameSurface[LUMINANCE_PREVIOUS], NULL, D3DTEXF_POINT); SwapRenderTarget(LUMINANCE_TEMP, LUMINANCE_PREVIOUS); count++; }
//-------------------------------------------------------------------------------------- // Name: AdaptLuminance() // Desc: Adapt the luminance over time and place the result in pDstTexture //-------------------------------------------------------------------------------------- VOID PostProcess::AdaptLuminance( LPDIRECT3DTEXTURE9 pAdaptedLuminanceTexture, LPDIRECT3DTEXTURE9 pToneMapTexture, FLOAT fElapsedTime, LPDIRECT3DTEXTURE9 pDstTexture ) { // Make sure that the required shaders and objects exist assert( m_pCalculateAdaptedLumPS ); assert( pAdaptedLuminanceTexture && pToneMapTexture && pDstTexture ); // Create and set a render target PushRenderTarget( 0L, CreateRenderTarget( pDstTexture ) ); // This simulates the light adaptation that occurs when moving from a dark area to // a bright area, or vice versa. The m_pTexAdaptedLuminance texture stores a single // texel cooresponding to the user's adapted level. g_pd3dDevice->SetPixelShaderConstantF( PSCONST_fElapsedTime, &fElapsedTime, 1 ); g_pd3dDevice->SetPixelShader( m_pCalculateAdaptedLumPS ); g_pd3dDevice->SetTexture( 0, pAdaptedLuminanceTexture ); g_pd3dDevice->SetTexture( 1, pToneMapTexture ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(); g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL, 0, 0, NULL, 1.0f, 0L, NULL ); // Cleanup and return PopRenderTarget( 0L )->Release(); g_pd3dDevice->SetPixelShader( NULL ); }
void ExpLuminance(void) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->SetRenderTarget(0, g_pFrameSurface[LUMINANCE_TEMP]); D3DXHANDLE shader = g_pExposureEffect->GetTechniqueByName("ExpLuminance"); D3DXHANDLE image_var = g_pExposureEffect->GetParameterByName(NULL, "Image"); g_pExposureEffect->SetTechnique(shader); g_pExposureEffect->SetTexture(image_var, g_pFrameBuffer[LUMINANCE_CURRENT]); g_pExposureEffect->Begin(NULL, 0); g_pExposureEffect->BeginPass(0); DrawFullScreenQuad(&g_Image1x1); g_pExposureEffect->EndPass(); g_pExposureEffect->End(); SwapRenderTarget(LUMINANCE_TEMP, LUMINANCE_CURRENT); }
//----------------------------------------------------------------------------- // Name: SceneScaled_To_BrightPass // Desc: ��ҹ��ۿ� �����Ҷ� ���� �κи� �����Ѵ� //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::SceneScaled_To_BrightPass() { // ����� ���� �����κ��� �������� ũ�� ���� D3DSURFACE_DESC desc; m_pTexBrightPass->GetLevelDesc( 0, &desc ); RECT rectDest = {0,0,desc.Width,desc.Height}; InflateRect( &rectDest, -1, -1 );// �o�͐�̑傫�������菬�������� m_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); m_pd3dDevice->SetScissorRect( &rectDest ); // ��üȭ�� ���� m_pd3dDevice->SetRenderTarget( 0, m_pSurfBrightPass ); m_pEffect->SetTechnique("BrightPassFilter"); m_pEffect->Begin(NULL, 0); m_pEffect->Pass(0); m_pd3dDevice->SetTexture( 0, m_pTexSceneScaled ); DrawFullScreenQuad( 0.0f, 0.0f, 1.0f, 1.0f ); m_pEffect->End(); m_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); return S_OK; }
//----------------------------------------------------------------------------- // Name: Scene_To_SceneScaled() // Desc: m_pTexScene�� 1/4�� �ؼ� m_pTexSceneScale�� �ִ´� //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::Scene_To_SceneScaled() { // �ʰ��� �κп� �߽ɺκ��� �����Ѵ� CoordRect coords; RECT rectSrc; rectSrc.left = (m_d3dsdBackBuffer.Width - m_dwCropWidth ) / 2; rectSrc.top = (m_d3dsdBackBuffer.Height - m_dwCropHeight) / 2; rectSrc.right = rectSrc.left + m_dwCropWidth; rectSrc.bottom = rectSrc.top + m_dwCropHeight; // ������Ÿ�ٿ� ���߿� �ؽ�ó��ǥ ��� GetTextureCoords( m_pTexScene, &rectSrc, m_pTexSceneScaled, NULL, &coords ); // �ֺ� 16�ؼ��� ���ø������� �ؼ� // 0.5�� �߽ɿ� ���߱����� ���� int index=0; D3DXVECTOR2 offsets[MAX_SAMPLES]; for( int y=0; y < 4; y++ ) { for( int x=0; x < 4; x++ ) { offsets[ index ].x = (x - 1.5f) / m_d3dsdBackBuffer.Width; offsets[ index ].y = (y - 1.5f) / m_d3dsdBackBuffer.Height; index++; } } m_pEffect->SetValue("g_avSampleOffsets", offsets, sizeof(offsets)); // 16�ؼ��� ���ø��ؼ� �� ��հ��� ��ҹ��ۿ� ����ϳ� m_pd3dDevice->SetRenderTarget( 0, m_pSurfSceneScaled ); m_pEffect->SetTechnique("DownScale4x4"); m_pEffect->Begin(NULL, 0); m_pEffect->Pass(0); m_pd3dDevice->SetTexture( 0, m_pTexScene ); DrawFullScreenQuad( coords.u0, coords.v0, coords.u1, coords.v1 ); m_pEffect->End(); return S_OK; }