コード例 #1
0
Shader::Shader(int numLayers, const char* shaderName)
{
    _numReferences = 1;
    _name = shaderName ? shaderName : "UnnamedShader";

    assert( numLayers>=0 && numLayers<=engine::maxTextureLayers );
    _numLayers = numLayers;

    for( int i=0; i<engine::maxTextureLayers; i++ )
    {
        _layerTexture[i] = NULL;
        _layerBlending[i] = engine::btOver;
        _layerUV[i] = 0;
        _layerConstant[i] = D3DCOLOR_RGBA( 0,0,0,0 );
    }

    dxSetColorValue( &_materialColor.Diffuse, 1,1,1,1 );
    dxSetColorValue( &_materialColor.Ambient, 0,0,0,1 );
    dxSetColorValue( &_materialColor.Specular, 0,0,0,1 );
    dxSetColorValue( &_materialColor.Emissive, 0,0,0,1 );
    _materialColor.Power = 0;

    _normalMap = NULL;
    _normalMapUV = 0;

    _environmentMap = NULL;

    _flags             = engine::sfCulling | engine::sfCollision | engine::sfCaching | engine::sfLighting;
    _lightset          = 0;
    _srcBlend          = D3DBLEND_SRCALPHA;
    _dstBlend          = D3DBLEND_INVSRCALPHA;
    _blendOp           = D3DBLENDOP_ADD;
    _alphaTestFunction = D3DCMP_GREATER;
    _alphaTestRef      = 128;
    _effect            = NULL;

    // reset hemisphere
    _hemisphere[0].r = _hemisphere[0].g = _hemisphere[0].b =
    _hemisphere[1].r = _hemisphere[1].g = _hemisphere[1].b = 0.0f;
    _hemisphere[0].a = _hemisphere[1].a = 1.0f;

    // reset cinematic lighting
    _illuminationColor.r = _illuminationColor.g = _illuminationColor.b = 0.0f;
    _illuminationColor.a = 1.0f;
    _contourColor.r = _contourColor.g = _contourColor.b = 0.0f;
    _contourColor.a = 1.0f;
}
コード例 #2
0
ファイル: bsp.cpp プロジェクト: cheinkn/basextreme
void BSP::calculateGlobalAmbient(unsigned int lightset)
{
    // calculate world global ambient color for default lightset
    dxSetColorValue( Shader::globalAmbient(), 0, 0, 0, 1 );
    for( LightI ambientI = _ambients.begin();
                ambientI != _ambients.end();
                ambientI++ )
    {
        if( (*ambientI)->lightset() == lightset )
        {
            dxAddColorValue( Shader::globalAmbient(), (*ambientI)->diffuse() );
            dxSaturateColorValue( Shader::globalAmbient() );
        }
    }
}
コード例 #3
0
ファイル: bsp.cpp プロジェクト: cheinkn/basextreme
Vector4f BSP::getAmbient(unsigned int lightset)
{
    // calculate world global ambient color
    D3DCOLORVALUE result;
    dxSetColorValue( &result, 0, 0, 0, 1 );
    for( LightI ambientI = _ambients.begin();
                ambientI != _ambients.end();
                ambientI++ )
    {
        if( (*ambientI)->lightset() == lightset )
        {
            dxAddColorValue( &result, (*ambientI)->diffuse() );
            dxSaturateColorValue( &result );
        }
    }
    return Vector4f( result.r, result.g, result.b, result.a );
}
コード例 #4
0
ファイル: bsp.cpp プロジェクト: cheinkn/basextreme
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;
}