Главная » Статьи » IT |
однопроходный постпроцессор для D3D9
Думаю ничего пояснять не надо. Всё и так должно быть понятно. Декларацияclass post_processor_surface { public: IDirect3DTexture9* m_pTexture; IDirect3DSurface9* m_pSurface; post_processor_surface(IDirect3DDevice9* _device); ~post_processor_surface(); void Clear(); }; class post_processor { post_processor_surface* m_first; post_processor_surface* m_second; IDirect3DVertexShader9* m_vertex_shader; IDirect3DPixelShader9* m_pixel_shader; public: post_processor(IDirect3DDevice9*); ~post_processor(); // // vertex program const // Name Reg Size // -------------- ----- ---- float time; //c0 1 float drojScaleImage; //c1 1 float drojScale; //c2 1 float drojSpeed; //c3 1 // // // pixel program consts // Name Reg Size // ------------------ ----- ---- //float g_time // c0 1 float blur_factor; // c1 1 float brightness; // c2 1 float contrast; // c3 1 float saturation; // c4 1 D3DCOLORVALUE color; // c5 1 float rastr_Speed; // c6 1 float rastr_Size; // c7 1 float rastr_Interference; // c8 1 IDirect3DTexture9* Image; //s0 1 IDirect3DVolumeTexture9* Rand; //s1 1 // void set_values_to_default() { time = 0.0f; drojScaleImage = 1.0f; drojScale = 0.2f; drojSpeed = 10.06f; blur_factor = 0.23f; brightness = 1.2f; contrast = 1.64f; saturation = 2.0f; color.r = color.g = color.b = color.a = 1.0f; rastr_Speed = 0.77f; rastr_Size = 4.14f; rastr_Interference = 0.14f; } void draw_quad(IDirect3DDevice9*); void do_postprocesses( IDirect3DDevice9* device, post_processor_surface* sceneAfterDraw ); }; Пример использованияvoid RenderFrame() { HRESULT hr=0; D3DXMATRIX mat; D3DXMatrixIdentity(&mat); g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat ); g_pd3dDevice->SetTransform( D3DTS_VIEW, &mat ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &mat ); g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); // begin g_pd3dDevice->BeginScene(); IDirect3DSurface9* backbuf=NULL; if (g_enable_postprocessing) { // set parameters g_post_processor->time = Time(); g_post_processor->Rand = g_random3d; // get backbuffer rendertarget and set new rendertarget g_pd3dDevice->GetRenderTarget(0, &backbuf ); g_pd3dDevice->SetRenderTarget(0, g_surface_for_scene->m_pSurface ); } // draw image quad as sample scene draw_sample_scene(); if (g_enable_postprocessing) { //restore rendertarget g_pd3dDevice->SetRenderTarget(0, backbuf ); // end. do postprocesses g_post_processor->do_postprocesses(g_pd3dDevice, g_surface_for_scene ); } //release backbuf interface if(backbuf) backbuf->Release(); backbuf=NULL; // end g_pd3dDevice->EndScene(); g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } | |
Просмотров: 383 | | |
Всего комментариев: 0 | |