mikebart@Posted: Tue May 01, 2007 2:21 pm :
I'd like to get sprites in to work in quake4 for foliage like the ES: oblivion trees.
The material includes diffuse, specular and a normal map aswell as the alpha channel.
Does anyone know of an existing shader in quake4 or doom3 that does this?



mikebart@Posted: Mon May 07, 2007 1:13 am :
I think that description might have been a bit vague so ill try again:

Ive been trying to get an alphatested shader with a specular and a normalmap for foliage on trees to work in quake4.

This is the shader im using:

Code:
models/nature/tree_foliage01
{
   deform sprite
   noShadows
   nonsolid
   noimpact
   twoSided

   qer_editorimage models/nature/tree_foliage01_d.tga
   
   {       
          blend   diffusemap
    map   models/nature/tree_foliage01_d.tga
    alphaTest 0.5
   }
}


This is what im getting:
[image]http://img244.imageshack.us/img244/3382/trees5hq3.th.jpg[/image]
basicly an unlit alphatested sprite.

I know its possible to get a particle effect sprite to use an alphatested shader, but havent found a way to get it to work through the material alone using the 'deform sprite' def, im really not too clued up on doom3 shaders but it just seems like such a simple thing.

Would really appreciate any help on this, even if you can tell me it cant be done :)



rich_is_bored@Posted: Mon May 07, 2007 2:22 am :
I don't believe sprites can be illuminated by lights. Not so much because it's impossible but rather id never bothered to implement a solution.

I mean, the idea behind a sprite is that it's like a decal that always faces the player. And while visually it might appear to be a quad floating in space it's probably represented by nothing more than a set of xyz coordinates that designate a location in game space.

You have to think about it from the perspective of the developer. If each sprite was represented by a quad that existed in game space, you'd need a routine to rotate each quad to face the player.

Meanwhile you could simply render each sprite directly onto the users screen using the sprite's distance from the player to scale the sprite to the correct dimensions.

I might be wrong but I think that the engine goes with the latter. It renders the sprites in post. And because the sprites don't occupy space in the game world, they are unaffected by lights.



mikebart@Posted: Mon May 07, 2007 2:57 am :
Thanks for the response Rich, I also asked about this on the darkmod forums and SneaksiDave showed me this, its a particle sprite pointing to an alphatested material and clearly showing bump and spec and being illuminated by lights.

http://img488.imageshack.us/my.php?image=fliesbz5.jpg

I may have missed a key point you made there but isnt this image closer to the former of your two descriptions?
Quote:
If each sprite was represented by a quad that existed in game space, you'd need a routine to rotate each quad to face the player.


and if so, im wondering if its possible to do the same thing but within the shader alone.

thanks again for the reply :)



rich_is_bored@Posted: Mon May 07, 2007 3:32 am :
Well here's the shader where that image is used...

Code:
textures/particles/fly

{
   
   noSelfShadow
   translucent
   noShadows
   twosided
   //deform sprite
   {
      blend add
      map textures/particles/fly.tga
      vertexcolor
      clamp
   }


}


Notice that deform is commented out? So this isn't a sprite. It's just a decal.

As far as creating a routine that rotates quads to face the player, you might be able to do that by making a custom entity that uses a scriptobject.

It would be more robust if you could address the problem directly via the SDK but it's doubtful that the necessary code is included.

I'm also doubtful that the problem could be addressed through a material shader alone. I can't think of a way to rotate a surface in 3D space via just a material shader and that's just half the problem. The other half is getting information about where the player is in relation to each sprite and furthermore rotating each sprite independently.

BTW, i noticed you used twoSided in your material shader. Is there any particular reason for this given you'd never see the backside of a sprite?



The Happy Friar@Posted: Mon May 07, 2007 4:08 am :
Not sure why you want to use sprites for trees. Check out this shot. Those really really simple trees but I used spectrum lights to light them properly so they weren't all black (like yours. Here's the map).

Try using different blend techniques. With
Code:
    blend gl_one_minus_src_alpha, gl_src_alpha
for example, I get full bright & alpha channels.

you'll also notice sprites don't sort properly. that's a reason I don't really use them. So if you had several trees with that sprite it would look really really bad.



rich_is_bored@Posted: Mon May 07, 2007 5:07 am :
BTW, can someone verify my theory here. I think this would be valuable information for the wiki.



mikebart@Posted: Mon May 07, 2007 5:29 am :
@the happy friar; im not sure what spectrum lights are but I did try a shader simalar to that with a previous tree model, it did the trick but yeah, it also wouldnt sort properly or react to light, I ended up just creating a 6-tri cluster model (3 planes facing at each axis) for the foliage using the same material but removed the 'deform sprite' def and I personally think it looks ok possibly even better than it would have if i'd used sprites.

