Foliage problem


(FrostyChilli) #1

Hello!

I have a problem that my foliage is too bright:


This is my foliage model shader, which is done by a tutorial:

models/mapobjects/plants_sd/grass_green1 //name of the texture
{
    surfaceparm trans //The texture will be transparant.
    surfaceparm pointlight //This will cast shadows on your terrain.

    cull disable //The texture will be visible from both front and backsides.

    distanceCull 2048 5096 0.5 //(256) Distance between the player and the model before scaling down, (1536) Distance to not be drawn anymore (scale = 0), (0,5) Fluency (0,5 = most fluency).

    {
	map models/mapobjects/plants_sd/grass_green1.tga //path to the texture
	alphaFunc GE128 //Every pixel equal to and greater than 128 in the alpha-channel will be visible
	rgbGen exactVertex
	alphaGen vertex
    }
}

And this is where I add my foliage to a texture:

textures/mygrass/grass_2
{

	qer_editorimage textures/temperate_sd/master_grass_dirt3.tga
	implicit textures/temperate_sd/master_grass_dirt3.tga

	q3map_foliage models/mapobjects/plants_sd/grass_low.md3 .6 90 .5 .5 //scale, distance between the models, percent filled (decrease for less foliage), 2(unknown variable, for now use 2)
	surfaceparm grasssteps
	surfaceparm landmine
}

This bright effect is not affected by compile method or ambient light. Is there an easy way to change the lighting of the model or should I just make the texture darker(though it is using a vanilla texture(like in Radar map)).


(stealth6) #2

Try this for the model shader:


models/mapobjects/plants_sd/grass_green1 //name of the texture
{
    surfaceparm trans //The texture will be transparant.
    surfaceparm pointlight //This will cast shadows on your terrain.

    cull disable //The texture will be visible from both front and backsides.

    distanceCull 2048 5096 0.5 //(256) Distance between the player and the model before scaling down, (1536) Distance to not be drawn anymore (scale = 0), (0,5) Fluency (0,5 = most fluency).

    {
	map models/mapobjects/plants_sd/grass_green1.tga //path to the texture
	alphaFunc GE128 //Every pixel equal to and greater than 128 in the alpha-channel will be visible
	rgbGen exactVertex
	alphaGen vertex
    }
    {
        map $lightmap
        blendFunc filter
    }
}


(FrostyChilli) #3

These are the results. Same in lit areas. Weird in dark. I use Fuel Dump’s sky shader as a sky material.







(ailmanki) #4

Try the foliage example map from here:
http://www.magics-territory.com/files/wet/prefabs/prefabs.html


(stealth6) #5

After some googlefu, the only thing that’s definitely missing is rgbGen identity in the lightmap stage:


models/mapobjects/plants_sd/grass_green1 //name of the texture
{
    surfaceparm trans //The texture will be transparant.
    surfaceparm pointlight //This will cast shadows on your terrain.

    cull disable //The texture will be visible from both front and backsides.

    distanceCull 2048 5096 0.5 //(256) Distance between the player and the model before scaling down, (1536) Distance to not be drawn anymore (scale = 0), (0,5) Fluency (0,5 = most fluency).

    {
	map models/mapobjects/plants_sd/grass_green1.tga //path to the texture
	alphaFunc GE128 //Every pixel equal to and greater than 128 in the alpha-channel will be visible
	rgbGen exactVertex
	alphaGen vertex
    }
    {
        map $lightmap
        rgbGen identity
        blendFunc filter
    }
}


(Mateos) #6

A lightmap stage for it?


(Tardis) #7

[QUOTE=ailmanki;512990]Try the foliage example map from here:
http://www.magics-territory.com/files/wet/prefabs/prefabs.html[/QUOTE]

look at the foliage example Created by Rayban - also look at radar and you can look at transmitter_spring as well.


(twt_thunder) #8

this is radars shader if it is to any help:

textures/radar/lmterrain2_base
{
	q3map_normalimage textures/sd_bumpmaps/normalmap_terrain.tga
	
	q3map_lightmapsize 512 512
	q3map_lightmapMergable
	q3map_lightmapaxis z
	
	q3map_tcGen ivector ( 512 0 0 ) ( 0 512 0 )
	q3map_tcMod scale 2 2
	q3map_tcMod rotate 37
	
	surfaceparm grasssteps
	surfaceparm landmine	
}

textures/radar/lmterrain2_foliage_base
{
	q3map_baseShader textures/radar/lmterrain2_base

	q3map_foliage models/foliage/grassfoliage1.md3 1.25 48 0.1 2
	q3map_foliage models/foliage/grassfoliage2.md3 1.1 48 0.1 2
	q3map_foliage models/foliage/grassfoliage3.md3 1 48 0.1 2
}

textures/radar/lmterrain2_foliage_fade
{
	q3map_baseShader textures/radar/lmterrain2_base

	q3map_foliage models/foliage/grassfoliage1.md3 1.25 64 0.1 2
	q3map_foliage models/foliage/grassfoliage2.md3 1.1 64 0.1 2
	q3map_foliage models/foliage/grassfoliage3.md3 1 64 0.1 2
}



(stealth6) #9

To provide some more actual explanation instead of check out this shader vs this other shader :smiley:

In the model shader you posted you were missing the lightmap stage so the texture was not affected by light. I added a lightmap stage in the shader I posted, but I made a mistake somewhere since it didn’t take the alpha layer into account.


(FrostyChilli) #10

