[2.3] Flat shade Terra terrain

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
old_man_auz
Greenskin
Posts: 100
Joined: Tue Jun 15, 2004 5:10 am
Location: Australia

[2.3] Flat shade Terra terrain

Post by old_man_auz »

Hi,
I'm trying to flat shade the Terra terrain. To do so, I believe I need each vertex of a triangle to have the same normal.

So I was playing with the "GpuNormalMapper_ps.hlsl" shader and trying a few things but I came to realisation that as it stands, the shader is caluclating a normal on a per vertex basis, so you can't set the normals for each of the verticies of a triangle together.

Is this even possible in a pixel shader or do you need to go about it another way?

Thanks for any hints in the right direction.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.3] Flat shade Terra terrain

Post by dark_sylinc »

It's worth trying using point sampling instead of bi/trilinear

Find the code:

Code: Select all

*commandBuffer->addCommand<CbTexture>() = CbTexture(
    mTexBufUnitSlotEnd + 1u, terraObj->getNormalMapTex(), mAreaLightMasksSamplerblock );
There you need to replace mAreaLightMasksSamplerblock. We're reusing mAreaLightMasksSamplerblock which is a samplerblock set to trilinear (in OgreHlmsPbs.cpp):

Code: Select all

if( !mAreaLightMasksSamplerblock )
{
    samplerblock.mMinFilter     = FO_LINEAR;
    samplerblock.mMagFilter     = FO_LINEAR;
    samplerblock.mMipFilter     = FO_LINEAR;
    samplerblock.mCompareFunction   = NUM_COMPARE_FUNCTIONS;

    samplerblock.mU             = TAM_CLAMP;
    samplerblock.mV             = TAM_CLAMP;
    samplerblock.mW             = TAM_CLAMP;

    mAreaLightMasksSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
}
Create a new sampler block set to FO_POINT/FO_POINT/FO_NONE (or FO_POINT/FO_POINT/FO_POINT) and see if that gives you satisfying results.

Otherwise the solution would be to modify the shaders so that the normal map is sampled in the Vertex Shader instead of Pixel Shader, and the normal is sent directly from there using flat interpolation.
Post Reply