Heres the shader that goes with the image I posted of the fly;

Code:
textures/decals/junebug
{
    noSelfShadow
    noshadows
    nonsolid
    twosided

    qer_editorimage textures/decals/junebug.tga

        {       
           blend    diffusemap
     map    textures/decals/junebug.tga
     scale  bugwings[ time *10 ],1
     alphaTest 0.5
    }
    {       
           blend    bumpmap   
     map    textures/decals/junebug_local.tga
    }
    {       
           blend    specularmap
     map    textures/decals/junebug_s.tga
     scale  bugwings[ time *10 ],1
    }
    {       
           blend    add
     map    textures/decals/junebug_s.tga
     scale  bugwings[ time *10 ],1
       
    }
}


as you can see it has normal and spec.
Im suprised this question hasnt come up before, are alphatested sprites a common thing in games these days?

thx for pointing that out about the 2sided too :)



Tron@Posted: Mon May 07, 2007 6:35 am :
mikebart wrote:
@the happy friar; im not sure what spectrum lights are but I did try a shader simalar to that with a previous tree model, it did the trick but yeah, it also wouldnt sort properly or react to light,


Spectrum lights only affect materials which are set to that spectrum.

In this testmap of mine: http://www.mapsbytron.com/secret/16JAN07-02.jpg the foliage on the trees has a material set to only use lights on a seperate spectrum. This allows you to setup the lighting better for foliage so you don't get as much harsh contrast. The downside is that you don't get any shadows being cast off other objects.



mikebart@Posted: Mon May 07, 2007 9:28 am :
thanks tron, ill look into that.

Well, should we conclude that doom3 cant render an alphatested material as a sprite with spec and bump?



6th Venom@Posted: Mon May 07, 2007 10:56 am :
Did you just try to remove the twosided keyword?
Cause a deform sprite don't got to be twosided, cause it always point to the player.



mikebart@Posted: Mon May 07, 2007 12:11 pm :
It doesnt seem to matter, it still shows the black sprite.



mikebart@Posted: Tue May 08, 2007 1:33 am :
I just double checked about the fly, its definitly a sprite with bump and spec, should we conclude that this can only be done through a particle effect but not a material?, if so I guess thats how one would go about creating oblivion like trees.



The Happy Friar@Posted: Tue May 08, 2007 4:33 am :
the fly isn't a sprite to the material file. Just the particle file. So a particle would work for you since you cold tell it to always face the player & it would still handle normal material's w/o any problem.



LDAsh@Posted: Tue May 08, 2007 4:45 am :
It is possible to have alphatest autosprites even with specular, just no bumpmapping and no light interaction, which makes for some pretty crappy trees mostly, in my opinion. There's nothing to indicate the junebug material up there can have the "deform sprite" keyword, I'd bet it will turn fullblack like any other normalmapped light-friendly alphatest material the moment you try to make it happen, and from my experience shooting it from a particle emitter won't make any difference to how the material is rendered, but I'll give it a shot later to prove to myself.
Been a while since I last saw Oblivion but did that actually have autosprites in the trees? I don't think it had bumpmapped or light-friendly trees, I mean there was no reason for them to be bumpmapped anyway. Probably just texture baked to seem so. I've been working on a new technique for normalmapped foliage that avoids harsh seams or the need for strong/flat ambient light, and is completely light and fog friendly, but it's pretty weird and I haven't fully figured it all out yet:-
http://www.violationentertainment.com/images/g_sh/SH_ingame_070506a.jpg



mikebart@Posted: Thu May 10, 2007 11:22 am :
Oblivion does have sprites for the foliage, but I dont think they were normal mapped or spec mapped, I just used them as an example of a sprite being used for foliage.

Image

hey this scenes looking really nice btw, how did you do the foliage on the pines? could you tell me more about this new technique you're working on?



kat@Posted: Thu May 10, 2007 6:22 pm :
Trees in Oblivion have normal and specular maps. I'd suggest you don't use sprites for trees beacsue after a while the 'popping' that happens as the rotate and intersect each gets rather noticable (and annoying).



mikebart@Posted: Fri May 11, 2007 12:16 am :
Did they have normal and spec on the sprites?, I agree about the sprites 'popping' issue, I had them set up in 3dsmax to always face a camera. I had to keep them quite small, so that they would be less noticable, in the end after failing to get them working the way I wanted them to in quake4 as sprites I ended up making a 6-tri cluster model (3 planes facing at each axis) for the foliage and ended up saving a few tris, and like you say it looks alot better too