Advertisement
snake5

d3d9renderer shitload ifs

Jun 13th, 2015
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. void D3D9Renderer::_RS_Render_Shadows()
  2. {
  3.     SGRX_Scene* scene = m_currentScene;
  4.    
  5.     for( size_t pass_id = 0; pass_id < m_renderPasses.size(); ++pass_id )
  6.     {
  7.         // Only shadow passes
  8.         if( m_renderPasses[ pass_id ].type != RPT_SHADOWS )
  9.             continue;
  10.        
  11.         for( size_t light_id = 0; light_id < scene->m_lights.size(); ++light_id )
  12.         {
  13.             Mat4 m_world_view, m_inv_view;
  14.            
  15.             SGRX_Light* L = scene->m_lights.item( light_id ).key;
  16.             if( !L->enabled || !L->shadowTexture || !L->shadowTexture->m_isRenderTexture )
  17.                 continue;
  18.            
  19.             /* CULL */
  20.             _RS_Cull_SpotLight_MeshList( scene, L );
  21.            
  22.             D3D9RenderTexture* RT = (D3D9RenderTexture*) L->shadowTexture.item;
  23.            
  24.             m_dev->SetRenderTarget( 0, RT->CS );
  25.             m_dev->SetDepthStencilSurface( RT->DSS );
  26.             m_dev->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0 );
  27.            
  28.             VS_SetMat4( 4, L->projMatrix );
  29.             VS_SetMat4( 12, L->viewMatrix );
  30.             m_inv_view = L->viewMatrix;
  31.             m_inv_view.Transpose();
  32.             PS_SetMat4( 0, m_inv_view );
  33.             PS_SetMat4( 4, L->projMatrix );
  34.            
  35.             for( size_t miid = 0; miid < m_visible_spot_meshes.size(); ++miid )
  36.             {
  37.                 SGRX_MeshInstance* MI = m_visible_spot_meshes[ miid ];
  38.                
  39.                 if( !MI->mesh || !MI->enabled )
  40.                     continue; /* mesh not added / instance not enabled */
  41.                
  42.                 D3D9Mesh* M = (D3D9Mesh*) MI->mesh.item;
  43.                 if( !M->m_vertexDecl )
  44.                     continue; /* mesh not initialized */
  45.                
  46.                 D3D9VertexDecl* VD = (D3D9VertexDecl*) M->m_vertexDecl.item;
  47.                
  48.                 /* if (transparent & want solid) or (solid & want transparent), skip */
  49.                 if( MI->transparent || MI->decal )
  50.                     continue;
  51.                
  52.                 MI_ApplyConstants( MI );
  53.                
  54.                 m_world_view.Multiply( MI->matrix, L->viewMatrix );
  55.                 VS_SetMat4( 0, m_world_view );
  56.                 VS_SetMat4( 8, MI->matrix );
  57.                
  58.                 m_dev->SetRenderState( D3DRS_CULLMODE, M->m_dataFlags & MDF_NOCULL ? D3DCULL_NONE : D3DCULL_CCW );
  59.                 m_dev->SetVertexDeclaration( VD->m_vdecl );
  60.                 m_dev->SetStreamSource( 0, M->m_VB, 0, VD->m_info.size );
  61.                 m_dev->SetIndices( M->m_IB );
  62.                
  63.                 for( size_t part_id = 0; part_id < M->m_meshParts.size(); ++part_id )
  64.                 {
  65.                     SGRX_MeshPart* MP = &M->m_meshParts[ part_id ];
  66.                     SGRX_Material* MTL = MP->material;
  67.                     if( !MTL )
  68.                         continue;
  69.                     SGRX_SurfaceShader* SSH = MTL->shader;
  70.                     if( !SSH )
  71.                         continue;
  72.                    
  73.                     if( MTL->transparent )
  74.                         continue;
  75.                    
  76.                     SGRX_IVertexShader* VSH = MI->skin_matrices.size() ? SSH->m_skinVertexShaders[ pass_id ] : SSH->m_basicVertexShaders[ pass_id ];
  77.                     if( !VSH )
  78.                         continue;
  79.                     SGRX_IPixelShader* SHD = SSH->m_pixelShaders[ pass_id ];
  80.                     if( !SHD )
  81.                         continue;
  82.                    
  83.                     if( MP->indexCount < 3 )
  84.                         continue;
  85.                    
  86.                     SetVertexShader( VSH );
  87.                     SetPixelShader( SHD );
  88.                     for( int tex_id = 0; tex_id < NUM_MATERIAL_TEXTURES; ++tex_id )
  89.                         SetTexture( tex_id, MTL->textures[ tex_id ] );
  90.                    
  91.                     m_dev->DrawIndexedPrimitive(
  92.                         M->m_dataFlags & MDF_TRIANGLESTRIP ? D3DPT_TRIANGLESTRIP : D3DPT_TRIANGLELIST,
  93.                         MP->vertexOffset, 0, MP->vertexCount, MP->indexOffset, M->m_dataFlags & MDF_TRIANGLESTRIP ? MP->indexCount - 2 : MP->indexCount / 3 );
  94.                     m_stats.numDrawCalls++;
  95.                     m_stats.numSDrawCalls++;
  96.                 }
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement