Game Development Community

Road Decal Textures...

by CSMP · in Torque Game Engine · 09/21/2009 (2:22 pm) · 29 replies

I'm using the DecalProjector for a Road and I noticed 2 things:

1. It seems the DecalProjector does not like Transparent Images.
(Or most likely I was incorrectly trying to remove the opacity from an image... and in that case, How would I correctly take an opaque texture using PhotoshopCS and add transparency?)

2. A Texture used with the DecalProjector does not fade out with the fog, and is only removed by the actual ViewDistance.

Any help with these two problems would be great.
Page «Previous 1 2
#1
09/27/2009 (5:14 pm)
Well I've(with help form the community!) been on a roll fixing problems lately, so I figured I'd give this one a try again.

I'm going to check if I was incorrectly adding the Alpha channel in photoshop right now.

The fact that the DecalProjector texture does not fade in the fog is the main problem with its usage and could prevent me from using this method for roads.

Even though DecalProjectors are not the easiest to use in unlevel terrains, if the Fog problem is fixed I believe this is the method I will be using.
(which except for the fog problem, Looks awesome... not too mention if/when I get the texture Alpha channel working!)
#2
09/27/2009 (5:35 pm)
I've heard of people having problems with transparencies in Photoshop -- but all seems to work fine for me using the Gimp. I think it was recommended to use an old "SuperPNG" plugin for PS if you need to work with transparency.

But yeah, that whole decal shining through the fog thing is rather annoying.
#3
09/27/2009 (5:40 pm)
I just tried again, and my problem with the transparency was that I was using .jpg, and while checking the properties of the LightingPack GlowDecal(arrow) I noticed they used .png.

So Transparency problem fixed... and again the Road Looks awesome with a special TerrainRoadBase texture blending together.

I was trying to think what the closest relative to the Decal would be to try and extract a working FogFading code for the DecalProjector.
#4
09/27/2009 (5:47 pm)
LOL, check this out:
http://www.garagegames.com/community/forums/viewthread/54317
Never noticed this before...

Checking it out right now, Ill post results asap.
Edit: OK, Kinda the results I wanted, Has a couple of problems though...
Problems seem to be angle dependant because it works from some angles and other angles it only fades some of the road sections...
I'm adding bug reports to the resource itself...
#5
09/28/2009 (10:43 am)
The problem with fog and decals is it needs to check all four corners and apply the needed fog colour and fade amount to each, especially for large decals.
I once managed to get the fade working, but not colourization, so might look into this again.
I found the best place to do this check is in DecalManager::renderDecal(), but you have to allow the scene state for the function (SceneState* state).
Near the middle of the function you will find the code for the four corners using the same fade value. Just change fade to be "U8" instead of "const U8" and set modify the fade value with whatever fogamount is found at that position. You'll need to do some number trickery since getHazeAndFog() returns a float and color.set() uses integers.
#6
09/29/2009 (4:07 pm)
At the moment I've been putting this issue aside, though in a week or two I will be getting back to this.
#7
09/29/2009 (9:59 pm)
I think I'll also take a look at this - decal roads are something I'm interested in. Don't know if it will take priority over current work, though :P.

EDIT: Scratch that, it was a 5-minute fix ;P. Try this in renderDecal(), after changing it to renderDecal(SceneState* state) and making the appropriate changes to calls:
renderVerts.increment(4);
     indices.increment(6);
     DecalVert *verts = &(renderVerts[decalCount * 4]);
     U16 *ind = &(indices[decalCount * 6]);
     
     U8	fade = mDecalQueue[x]->fade * 255;
     F32 fogmod = 1.0;
     Point3F vec;
     
     vec = mDecalQueue[x]->point[3] - state->getCameraPosition();
     fogmod = 1.0f - state->getHazeAndFog(vec.len(),vec.z);
     verts[0].vert = mDecalQueue[x]->point[3];
     verts[0].texCoord.set(0, 0);
     verts[0].color.set(255, 255, 255, (U8)(fade * fogmod));
     ind[0] = decalCount * 4;
     ind[5] = decalCount * 4;
      
     vec = mDecalQueue[x]->point[2] - state->getCameraPosition();
     fogmod = 1.0f - state->getHazeAndFog(vec.len(),vec.z);
     verts[1].vert = mDecalQueue[x]->point[2];
     verts[1].texCoord.set(0, 1);
     verts[1].color.set(255, 255, 255, (U8)(fade * fogmod));
     ind[1] = decalCount * 4 + 1;
      
     vec = mDecalQueue[x]->point[1] - state->getCameraPosition();
     fogmod = 1.0f - state->getHazeAndFog(vec.len(),vec.z);
     verts[2].vert = mDecalQueue[x]->point[1];
     verts[2].texCoord.set(1, 1);
     verts[2].color.set(255, 255, 255, (U8)(fade * fogmod));
     ind[2] = decalCount * 4 + 2;
     ind[3] = decalCount * 4 + 2;
      
     vec = mDecalQueue[x]->point[0] - state->getCameraPosition();
     fogmod = 1.0f - state->getHazeAndFog(vec.len(),vec.z);
     verts[3].vert = mDecalQueue[x]->point[0];
     verts[3].texCoord.set(1, 0);
     verts[3].color.set(255, 255, 255, (U8)(fade * fogmod));
     ind[4] = decalCount * 4 + 3;
      
     decalCount++;   
   }
That seems to be working for me, after a very cursory test with Kork's footprints. Also, it doesn't do anything about the colour, just fades the decals out smoothly.
#8
09/30/2009 (8:22 am)
Indeed it is a five minute fix, but the colour still eludes me. Setting the texture colour or the vert colour has no effect.
#9
09/30/2009 (3:25 pm)
After trying every method of fogging in TGE, it would appear the FogCoord method is the easiest to get working.

void DecalManager::renderDecal(SceneState* state)
{
   static Vector<DecalVert> renderVerts(__FILE__, __LINE__);
   static Vector<U16> indices(__FILE__, __LINE__);
   renderVerts.clear();
   indices.clear();
   U32 decalCount = 0;
   
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   glEnableClientState(GL_COLOR_ARRAY);
    
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_BLEND);
   glEnable(GL_ALPHA_TEST);
   glDepthMask(GL_FALSE);
   glAlphaFunc(GL_GREATER, 0.1f);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

   if (dglDoesSupportARBMultitexture() && dglDoesSupportFogCoord())
   {
      glEnable(GL_FOG);
      glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
      GLfloat fogColor[4];
      fogColor[0] = state->getFogColor().red;
      fogColor[1] = state->getFogColor().green;
      fogColor[2] = state->getFogColor().blue;
      fogColor[3] = 0.5f;
      glFogfv(GL_FOG_COLOR, fogColor);
      glFogi(GL_FOG_MODE, GL_LINEAR);
      glFogf(GL_FOG_START, 0.0f);
      glFogf(GL_FOG_END, 1.0f);
   }

...

   glDepthMask(GL_TRUE);
   glDisable(GL_BLEND);
   glDisable(GL_FOG);
   glDisable(GL_TEXTURE_2D);
   glDisable(GL_ALPHA_TEST);
}

EDIT: What's with not being able to us bold within the code mark-ups any more?
#10
09/30/2009 (4:29 pm)
Strange, I've tried both of the fixes and in each instance I'm getting this error:
..\engine\sim\decalManager.cc(403) : error C2511: 'void DecalManager::renderDecal(SceneState *)' : overloaded member function not found in 'DecalManager'
        ../engine\sim/decalManager.h(63) : see declaration of 'DecalManager'

I've looked at both snippets and my .cc file and they look fine but both give the same error, I'm not quite sure what else is needed.

Btw: is this to be used with Caylo Fog Resource I linked above, because even then they don't work.(which I'm pretty sure you all's snippets are stand-alone changes?)
#11
09/30/2009 (5:09 pm)
Remember to change "void renderDecal(); to "void renderDecal(SceneState* state);" in decalManager.h

