void Geometry::renderAlphaGeometry(unsigned int subsetId) { if( _numPrelights ) { _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1 ) ); } else { _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ) ); } unsigned int shaderId = _mesh->getAttributeId( subsetId ); if( _shaders[shaderId]->effect() ) { reinterpret_cast<Effect*>( _shaders[shaderId]->effect() )->render( _mesh, subsetId, _shaders[shaderId] ); dxSetVertexShader( NULL ); dxSetPixelShader( NULL ); } else { _shaders[shaderId]->apply(); _mesh->renderSubset( subsetId, _shaders[shaderId] ); } }
static void setWireRenderStates(const Color* color) { _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ) ); D3DMATERIAL9 material; material.Diffuse = _wrap( wrap( *color ) ); material.Ambient = material.Diffuse; material.Specular = material.Diffuse; material.Emissive = material.Diffuse; _dxCR( dxSetMaterial( &material ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ) ); _dxCR( dxSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ) ); _dxCR( dxSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ) ); }
void Geometry::renderDepthMap(void) { // for each triangle - the fill rule is simple opaque black-colored painting _dxCR( dxSetRenderState( D3DRS_TEXTUREFACTOR, depthColor ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TFACTOR ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR ) ); _dxCR( dxSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ) ); _dxCR( dxSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ) ); int shaderId; int numAttributes = _mesh->NumAttributeGroups; for( int i=0; i<numAttributes; i++ ) { shaderId = _mesh->getAttributeId( i ); if( !shader( shaderId )->isInvisible() ) { _mesh->renderSubset( i, shader( shaderId ) ); } } }
void Camera::renderTextureAdditive(engine::ITexture* texture) { Texture* t = dynamic_cast<Texture*>( texture ); assert( t ); t->apply( 0 ); dxSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 ); dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); _dxCR( dxSetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ) ); _dxCR( dxSetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ) ); _dxCR( dxSetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD ) ); dxRenderRect( 0, 0, _viewPort.Width, _viewPort.Height, white ); _dxCR( dxSetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ) ); _dxCR( dxSetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ) ); }
void CameraEffect::applyMotionBlur(void) { if( _prevIsEmpty || _weight == 0.0f ) { _prevIsEmpty = false; // setup new image for texture rendering _newImage->apply( 0 ); dxSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 ); dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); dxSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); // render new image in to the previous image IDirect3DSurface9* iDirect3DSurface; _dxCR( _prevImage->iDirect3DTexture()->GetSurfaceLevel( 0, &iDirect3DSurface ) ); _dxCR( _rts->BeginScene( iDirect3DSurface, &_viewPort ) ); iDirect3DSurface->Release(); _dxCR( iDirect3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, black, 1.0f, 0L ) ); dxRenderRect( 0, 0, Engine::instance->screenWidth-1, Engine::instance->screenHeight-1, white ); _dxCR( _rts->EndScene( D3DX_FILTER_LINEAR ) ); // render new image in to the render target _dxCR( _renderTarget->iDirect3DTexture()->GetSurfaceLevel( 0, &iDirect3DSurface ) ); _dxCR( _rts->BeginScene( iDirect3DSurface, &_viewPort ) ); iDirect3DSurface->Release(); _dxCR( iDirect3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, black, 1.0f, 0L ) ); dxRenderRect( 0, 0, Engine::instance->screenWidth-1, Engine::instance->screenHeight-1, white ); _dxCR( _rts->EndScene( D3DX_FILTER_LINEAR ) ); } else { // setup blending of new image & previous image _prevImage->apply( 0 ); _newImage->apply( 1 ); Color w = D3DCOLOR_RGBA( int(255 * _weight), int(255 * _weight), int(255 * _weight), 255 ); dxSetRenderState( D3DRS_TEXTUREFACTOR, w ); dxSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 ); dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 ); dxSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_LERP ); dxSetTextureStageState( 1, D3DTSS_COLORARG0, D3DTA_TFACTOR ); dxSetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT ); dxSetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE ); dxSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT ); dxSetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); dxSetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE ); // blend new image & prev image into the render target IDirect3DSurface9* iDirect3DSurface; _dxCR( _renderTarget->iDirect3DTexture()->GetSurfaceLevel( 0, &iDirect3DSurface ) ); _dxCR( _rts->BeginScene( iDirect3DSurface, &_viewPort ) ); iDirect3DSurface->Release(); _dxCR( iDirect3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, black, 1.0f, 0L ) ); dxRenderRect( 0, 0, Engine::instance->screenWidth-1, Engine::instance->screenHeight-1, white ); _rts->EndScene( D3DX_FILTER_LINEAR ); // setup rendering of render target _renderTarget->apply( 0 ); dxSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 ); dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); dxSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); dxSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); // copy target image into the previous image _dxCR( _prevImage->iDirect3DTexture()->GetSurfaceLevel( 0, &iDirect3DSurface ) ); _dxCR( _rts->BeginScene( iDirect3DSurface, &_viewPort ) ); iDirect3DSurface->Release(); _dxCR( iDirect3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, black, 1.0f, 0L ) ); dxRenderRect( 0, 0, Engine::instance->screenWidth-1, Engine::instance->screenHeight-1, white ); _dxCR( _rts->EndScene( D3DX_FILTER_LINEAR ) ); } }
void Shader::apply(void) { // simple caching if( ( _lightset == 0 ) && ( _flags & engine::sfCaching ) && ( _lastShader == this ) ) { Engine::instance->statistics.shaderCacheHits++; return; } _lastShader = this; // setup lighting if( _lightset == 0 ) { _materialColor.Emissive = _globalAmbient; dxModulateColorValue( &_materialColor.Emissive, &_materialColor.Diffuse ); _dxCR( dxSetMaterial( &_materialColor ) ); } else { BSP::currentBSP->calculateGlobalAmbient( _lightset ); BSPSector::currentSector->illuminate( _lightset ); _materialColor.Emissive = _globalAmbient; dxModulateColorValue( &_materialColor.Emissive, &_materialColor.Diffuse ); _dxCR( dxSetMaterial( &_materialColor ) ); } // current lightmap (if exists) Texture* lightmap = NULL; if( BSPSector::currentSector ) { if( BSPSector::currentSector->lightmap() ) { lightmap = BSPSector::currentSector->lightmap(); } if( Atomic::currentAtomic && Atomic::currentAtomic->lightmap() ) { lightmap = Atomic::currentAtomic->lightmap(); } } // cannot cache shaders with lightmaps if( lightmap ) _lastShader = NULL; // setup culling if( _flags & engine::sfCulling ) { _dxCR( dxSetRenderState( D3DRS_CULLMODE, D3DCULL_CW ) ); } else { _dxCR( dxSetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ) ); } // setup alpha-blending if( _flags & engine::sfAlphaBlending ) { _dxCR( dxSetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_SRCBLEND, _srcBlend ) ); _dxCR( dxSetRenderState( D3DRS_DESTBLEND, _dstBlend ) ); _dxCR( dxSetRenderState( D3DRS_BLENDOP, _blendOp ) ); } else { _dxCR( dxSetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ) ); } // setup alpha-testing if( _flags & engine::sfAlphaTesting ) { _dxCR( dxSetRenderState( D3DRS_ALPHATESTENABLE, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_ALPHAFUNC, _alphaTestFunction ) ); _dxCR( dxSetRenderState( D3DRS_ALPHAREF, _alphaTestRef ) ); } else { _dxCR( dxSetRenderState( D3DRS_ALPHATESTENABLE, FALSE ) ); } // fixed function pipeline : first texture if( _numLayers ) { assert( _layerTexture[0] ); _layerTexture[0]->apply( 0 ); _dxCR( dxSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, _layerUV[0] ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ) ); } // fixed function pipeline : multitextures int stageId; for( stageId=1; stageId<_numLayers; stageId++ ) { assert( _layerTexture[stageId] ); _layerTexture[stageId]->apply( stageId ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_TEXCOORDINDEX, _layerUV[stageId] ) ); switch( _layerBlending[stageId] ) { case engine::btOver: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); case engine::btAdd: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_ADD ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btSub: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_SUBTRACT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btAddSigned: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_ADDSIGNED ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btAddSmooth: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_ADDSMOOTH ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btModulate: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_MODULATE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btModulate2x: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_MODULATE2X ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btModulate4x: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_MODULATE4X ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); break; case engine::btBlendTextureAlpha: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_TEXTURE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_CURRENT ) ); break; case engine::btLerp: _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_LERP ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG0, D3DTA_CONSTANT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_CONSTANT, _layerConstant[stageId] ) ); break; default: assert( !"Shouldn't be here!" ); } _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG1, D3DTA_CURRENT ) ); } // lighting if( _flags & engine::sfLighting ) { if( lightmap ) { if( _numLayers ) { lightmap->apply( stageId ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_TEXCOORDINDEX, 1 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_MODULATE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAOP, D3DTOP_MODULATE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG2, D3DTA_TEXTURE ) ); stageId++; } else { lightmap->apply( 0 ); _dxCR( dxSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ) ); stageId++; } } else { if( _numLayers ) { _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_MODULATE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_DIFFUSE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAOP, D3DTOP_MODULATE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ) ); stageId++; } else { _dxCR( dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ) ); } } } // normal map ( for programmable pipeline only ) /*if( _normalMap ) { _normalMap->apply( stageId ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_TEXCOORDINDEX, 0 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG1, D3DTA_CURRENT ) ); stageId++; }*/ // environment map ( for programmable pipeline only ) /*if( _environmentMap ) { _environmentMap->apply( stageId ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR | 1 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_ADD ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG1, D3DTA_CURRENT ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_COLORARG2, D3DTA_TEXTURE ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ) ); _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAARG1, D3DTA_CURRENT ) ); stageId++; }*/ _dxCR( dxSetTextureStageState( stageId, D3DTSS_ALPHAOP, D3DTOP_DISABLE ) ); //_dxCR( dxSetTextureStageState( stageId, D3DTSS_COLOROP, D3DTOP_DISABLE ) ); // ms2010error }
void BSP::render(void) { currentBSP = this; // reset shader buffering Shader::_lastShader = NULL; _renderFrameId++; Engine::statistics.bspTotal += _root->getNumLeafSectors(); // update LODs for( ClumpI clumpI = _clumps.begin(); clumpI != _clumps.end(); clumpI++ ) { (*clumpI)->updateLODs(); } calculateGlobalAmbient( 0 ); // setup fog if( _fogMode != D3DFOG_NONE ) { dxSetRenderState( D3DRS_FOGENABLE, TRUE ); dxSetRenderState( D3DRS_FOGCOLOR, _fogColor ); dxSetRenderState( D3DRS_FOGTABLEMODE, _fogMode ); switch( _fogMode ) { case D3DFOG_LINEAR: dxSetRenderState( D3DRS_FOGSTART, *(DWORD*)(&_fogStart) ); dxSetRenderState( D3DRS_FOGEND, *(DWORD*)(&_fogEnd) ); break; case D3DFOG_EXP: case D3DFOG_EXP2: dxSetRenderState( D3DRS_FOGDENSITY, *(DWORD*)(&_fogDensity) ); break; } } // render all opaque geometry sectorRender( _root ); // render all batched geometries for( BatchI batchI = _batches.begin(); batchI != _batches.end(); batchI++ ) { (*batchI)->render(); } // render all transparent geometry renderAlphaGeometry(); { // find light for shadow casting Light* caster = NULL; forAllClumps( findShadowCastLightCB, &caster ); // build shadow casting data Vector lightPosData; if( caster ) { lightPosData.x = caster->frame()->LTM._41; lightPosData.y = caster->frame()->LTM._42; lightPosData.z = caster->frame()->LTM._43; } Vector* lightPos = caster ? &lightPosData : NULL; Vector* lightDir = caster ? NULL : &_shadowCastDirection; // fill stencil buffer with shadow data _renderFrameId++; sectorRenderShadowVolume( _root, _shadowVolume, _shadowCastDepth, lightPos, lightDir ); } // render shadow mask _shadowVolume->renderShadow( &_shadowCastColor ); for( RenderingI renderingI = _renderings.begin(); renderingI != _renderings.end(); renderingI++ ) { (*renderingI)->render(); } for( ParticleSystemI pSysI = _particleSystems.begin(); pSysI != _particleSystems.end(); pSysI++ ) { (*pSysI)->render(); } if( _postRenderCallback ) _postRenderCallback( _postRenderCallbackData ); // bugfix (render state corrector) dxSetRenderState( D3DRS_ZWRITEENABLE, FALSE ); Gui::instance->renderRect( rscRect, Engine::instance->alphaBlackTexture, rscTextureRect, rscColor ); dxSetRenderState( D3DRS_ZWRITEENABLE, TRUE ); // reset fog if( _fogMode != D3DFOG_NONE ) { dxSetRenderState( D3DRS_FOGENABLE, FALSE ); } // reset global ambient dxSetColorValue( Shader::globalAmbient(), 0, 0, 0, 1 ); // frame hierarchy if( Engine::instance->getRenderMode() & engine::rmFrameHierarchy ) { dxSetRenderState( D3DRS_ZENABLE, FALSE ); for( ClumpI clumpI = _clumps.begin(); clumpI != _clumps.end(); clumpI++ ) { renderFrameHierarchy( (*clumpI)->frame() ); } dxSetRenderState( D3DRS_ZENABLE, TRUE ); } //fclose( _renderReport ); //_renderReport = NULL; }
void Geometry::render(void) { // add "false &&" to enable lights for all geometry if( _numPrelights ) { _dxCR( dxSetRenderState( D3DRS_LIGHTING, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1 ) ); } else { _dxCR( dxSetRenderState( D3DRS_LIGHTING, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ) ); } int shaderId; int numAttributes = _mesh->NumAttributeGroups; for( int i=0; i<numAttributes; i++ ) { shaderId = _mesh->getAttributeId( i ); if( !shader( shaderId )->isInvisible() ) { // shading technique contains alpha blending/testing? if( ( _shaders[shaderId]->getFlags() & engine::sfAlphaBlending || _shaders[shaderId]->getFlags() & engine::sfAlphaTesting ) && ( Atomic::currentAtomic || BSPSector::currentSector ) ) { if( Atomic::currentAtomic ) { BSP* bsp = getAtomicBSP( Atomic::currentAtomic ); if( bsp ) bsp->addAlphaGeometry( Atomic::currentAtomic, i ); } else if( BSPSector::currentSector ) { BSP* bsp = BSPSector::currentSector->bsp(); assert( bsp ); bsp->addAlphaGeometry( BSPSector::currentSector, i ); } } else if( _shaders[shaderId]->effect() ) { reinterpret_cast<Effect*>( _shaders[shaderId]->effect() )->render( _mesh, i, _shaders[shaderId] ); dxSetVertexShader( NULL ); dxSetPixelShader( NULL ); } else { if( _mesh->pSkinInfo ) { int i=0; } _shaders[shaderId]->apply(); _mesh->renderSubset( i, _shaders[shaderId] ); // if shader use non-default lightset, then recalculate // lighting back to default lightset if( _shaders[shaderId]->getLightset() ) { BSP::currentBSP->calculateGlobalAmbient( 0 ); BSPSector::currentSector->illuminate( 0 ); } } } } }
void Rain::render(void) { float dot; Vector x,y,z; Vector vector; Matrix m; unsigned int i; // culling value float cullDot = cos( Camera::fov * D3DX_PI / 180.0f ); // lock buffers void* vertexData = NULL; void* indexData = NULL; _dxCR( _vertexBuffer->Lock( 0, _numParticles * 4 * sizeof( RainParticleVertex ), &vertexData, D3DLOCK_DISCARD ) ); _dxCR( _indexBuffer->Lock( 0, _numParticles * 6 * sizeof( WORD ), &indexData, D3DLOCK_DISCARD ) ); assert( vertexData ); assert( indexData ); RainParticleVertex* vertex = (RainParticleVertex*)( vertexData ); WORD* index = (WORD*)( indexData ); // render particles RainParticle* particle; unsigned int numVisibleParticles = 0; for( i=0; i<_numParticles; i++ ) { // particle pointer particle = _particles + i; // build billboard matrix z = particle->pos - Camera::eyePos; D3DXVec3Normalize( &z, &z ); // particle culling dot = D3DXVec3Dot( &z, &Camera::eyeDirection ); if( -dot <= cullDot ) continue; // rest of billboard matrix D3DXVec3Scale( &y, &particle->vel, -1 ); D3DXVec3Normalize( &y, &y ); D3DXVec3Cross( &x, &y, &z ); D3DXVec3Normalize( &x, &x ); x.x *= rainXScale, x.y *= rainXScale, x.z *= rainXScale; y.x *= rainYScale, y.y *= rainYScale, y.z *= rainYScale; z.x *= rainZScale, z.y *= rainZScale, z.z *= rainZScale; // finalize m._11 = x.x, m._12 = x.y, m._13 = x.z, m._14 = 0.0f, m._21 = y.x, m._22 = y.y, m._23 = y.z, m._24 = 0.0f, m._31 = z.x, m._32 = z.y, m._33 = z.z, m._34 = 0.0f, m._41 = 0.0f, m._42 = 0.0f, m._43 = 0.0f, m._44 = 1.0f; // transform vertex coordinates by matrix D3DXVec3TransformCoord( &vertex[0].pos, &billboardVertices[0], &m ); D3DXVec3TransformCoord( &vertex[1].pos, &billboardVertices[1], &m ); D3DXVec3TransformCoord( &vertex[2].pos, &billboardVertices[2], &m ); D3DXVec3TransformCoord( &vertex[3].pos, &billboardVertices[3], &m ); vertex[0].pos.x += particle->pos.x, vertex[0].pos.y += particle->pos.y, vertex[0].pos.z += particle->pos.z, vertex[1].pos.x += particle->pos.x, vertex[1].pos.y += particle->pos.y, vertex[1].pos.z += particle->pos.z, vertex[2].pos.x += particle->pos.x, vertex[2].pos.y += particle->pos.y, vertex[2].pos.z += particle->pos.z, vertex[3].pos.x += particle->pos.x, vertex[3].pos.y += particle->pos.y, vertex[3].pos.z += particle->pos.z; // setup uvs vertex[0].uv = billboardUVs[0]; vertex[1].uv = billboardUVs[1]; vertex[2].uv = billboardUVs[2]; vertex[3].uv = billboardUVs[3]; // setup colors vertex[0].color = vertex[1].color = vertex[2].color = vertex[3].color = _ambient; // indices... index[0] = numVisibleParticles * 4 + 0; index[1] = numVisibleParticles * 4 + 1; index[2] = numVisibleParticles * 4 + 2; index[3] = numVisibleParticles * 4 + 0; index[4] = numVisibleParticles * 4 + 2; index[5] = numVisibleParticles * 4 + 3; // next particle vertex += 4, index += 6, numVisibleParticles++; } // unlock buffers _vertexBuffer->Unlock(); _indexBuffer->Unlock(); // render buffers // render _dxCR( dxSetRenderState( D3DRS_LIGHTING, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_ZWRITEENABLE, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _shader->apply(); _dxCR( iDirect3DDevice->SetTransform( D3DTS_WORLD, &identity ) ); _dxCR( iDirect3DDevice->SetFVF( particleFVF ) ); _dxCR( iDirect3DDevice->SetStreamSource( 0, _vertexBuffer, 0, sizeof( RainParticleVertex ) ) ); _dxCR( iDirect3DDevice->SetIndices( _indexBuffer ) ); _dxCR( iDirect3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, numVisibleParticles * 4, 0, numVisibleParticles * 2 ) ); _dxCR( dxSetRenderState( D3DRS_ZWRITEENABLE, TRUE ) ); _dxCR( dxSetRenderState( D3DRS_LIGHTING, TRUE ) ); // debug info //mainwnd::IMainWnd* iMainWnd; //queryInterfaceT( "MainWnd", &iMainWnd ); //iMainWnd->setWindowText( strformat( "Rain::render(): numVisibleParticles = %d", numVisibleParticles ).c_str() ); }