@stealth6. Well now if I look at my pictures again then it really seems as if alpha has not been calculated correctly. However, how do you explain these models, which are in the lighted area but are still not lit correctly?


(Mateos) #11

Experience with shaders. I remember experiencing this, but can’t try myself, no time; You seem to have some :slight_smile:
http://q3map2.robotrenegade.com/docs/shader_manual/contents.html


(stealth6) #12

Are you talking about the 2nd screenshot?

I don’t see an irregularity. On the left the ground texture is dark and the grass models are dark, on the right the ground texture is light and the grass is light. There is 1 triangular brush in the middle that seems to be slightly darker than the surrounding brushes and this causes the darker grass models. Maybe this can be improved with phong shading


(Mateos) #13

You don’t see the alpha part of the model being black while still transparent?


(FrostyChilli) #14

@Mateos I didn’t quite understand your question.

@stealth6 Well, yes, but compared to Radar grass texture, this is too bright. Plus my ambient light is quite low(6) in these pictures. They are too lit up. Too bright. Does it mean if I want this grass to be darker I need to either change the ground texture, darken grass texture(model) or add a darker skybox? I was wondering if there is a quick way to change lighting on a model(foliage) through shaders.


(stealth6) #15

lol, yea I see that. As i said previously I’m not sure why it’s working like that. The lightmap is being applied to the texture without taking the alpha layer into account.

When I google similar shaders (shader with transparency & lightmap), then the only thing I see missing from my suggested shader is rgbGen identity. But rgbGen identity is the default so that’s why I didn’t mention is in my first shader.

If that doesn’t work maybe try adding alphaFunc GE128 to the lightmap layer?

I think it’s definitely something blendFunc, rgbGen or alphaFunc related.

Probably possible by messing with the rgbGen value, but I don’t have any experience with it & models.
Maybe try rgbGen vertex instead of rgbGen exactVertex

According to the link Mateos posted earlier: http://q3map2.robotrenegade.com/docs/shader_manual/stage-directives.html#rgbGen exactVertex is brighter.


(FrostyChilli) #16

@thunder_13th I tried looking up radar shaders as well but I don’t understand how they work. There are 3 different shaders that are somehow connected to 1 texture? Is that right? Oh and new Transmitter spring edition map has a lots of shaders too for foliage. I wonder if same kind of system is used there also.


(twt_thunder) #17

I guess it is

here is one of mine from safe_spot map:

textures/safe_spot/terrain_1to2
{
	q3map_lightmapsamplesize 64
	q3map_lightmapaxis z
	q3map_texturesize 256 256
	q3map_tcGen ivector ( 252 0 0 ) ( 0 252 0 )
	q3map_foliage models/foliage/grassfoliage3.md3 0.7 64 0.21 0
	surfaceparm grassteps
	surfaceparm landmines
	{
		map textures/etnam/dirt4.jpg
	}
	{
		map textures/etnam/grass_dirt4.tga
		alphaGen vertex
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		tcGen lightmap
	}
}

try to modify it to yours


(Mateos) #18

Is this OK or still something to improve?

Edit: Too bright I guess


(Tardis) #19

Well I know there is no light stage on this shader just the same as rayban’s foliage and radar …
I try to explain .

The base shader is the MAIN terrain that is every were - when called

and then a base foliage and a fade foliage again only called when I use it on that terrain_0 e.t.c



textures/MAP_NAME/base
//MAIN BASE TERRAIN
 {
	q3map_nonplanar
	q3map_shadeangle 90
	q3map_lightmapaxis z
	q3map_lightmapMergable
	q3map_lightmapsize 512 512
	q3map_tcMod rotate 37
	q3map_tcGen ivector ( 256 0 0 ) ( 0 256 0 )
 }

textures/MAP_NAME/terrain_foliage_base
//FOLIAGE BASE
 {
	q3map_baseshader textures/MAP_NAME/base

	q3map_foliage models/foliage/grassfoliage1.md3 1.25 48 0.1 2
	q3map_foliage models/foliage/grassfoliage2.md3 1.1 48 0.1 2
	q3map_foliage models/foliage/grassfoliage3.md3 1 48 0.1 2
 }

textures/MAP_NAME/terrain_foliage_fade
//FOLIAGE FADE
 {
	 q3map_baseshader textures/MAP_NAME/base

	 q3map_foliage models/foliage/grassfoliage1.md3 1.25 64 0.1 2
	 q3map_foliage models/foliage/grassfoliage2.md3 1.1 64 0.1 2
	 q3map_foliage models/foliage/grassfoliage3.md3 1 64 0.1 2
 }

textures/MAP_NAME/terrain_0
 {
	 q3map_baseshader textures/MAP_NAME/base
	 q3map_baseshader textures/MAP_NAME/terrain_foliage_fade
	 qer_editorimage textures/editor_image/terrain0.tga		
	 surfaceparm grasssteps
	  surfaceparm landmine
	{
		 map textures/temperate_sd/grass_dense1.tga
 		rgbgen identity
 	}
  {
		 map textures/temperate_sd/master_grass_dirt3.tga
		alphaGen vertex
		 blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		rgbgen identity
  }
  {
		 map $lightmap
 		blendFunc GL_DST_COLOR GL_ZERO
		 rgbgen identity
  }
 }


so you can call for the foliage base or fade when you want on the terrain you want to call it on and have the main base called all the time .
I hope that helps .


(RayBan) #20

@FrostyChilli Are you looking for foliage shader’s like nexgen… then i can tell you they do not exist in this current engine… you can fake it… but it’s just fake in the end… your limited in et’s engine… like the rest of us…