Simple shader confusion


(VolumetricSteve) #1

To distract myself, I’m working on a small map, something I was sure would be a simple one day job, but I’ve run into an issue I have no idea how to approach. I just wanted to take quake 3’s concrete floor texture and take some, maybe all of the color out of the main texture. Step one to this, I have to look at the contents of “base_floor/concretefloor1” in the base_floor.shader

I found this:

textures/base_floor/concretefloor1
{

{
	map textures/base_wall/chrome_env.tga
	tcgen environment
	rgbgen wave sin .25 0 0 0
}


{
	map textures/base_floor/concretefloor1.tga
	blendFunc GL_ZERO GL_SRC_ALPHA
	tcmod scale .1 .1
	rgbgen identity	
}

{
	map textures/base_floor/concretefloor1.tga
	blendFunc GL_ONE GL_SRC_ALPHA
	tcmod turb sin .5 1 0 1
	rgbgen identity	
}


{
	map $lightmap
    	blendfunc gl_dst_color gl_zero
	rgbgen identity 
}

}

The problem I’m having is the shader only seems to reference the special effects of the concrete texture, not the actual concrete.jpg itself. I see that quake 3 has a concrete that’s clearly the one used in the game, and I’m sure it’s the base that all of these extra rendering passes are applied to…but…how can the shader, which is known to be good, use a texture it doesn’t reference? I’m not just…missing it, right? There’s no mention of concrete.jpg in there, right? I see there’s a ‘concretefloor1.tga’ referenced, but this is the part of the shader that gives the shader it’s shimmer effect, not the underlaying concrete texture.

I was hoping I could simply copy this shader, use all the same code, and just desaturate the concrete.jpg a little for dramatic effect, and let quake 3 do its thing, but I can’t do that if what I copy doesn’t reference the thing I’m going to be desaturating, right? How…is that shader possible? What I have up there is code DIRECTLY from quake 3’s shader file (which I assume is now GNU along with the rest of it, so it’s hopefully ok to post that code up here in an unedited form)

Also, I see the shaders tend to point to files ending in .tga, where there generally aren’t .tga files, but there are .jpg files by the same name which I believe are what appear in-game, regardless of not being specified fully. Does quake 3 automatically look for a jpg if it can’t find a tga by the same name?

Thanks, sorry I’m like the only person keeping this forum alive, but hopefully other people will find these threads useful sooner or later.

*** Edit

Looking through the shader manual while reviewing Id’s quake 3 shaders…
all of those lights in base_light that emit different colors…those colors never seem to be referenced or defined in the shaders. How on earth does quake 3 know what surface light color to emit if it’s not coded into the shaders? Just…What? What did they do?


(obsidian) #2

Does quake 3 automatically look for a jpg if it can’t find a tga by the same name?

Yes, exactly this. In general, shaders should always point to a .tga regardless of whether the image is actually a .tga or .jpg (let the engine automatically find the right extension).

Surface light colours are potentially sampled from a variety of different sources, depending on which source takes priority over the other. In ascending order:

-average pixel colour of texture map (map)
-average pixel colour of editor image (qer_editorImage)
-average pixel colour of light image (q3map_lightImage)
-explicitly set RGB values (q3map_lightRGB)

So if both q3map_lightRGB and an editor image is set, the q3map_lightRGB value is used since it has a higher priority.


(VolumetricSteve) #3

how on earth do you always have the answers…to everything? Thanks a million, you’re spot on, as usual.

Is the syntax for q3map_lightRGB something like

q3map_lightRGB 1 0 0 for an all red map
0 1 0 for an all green map
0 0 1 for an all blue map

used, I imagine in the primary brackets of the shader…like

shader dir/shader name
{
normal shader stuff
q3map_lightRGB 1 0 0
{
shader pass
}
}

Thanks again


(obsidian) #4

Psudo-shader looks about right.

I know most of this stuff because I was around when they were created, and helped with feature testing, suggestions and implementation. I also wrote the manual.


(VolumetricSteve) #5

I thought I saw your name come up a few times when I was frantically downloading every quake 3 engine related thing I could get my hands on a few weekends ago. That’s quit a credential, lemme throw you a curve ball. What’s the computational difference between -light and -light -fast?

I read that -fast puts the lights into envelopes ordered by …complexity I think it was. Just sorting data by complexity shouldn’t make it faster, all of the data is still being computed, it’s just being computed with the tough stuff up front. And technically speaking, what is an envelope?

I’m trying to envision what q3map2 does with RAM in terms of lightmapping. I also found that the bsp switch, “samplesize” allows for a higher resolution lightmap without the modification of any shaders or game code. However, using this switch total ruins the speed of a compile. If the default samplesize is 16, and I set it to 14 to achieve a slighter sharper lightmap, my compile times are drastically longer, even with just a small difference. What is q3map2 doing so much more of that, in one test of mine, made the compile take 10 times longer?

Thanks, looking back through these threads, every answer you’ve given me has in someway impacted how I make maps, I wouldn’t have been able to do half of my maps if it hadn’t been for this forum.


(obsidian) #6

I believe -fast culls light traces after a certain distance and intensity. It does make lights slightly dimmer which is usually easy to compensate for, but the quality difference is pretty negligible so the tradeoff is in your favour. Someone made a map of the inside of a church (forgot who, rgoer?) without any textures (lightmap only) that was illuminated only by radiosity. No fill or ambient lights, only “natural” light from a few small windows. That was one of the extreme cases where -fast significantly decreased light quality.

I’m not sure what is meant by envelope without context.

Lightmaps are textures. Lightmap pixels (luxels) cover your surfaces at a default of 1 luxel per 2x2 grid units. -samplesize usually takes power of 2 values (32, 16, 8, 4, etc.). It scales the lightmap resolution on the entire map, so you can easily increase (or reduce) the total lightmap data by a power of 2. If you have other switches like -bounce 8 or something and you can see why it can increase compile times significantly. Being a switch, -samplesize is global, so I would prefer to increase lightmap resolution on a more localized manner using shaders or entity key/values for compile time, bsp size and in-game performance optimization.


(VolumetricSteve) #7

I saw the term envelopes used here:

http://shaderlab.com/q3map2/manual/

more precisely:

“fast
This enables light envelopes for area lights, and enables light culling. With some maps, using it could speed up light calculations by 50x or more. For maps with large numbers of dim surface lights, it also has the side effect of producing dimmer maps, so you’ll need to tweak your lighting. Fast makes for great final compiles though, as long as you light accordingly. To disable light culling, and at the same time disable compile time speed increases, don’t put fast in your command line.”

The use of the term envelopes there confused me.

also, this is totally off the wall, but if I wanted to fill a level with a snow effect, how could I best go about doing that in vanilla quake 3? I saw raven did some things with snow, but I’m not sure how to import those back to quake 3, if it’d require a mod, an engine mod, or what. any ideas? Thanks again.


(obsidian) #8

Definition: Something that envelops; a wrapping. So in this case, a “wrapper” for light limiting its maximum distance. It’s just another way of saying what I said above about light culling.

Raven (and other games) have hard-coded environmental/particle controls which vanilla Q3 lacks. You can still do it with some shaders, just requires a bit more work. Check this out:
http://www.quake3world.com/forum/viewtopic.php?t=37893