Detail Textures on Atlas2 terrains (sorta)
by Dreamer · in Torque Game Engine Advanced · 12/06/2006 (4:53 pm) · 3 replies
Hello everyone,
After weeks of working trying to get detail textures (and normal maps by simple extension) working on Atlas2, here is how you do it.
Thanks to Dave Young for most of this code (except for any broken parts, those are my fault :)
In atlas/runtime/clipmapBatcher.cpp add this function
The rest is elementary, just add in atlasClipMap.cpp a function called
Next just modify your materials.cs to include an atlas shader.
Now here's the wierd thing.
This appears to work good for the most part, however I have noticed that if I have more than 1 Atlas terrain instance it fails to render the detailTexture, but will do a nice smoothing pass that does make the whole thing look a whole lot better. but sadly in this case no detail texture gets rendered.
I'm hoping someone can look at this and point me in the right direction.
Regards,
Dreamer
After weeks of working trying to get detail textures (and normal maps by simple extension) working on Atlas2, here is how you do it.
Thanks to Dave Young for most of this code (except for any broken parts, those are my fault :)
In atlas/runtime/clipmapBatcher.cpp add this function
void AtlasClipMapBatcher::renderDetail()
{
PROFILE_START(AtlasClipMapBatcher_renderDetail);
// Grab the shader for this pass - replaceme w/ real code.
GFXShader *s;
ShaderData *sd;
if(!Sim::findObject("AtlasShader", sd))
{
Con::errorf("AtlasClipMapBatcher::renderDetail - no shader 'AtlasSurface");
return;
}
// Set up the fog shader and texture.
GFX->setShader(sd->shader);
GFX->setTexture(2, mClipMap->getDetailTex());
GFX->setTextureStageAddressModeU(0, GFXAddressClamp);
GFX->setTextureStageAddressModeV(0, GFXAddressClamp);
GFX->setTexture(3, mClipMap->getDetailTex());
GFX->setTextureStageAddressModeU(0, GFXAddressClamp);
GFX->setTextureStageAddressModeV(0, GFXAddressClamp);
// We need the eye pos but AtlasInstance2 deals with setting this up.
// Set blend mode and alpha test as well.
GFX->setAlphaBlendEnable(true);
GFX->setSrcBlend(GFXBlendSrcAlpha);
GFX->setDestBlend(GFXBlendInvSrcAlpha);
GFX->setAlphaTestEnable(true);
GFX->setAlphaFunc(GFXCmpGreaterEqual);
GFX->setAlphaRef(2);
// And render all the detail chunks - all for now.
//not sure which constants we need set for the normal surface/detail render
for(S32 i=0; i<mDetailList.size(); i++)
{
// Grab the render note.
const RenderNote *rn = mDetailList[i];
// Pass morph constant to the chunk.
Point4F chunkConsts(rn->morph, 0, 0, 0);
GFX->setVertexShaderConstF(49, &chunkConsts.x, 1);
rn->chunk->render();
}
GFX->setAlphaBlendEnable(false);
GFX->setAlphaTestEnable(false);
// Don't forget to clean up.
for(S32 i=0; i<4; i++)
GFX->setTexture(0, NULL);
PROFILE_END();
}The rest is elementary, just add in atlasClipMap.cpp a function called
getDetailTex()All it needs to do is return the current DetailTextureHandle.
Next just modify your materials.cs to include an atlas shader.
Now here's the wierd thing.
This appears to work good for the most part, however I have noticed that if I have more than 1 Atlas terrain instance it fails to render the detailTexture, but will do a nice smoothing pass that does make the whole thing look a whole lot better. but sadly in this case no detail texture gets rendered.
I'm hoping someone can look at this and point me in the right direction.
Regards,
Dreamer
#2
12/07/2006 (5:09 pm)
Can i see a screenshot Dreamer, I'm really interested in this for a school project, were doing MMO design and I'm supposed to eventually come up with working terrain with one class for players and one MOB, and 3 areas that are not zoned. I'm not supposed to be worried about the aesthetics very much but the function of the area's, but i really want to add this it doesn't look hard so I was wondering what it looked like?
#3
12/15/2006 (9:22 am)
I've fiddled with this quite a bit, and haven't ever been able to make it work. It seems like a good start, but non-functional. I've also tinkered quite a bit with trying to get a shader to do detail mapping or normal mapping with atlas to no avail.
Torque Owner Dreamer
Default Studio Name
We'll start in AtlasInstance2.cpp
Right after the ClipMap is instantiated
You'll want to add...
Note: This would probably be a ton more efficient if we were just passing a pointer instead.
Anyways onto the AtlasClipMap.h
add this in the private section somewhere
Next somewhere nice and public add this
inline void setDetailTex(GFXTexHandle tex){mDetailTex = tex;} inline GFXTexHandle getDetailTex(){return mDetailTex;}And thats pretty much all ya need.