Jump to content

Shaders with lightmap and gradual transparency


Go to solution Solved by Szico VII,

Recommended Posts

After trying all I can think of and some more, I can't seem to simply fade in a decal I'm making, while keeping it lightmapped.

 

In-game what is showing up is the brightest area of the alpha channel, I think. It is at least a hard round border, instead of a faded one.

 

Shader:

 

textures/Bootland/terrain_decal1
{
	qer_editorimage textures/Bootland/terrain_decal1.tga
	surfaceparm	nonsolid
	{
	map textures/Bootland/terrain_decal1
	alphaFunc GT0
	depthWrite
	}
	{
	map $lightmap
	rgbGen identity
	blendFunc GL_DST_COLOR GL_ZERO
	depthFunc equal
	}
}

 

Decal: https://dl.dropboxusercontent.com/u/58757568/terrain_decal1.jpg

Alpha channel: https://dl.dropboxusercontent.com/u/58757568/alphachannel.jpg

 

In-game: https://dl.dropboxusercontent.com/u/58757568/shot0055.jpg (placed upon an irrelevant mud texture for clarity)

 

With blendFunc blend in the first stage: https://dl.dropboxusercontent.com/u/58757568/shot0056.jpg

 

with alphaFunc GE128: https://dl.dropboxusercontent.com/u/58757568/shot0057.jpg

 

How would I do this?

Link to comment

You want blendfunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA and no alphafunc.

 

Lightmapping it is difficult however, since you have to keep the transparent areas from being lit twice. Since I don't think you have access to the texture's alpha channel in the lightmap, I can only think of having a special nolightmap ground shader below the decal and doing the ordinary lightmap stage on the decal (or using just one shader to begin with, but you'll likely want to be able to change the texture coordinates separately).

Link to comment

What kind of nolightmap shader do you mean? (Special, as in one for every texture it lies upon?)

Would it defeat the purpose of having decals in the first place (opposed to making different versions of textures you already have, and gaining map size)?

 

If it's not either of these, couldn't it just be a stage in the shader to cancel out the transparent areas being lit twice? That said, I didn't quite understand what you meant by changing the texture coordinates seperately.

 

Either way, could you give an example? :D

Link to comment

It's somewhat hard to explain without going into detail on how exactly shaders work, and that would make for a pretty lengthy explanation. I should write a tutorial on that some day. But if you don't understand the rendering pipeline to some extend you really can't write shaders (well), just copy-paste them and hope for the best.

 

But yeah, the Quake 3 Engine does not really support decals very well due to how it works. If you want to layer textures on top of each other, you'd usually do that in a single shader. Since shader stages are applied in order, and the lightmap stage generally needs to be after the stages you want to light you can't render a decal on top of it and have it lit. At least I can't think of a way.

Link to comment

Yeah well, I understand them enough to never copy one without research. But some things seem very inconsistent when combining with other methods, thus creating a lot of experimentation even when it contradicts my sense of logic :D

 

But be sure to tell me if you make a tutorial, or if you have any other references I could use to make it. Or if it's easy to do but hard to explain, I could just observe instead if you have an example pk3 or so.

 

 

 

Either way, too bad it's so unsupported, as I had great ambitions with terrain blending and the likes. At least I can still make good use of decals with the all-or-nothing method.

Link to comment

Your best bet really is to fade the two textures together using alpha mods, because this eliminates need for an alpha channel and you can have your lightmaps.

 

http://www.simonoc.com/pages/articles/terrain1_2.htm

 

 

Wow, thanks for this one! It took me a (good!) while to crack this one, but now I've got it. I'll definitely use this for terrain blending. Thanks again!

 

I guess for simple decals (like on walls, or for variation in very small areas of terrain) it would be more expensive for the engine to do it this way, because of the extra segmentation required. Opposed to an extra texture. Or what do you think?

Link to comment

I encountered this problem a lot and when I finally solved it I was quite overjoyed. Szico may be right in this instance, however it's still good to know the fix, right? :D

 

 
textures/dotf/vines1
{
qer_editorimage textures/dotf/vines1
surfaceparm nomarks
surfaceparm trans
q3map_alphashadow
    {
        map textures/dotf/vines1
        alphaFunc GE128
        depthWrite // writes the alpha map for other stages to use
    }
    {
        map $lightmap
blendfunc GL_DST_COLOR GL_ZERO
depthFunc equal
// sets the alpha to the same as the stages that wrote it
    }
}
 
Note this only works with alphaFunc. Blendfunc blend is a no-go, it will look ugly no matter what (only in some cases though, depending on the lighting. It's wierd).
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...