Jump to content
  • Advertisement
Sign in to follow this  

Shining Meshes

This topic is 1751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I noticed in some modern games that all the meshes are shining.
 
I'm not talking about specular light here, but the entire mesh is shining which make it look much more realistic, how do I get this effect?

Share this post


Link to post
Share on other sites
Advertisement

Like the environment is reflected on polished metal? Maybe you are looking for environmental mapping.

Edited by Tispe

Share this post


Link to post
Share on other sites

Do you mean meshes which seem to be emitting light by themselves instead of reflecting light from light sources?

You can achieve this with emissive materials, which are materials which have an emissive color or texture which gets added to the lighting results of the geometry.

Note that emissive materials in general don't affect surrounding geometry though as they're not actual light sources

Share this post


Link to post
Share on other sites

Yeah, those are done with environment maps, like Tispe said

This technique is achieved by calculating a reflection vector for your surface point and using it to sample relfections from a cube map.

Share this post


Link to post
Share on other sites

At start use pre-existing cube texture and practice with that.

If you must, to match the surrounding scene you must have dynamic cube, which means you must render your scene multiple times, possibly in lower resolution for better performance, something like this (chopped code from my old project):

D3DXCreateRenderToEnvMap(device, CUBEMAP_RESOLUTION, 1, format, TRUE, D3DFMT_D16, &RenderToEnvMap);
D3DXCreateCubeTexture(device, CUBEMAP_RESOLUTION, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &CubeMapTexture);
...
void RenderSceneIntoEnvMap(D3DXVECTOR3 camPosition)
{
    // 90 degree fov to get a seamless environment map texture
    D3DXMATRIX cubeProj;
    D3DXMatrixPerspectiveFovLH( &cubeProj, D3DX_PI * 0.5f, 1.0f, 1.0f, 1000.0f );

    RenderToEnvMap->BeginCube(CubeMapTexture);

    for(UINT i = 0; i < 6; i++)
    {
        RenderToEnvMap->Face((D3DCUBEMAP_FACES)i, 0 );
        D3DXMATRIX cubeFaceView = getCubeMapViewMatrix((D3DCUBEMAP_FACES)i, camPosition);
        D3DDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0 );
        RenderScene(&cubeFaceView, &cubeProj);
    }

    RenderToEnvMap->End(0);
}
...
 
D3DXMATRIX getCubeMapViewMatrix(DWORD dwFace, D3DXVECTOR3 camPosition)
{
    D3DXVECTOR3 lookDir;
    D3DXVECTOR3 upDir;

    switch( dwFace )
    {
    case D3DCUBEMAP_FACE_POSITIVE_X:
        lookDir = D3DXVECTOR3( 1.0f, 0.0f, 0.0f ) + camPosition;
        upDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
        break;
    case D3DCUBEMAP_FACE_NEGATIVE_X:
        lookDir = D3DXVECTOR3(-1.0f, 0.0f, 0.0f ) + camPosition;
        upDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
        break;
    case D3DCUBEMAP_FACE_POSITIVE_Y:
        lookDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) + camPosition;
        upDir   = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
        break;
    case D3DCUBEMAP_FACE_NEGATIVE_Y:
        lookDir = D3DXVECTOR3( 0.0f,-1.0f, 0.0f ) + camPosition;
        upDir   = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
        break;
    case D3DCUBEMAP_FACE_POSITIVE_Z:
        lookDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ) + camPosition;
        upDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
        break;
    case D3DCUBEMAP_FACE_NEGATIVE_Z:
        lookDir = D3DXVECTOR3( 0.0f, 0.0f,-1.0f ) + camPosition;
        upDir   = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
        break;
    }

    D3DXMATRIX cubeFaceView;
    D3DXMatrixLookAtLH( &cubeFaceView, &camPosition, &lookDir, &upDir );
    return cubeFaceView;
}

Or use some other method to render your environment like "dual paraboloid" but then that is not cube texture.

Edited by belfegor

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!