DirectX9 SDK Samples(20) HDRDemo Sample(2)
来源:互联网 发布:阿里云服务器使用手册 编辑:程序博客网 时间:2024/05/20 16:37
接下来进入第二部分,Bloom,SDK里称为post-processing effect。代码所在文件为PostProcess.cpp。
LPDIRECT3DTEXTURE9 g_pBrightPassTex = NULL; // The results of performing a bright pass on the original HDR imageryLPDIRECT3DTEXTURE9 g_pDownSampledTex = NULL; // The scaled down version of the bright pass resultsLPDIRECT3DTEXTURE9 g_pBloomHorizontal = NULL; // The horizontally blurred version of the downsampled textureLPDIRECT3DTEXTURE9 g_pBloomVertical = NULL; // The vertically blurred version of the horizontal blurD3DFORMAT g_fmtHDR = D3DFMT_UNKNOWN; // What HDR (128 or 64) format is being usedLPDIRECT3DPIXELSHADER9 g_pBrightPassPS = NULL; // Represents the bright pass processingLPD3DXCONSTANTTABLE g_pBrightPassConstants = NULL;LPDIRECT3DPIXELSHADER9 g_pDownSamplePS = NULL; // Represents the downsampling processingLPD3DXCONSTANTTABLE g_pDownSampleConstants = NULL;LPDIRECT3DPIXELSHADER9 g_pHBloomPS = NULL; // Performs the first stage of the bloom renderingLPD3DXCONSTANTTABLE g_pHBloomConstants = NULL;LPDIRECT3DPIXELSHADER9 g_pVBloomPS = NULL; // Performs the second stage of the bloom renderingLPD3DXCONSTANTTABLE g_pVBloomConstants = NULL;从这些变量我们可以得知:一共需要4个纹理,对应4个像素着色器。
CreateResource就不说了,无非是创建纹理和载入着色器。
//--------------------------------------------------------------------------------------// PerformPostProcessing( )//// DESC:// This is the core function for this module - it takes the raw HDR image// generated by the 'HDRScene' component and puts it through 4 post// processing stages - to end up with a bloom effect on the over-exposed// (HDR) parts of the image.
LPDIRECT3DTEXTURE9 pHDRSource = NULL; HDRScene::GetOutputTexture( &pHDRSource ); LPDIRECT3DSURFACE9 pBrightPassSurf = NULL; PostProcess::g_pBrightPassTex->GetSurfaceLevel( 0, &pBrightPassSurf );
pDevice->SetRenderTarget( 0, pBrightPassSurf ); // Configure the output of this stage pDevice->SetTexture( 0, pHDRSource ); // Configure the input.. pDevice->SetPixelShader( PostProcess::g_pBrightPassPS ); PostProcess::g_pBrightPassConstants->SetFloat( pDevice, "fBrightPassThreshold", PostProcess::g_BrightThreshold ); // We need to compute the sampling offsets used for this pass. // A 2x2 sampling pattern is used, so we need to generate 4 offsets D3DXVECTOR4 offsets[4]; // Find the dimensions for the source data D3DSURFACE_DESC srcDesc; pHDRSource->GetLevelDesc( 0, &srcDesc ); // Because the source and destination are NOT the same sizes, we // need to provide offsets to correctly map between them. float sU = ( 1.0f / static_cast< float >( srcDesc.Width ) ); float sV = ( 1.0f / static_cast< float >( srcDesc.Height ) ); // The last two components (z,w) are unused. This makes for simpler code, but if // constant-storage is limited then it is possible to pack 4 offsets into 2 float4's offsets[0] = D3DXVECTOR4( -0.5f * sU, 0.5f * sV, 0.0f, 0.0f );//省略其他offset PostProcess::g_pBrightPassConstants->SetVectorArray( pDevice, "tcDownSampleOffsets", offsets, 4 ); RenderToTexture( pDevice );
流程都是一样的,计算所需要的变量,然后设置变量,渲染到RenderTarget。
接下来的DownSampling就不说了。然后就到了Blur,这个例子中先进行水平模糊,再进行垂直模糊。计算模糊值中用到了高斯分布函数。
那么下一节将进行最后效果合成代码的阅读。
- DirectX9 SDK Samples(20) HDRDemo Sample(2)
- DirectX9 SDK Samples(20) HDRDemo Sample(1)
- DirectX9 SDK Samples(20) HDRDemo Sample(3)
- DirectX9 SDK Samples(20) MeshFromObj Sample
- DirectX9 SDK Samples(8) BasicHLSL Sample(2)
- DirectX9 SDK Samples(14) EffectParam Sample(2)
- DirectX9 SDK Samples(16) ShadowMap Sample(2)
- DirectX9 SDK Samples(7) EmptyProject Sample
- DirectX9 SDK Samples(8) BasicHLSL Sample(1)
- DirectX9 SDK Samples(9) Text3D Sample
- DirectX9 SDK Samples(10) HLSLwithoutEffects Sample
- DirectX9 SDK Samples(11) CompiledEffect Sample
- DirectX9 SDK Samples(12) CustomUI Sample
- DirectX9 SDK Samples(14) EffectParam Sample(1)
- DirectX9 SDK Samples(15) OptimizedMesh Sample
- DirectX9 SDK Samples(17) StateManager Sample
- DirectX9 SDK Samples(21) HDRCubeMap Sample
- DirectX9 SDK Samples(23) HDRFormats Sample
- VMware Easy Install模式详细介绍:如何启用和禁用Easy Install模式
- Device eth0 does not seem to be present
- 程序员面试题精选100题(24)-栈的push、pop序列[数据结构]
- IIS 重启命令
- 8086/8088汇编指令系统剖析(四)
- DirectX9 SDK Samples(20) HDRDemo Sample(2)
- MOVE语句。
- READ1.
- )::WaitForSingleObject
- 黑马程序员--java多线程
- 所谓经验,半数扯淡
- spring整合quartz
- Linux RTC 驱动模型分析
- android 修改文件属性(U960S删除快门声实例)