The code Daniel posted is a better alternative to Caylo's resource, so you do not need both.
The fogcoord snippet can be used stand-alone, just remove the "SceneState* state" from renderDecal(); if you do not need to use the fade-out code.
#12
09/30/2009 (5:53 pm)
Awesome, Thank you both for the help...
It looks great!

Btw: what would the differance be from Daniels code to yours?

P.S. My main problems with using Decals for the roads would be the elevation changes in terrain, in my tests I've mainly been using flat terrain though it seems with a little work it could work on angles as well.

#13
09/30/2009 (6:43 pm)
They do two different things. Daniels code fades the decal, my code changes the colour of the decal. Both can be used together, which might be preferable if someone has a graphics card that does not support fog coords.

The major drawback of decals is the fact is does not work on angled surfaces. That's fine for what it was designed for, but not for a road.
If you manage to get it to work the way you want, I would be interested in having that code.
#14
09/30/2009 (7:57 pm)
While Flat Terrain would really be the ideal setup for the RoadDecals, angles would make them more flexible, however they would still be limited with angles that would "look" right.(though for performance not using a new decal for every angle)

I was thinking about the "Conform Player to Terrain" resource for pointers on how to accomplish the decal angles.
#15
09/30/2009 (9:12 pm)
Quote:Both can be used together, which might be preferable if someone has a graphics card that does not support fog coords.
I think that's preferable in any case, just so the colour can affect the decals (or maybe link it to some global pref? My method probably entails a performance hit, with 4 vec.len() ops for every decal every render). Thanks for the fix! :)

Quote:The major drawback of decals is the fact is does not work on angled surfaces.
What do you mean? That decals don't wrap? From what I've seen, decal projectors will conform to the surface they're projected on...
#16
09/30/2009 (9:30 pm)
Quote:
From what I've seen, decal projectors will conform to the surface they're projected on...

You know I thought that same exact thing until I tested it with the roads, it doesnt seem to like "angling" with the terrain, I've gotten minor angles and actually some skewing going on at some angles but not the normal decal behavior.

Though, this is something that I only recently ported over to the MG StarterKit/MPGE Scripts(MGSK was missing all sgObjects originally) and I have not tested this with the original scripts.

And no they don't wrap either, which again I thought they did.

P.S. I'll post some pics up after I work out the right alpha on the .png.
#17
09/30/2009 (10:06 pm)
Here are some test textures,
somewhere above 55% opacity
i566.photobucket.com/albums/ss101/CS_MP/MPGE/Bugs/over50_opacity.jpg

somewhere under 50% opacity
i566.photobucket.com/albums/ss101/CS_MP/MPGE/Bugs/less50_opacity.jpg


Not quite sure which one works better, leaning toward the under 50% for the blend effect, but the over 50% is more defined... probably settle halfway for the end result.
#18
09/30/2009 (10:52 pm)
Hmm. I'd say the latter does look better.

Using the default GlowDecal with an sgDecalProjector I was able to get it angling quite nicely to terrains. Maybe larger decals create problems?

Incidentally, I'd advocate having the stripes on the road as separate decals, but I haven't tried to do anything like this, so I'm not really qualified to give an opinion ;P.
#19
10/01/2009 (1:25 am)
I must say that's looking pretty good!

Got distracted over in Torque3D land and forgot about this thread. I do like the Road tools over there (Decal and Mesh), but I would have loved to have seen this sort of thing in my own TGE stuff -- it just never occurred to me to use decals for roads until a few months ago.

Nice to see you got things sorted out :D
#20
10/01/2009 (1:43 am)
Quote:I do like the Road tools over there (Decal and Mesh), but I would have loved to have seen this sort of thing in my own TGE stuff -- it just never occurred to me to use decals for roads until a few months ago.
I'm working on it, actually ;). Mesh roads will be difficult, but I'm pretty confident about implementing decal roads.

Seems a few people have tried to get wrapping decals working before, with mixed results. When I get around to working on decal roads proper I'll see how they go.
Page «Previous 1 2