Texture from Shader question (yes, again... :( )


(Flippy) #1

Hi,

I need to ask a very similar question to what I asked about 2 weeks ago, but this time I hope I have a better understanding…

I need my PK3 Creator to find texture images (jpg or tga files) belonging to a shader definition which I can extract from the BSP file.

With shader definition, I mean the ‘shader name’ as it is declared in a shader file.

For example, the following shader will have textures/egypt_trim_sd/ctrim_c01 as shader definition name.

textures/egypt_trim_sd/ctrim_c01
{
	surfaceparm woodsteps
	implicitMap -
}

The above I will also call a shader (one shader is thus a shader definition name, including all the code between the two following { and } characters.

This is different from a shader file which can host several shaders.
For example, the following is the contents of a shader file, containing three shaders:

textures/egypt_trim_sd/ctrim_c01
{
	surfaceparm woodsteps
	implicitMap -
}

textures/egypt_trim_sd/ctrim_c03
{
	surfaceparm woodsteps
	implicitMap -
}

textures/egypt_trim_sd/trim_c14
{
	surfaceparm woodsteps
	implicitMap -
}

I hope my terminology is correct, and if not at least understandable?

Now, I am just going to ask if the following (the bold statements in particular) is correct.

  1. If a shader contains the string “implicitMap -” (such as all the three shaders in above shader file), the texture image filename MUST be given by it’s shader definition name, with a “.tga” or “.jpg” extension, because it is an implicit shader.
    It is not possible that the texture image filename does not exist. If the filename does not exist, the texture is simply missing.

So, there are three texture images belonging to the three shaders in the above example, namely:

  • textures/egypt_trim_sd/ctrim_c01.tga / .jpg
  • textures/egypt_trim_sd/ctrim_c03.tga / .jpg
  • textures/egypt_trim_sd/trim_c14.tga / .jpg
  1. If a shader does NOT contain “implicitMap -”, it is an explicit shader. If a shader is an explicit shader, there are three more possibilities:

2.1. The shader contains one or more texture maps, for example the following shader:

textures/metals_sd/grate_b
{
	qer_editorimage textures/metals_sd/grate_b.tga
	surfaceparm alphashadow
	surfaceparm metalsteps
	nomipmaps
	nopicmip
	cull disable
	{
		map textures/metals_sd/grate_b.tga
		alphaFunc GE128
		depthWrite
		rgbGen vertex
    }
}

This contains the texture map textures/metals_sd/grate_b.tga.
The texture map(s) must be supplied in your PK3 file.

2.2. The explicit shader contains one or more implicitMaps. For example:

textures/props/base_lamp_1
{
	qer_editorimage textures/props/base_lamp.tga
        surfaceparm nomarks
        surfaceparm pointlight
 	surfaceparm nolightmap

	implicitMap textures/props/base_lamp.tga
}

The implicitMap texture image(s) MUST be supplied in your PK3.

2.3. The explicit shader does not have a texture map --> The shader does not require any texture image.
Example:

textures/common/clip
{
	qer_trans 0.3
	surfaceparm nodraw
	surfaceparm nomarks
	surfaceparm nonsolid
	surfaceparm playerclip
	surfaceparm trans
}

Finally, if a shader is an explicit shader (it abides by rule 2.1, 2.2 or 2.3) then the texture image .tga CAN NOT or MAY NOT exist. except if the shader definition name happens to be the same as the texture map filename.

I would really love it if someone can tell me if all these statements (the bold ones in particular) are correct, and if they are not please tell me why not, preferably with a counter-example.

This would really help me with PK3 Creator v0.2…!!

Thanks!

EDIT

Then I have one more question left, what about q3map_lightimages?

The following shader for example:

textures/lights/light_c01
{
	qer_editorimage textures/lights/light_c01.tga
	q3map_lightimage textures/lights/light_c01.blend.tga
	q3map_surfacelight 5000
	surfaceparm nomarks
	{
		map $lightmap
		rgbGen identity
	}
	{
		map textures/lights/light_c01.tga
		blendFunc GL_DST_COLOR GL_ZERO
		rgbGen identity
	}
	{
		map textures/lights/light_c01.blend.tga
		blendFunc GL_ONE GL_ONE
	}
}

contains two texture maps that should be supplied in the PK3. I know the editorimage does not need to be in the PK3 because it is only used for the editor (I know, it’s the same file in this case, but that doesn’t need to be the case!). But what about the lightimage? Does that need to be in your pk3?


(Flippy) #2

If all the above is true, I can use the following ‘algorithm’ to correctly find all the texture images belonging to a shader definition name:

1. Find the shader file belonging to the shader definition
2. Extract the shader (between { and }) belonging to the shader definition

3. If the shader contains "implicitMap -" then -->
     3.1. The texture image is given by <shader definition>.tga or <shader definition>.jpg

4. Else    (shader does not contain implicitMap -)
     4.1. Find each texture map (starting with "map " and not "map $lightmap"). Each texture map is a texture image.
     4.2. Find each implicitMap. Each implicitMap is a texture image.

(ailmanki) #3

I think that is correct.

you might want to check those things:
http://pumpkin.game-server.cc/q3map2/shader_manual/contents.html

the name length, upper/lower case.

And dunno if you already do, but check if it does overwrite official files… or you could automove all to a custom namespace…


(Flippy) #4

Thanks.

I think I may have found one more case… If a shader definition cannot be found at all, it is automatically an implicit shader and thus the filename of the texture image is just the shader definition + the tga extension.

Correct?

I’m making good progress now on the Textures part… Although it’s still adding my Alpha mod textures for some reason… :tongue:

I am foreseeing some trouble when it comes to models though… I don’t know if I will be able to tell the difference between misc_gamemodels (should be in pk3) and misc_models (should not be in pk3)…

Oh well, one battle at a time!

EDIT
Well, textures work!

On to models…


(kamikazee) #5

I think your final assumption is badly stated; i.e. I think it is possible to have a texture and a shader with the same name. However, the game will most likely pick the shader and ignore the texture, hence it is not an issue.

Those q3map thingies are neither an issue, they are only read at compile time.

Finally, I thought there was also some rarely used implicitAlphaMap directive.


(Flippy) #6

[QUOTE=kamikazee;187769]I think your final assumption is badly stated; i.e. I think it is possible to have a texture and a shader with the same name. However, the game will most likely pick the shader and ignore the texture, hence it is not an issue.

Those q3map thingies are neither an issue, they are only read at compile time.

Finally, I thought there was also some rarely used implicitAlphaMap directive.[/QUOTE]

Alright, so if I have a shader:
(not sure if this is a valid shader, but just for the sake of example…)

textures/folder/shader1
{
   surfaceparm metalsteps
   {
       map textures/folder/my_shader_image.tga
   }
}

Then it is possible that textures/folder/shader1.tga is also a texture that could also be in use. But your assumption is that the game will discard the texture and use the shader instead?
I will test if that is true, but I think you are probably right.
If we are wrong here that is an issue because right now I am discarding any ‘texture/folder/shader1.tga’ images because there is no “implicitMap -” command.

I have never seen implicitAlphaMap, and Google does not bring anything up either. Now you mention it however, I think I did see an implicitMask (not Map) command? I’ll see if I can find it.


(kamikazee) #7

[QUOTE=Flippy;187770]I have never seen implicitAlphaMap, and Google does not bring anything up either. Now you mention it however, I think I did see an implicitMask (not Map) command? I’ll see if I can find it.[/QUOTE]Oops, you are right. Take a look at alpha.shader (which can be found online at https://zerowing.idsoftware.com/svn/radiant.gamepacks/ETPack/trunk/scripts/alpha.shader ) and you’ll notice that it has implicitMask and implicitBlend.


(Flippy) #8

Yep, that’s the one… So I need to check for implicitMask too, that’s not too much trouble.

What does implicitBlend do? I can only find empty implicitBlend commands “implicitBlend -”, none with a texture… But I suppose I’d better check for them too huh :tongue:


(kamikazee) #9

Their use seems to be explained in the Level Designers Reference: Implicitshaders. Silly of me that I didn’t think of that earlier on.


(Flippy) #10

It is probably my FireFox, but I can’t seem to visit any links you gave me so far :frowning:
I need to add a Security Certificate Exception or something, and when I do I just get to see the HTML code, not the actual page… Pretty annoying to read ^^

I did find it in another LDR link though, thanks.


(Flippy) #11

I have discovered one (only one so far, seems to be a mistake maybe?) case where the implicit map texture path did not have an extension:

textures/egypt_floor_sd/sandy_dirt_02
{
	qer_editorimage textures/egypt_floor_sd/sandy_dirt_01.tga
	q3map_nonplanar
	q3map_shadeangle 100
	surfaceparm gravelsteps
	implicitMap textures/egypt_floor_sd/sandy_dirt_01
}

Does this mean perhaps tell the engine to use the sandy_dirt_01 shader as a implicitMap (that doesn’t make sense does it? :rolleyes:), because that shader is defined just above it:

textures/egypt_floor_sd/sandy_dirt_01
{
	q3map_nonplanar
	q3map_shadeangle 100
	surfaceparm landmine
	surfaceparm gravelsteps
	implicitMap -
}

textures/egypt_floor_sd/sandy_dirt_02
{
	qer_editorimage textures/egypt_floor_sd/sandy_dirt_01.tga
	q3map_nonplanar
	q3map_shadeangle 100
	surfaceparm gravelsteps
	implicitMap textures/egypt_floor_sd/sandy_dirt_01
}

In my application I decided just to append a tga or jpg extension (depending on which file exists) if the texture map doesn’t have an extension… Didn’t encounter any issues with that so far but one can never be careful enough…


(TomTom7777) #12

Am I missing something in this discussion or are animMap animated shaders missing from your search algorithm? E.g. textures/sfx/flame1.tga etc (and sprites/… gfx/… models/…)

(BTW great work this! keep it up!)


(Flippy) #13

[QUOTE=TomTom7777;187785]Am I missing something in this discussion or are animMap animated shaders missing from your search algorithm? E.g. textures/sfx/flame1.tga etc (and sprites/… gfx/… models/…)

(BTW great work this! keep it up!)[/QUOTE]

Yep, you’re right, I should add those. Thanks for notifying me.

And what about sprites / gfx / models?

You can add models in the Models category, and you can add sprites or gfx images or any other files in the Misc Files category. I don’t see a large need for separate categories for these files at the moment but I might add them later.


(ailmanki) #14

http://bunker5.aaxxss.com/jaymod/Level%20Designers%20Reference.7z
(will remove it soon…)

basically just use wget :stuck_out_tongue:
http://www.gnu.org/software/wget/manual/wget.htm

 wget --no-check-certificate -mirror  --no-parent "https://zerowing.idsoftware.com/svn/radiant.gamepacks/ETPack/trunk/docs/Level%20Designers%20Reference"