Followers 0

Color attenuation problem on terrain

3 posts in this topic

My GLSL shader is not outputting the correct attenuation onto my terrain. My terrain is green(0.1,0.6,0.0), and I want the color of the terrain to go from dark green to bright green as the light gets closer to each on the terrain, as it should in attenuation.

When my terrain's color = {0.1, 0.6, 0.0}, I see a very rapid color change from green->yellow as pixels on the terrain get closer to the light, when it should be going green->bright green instead of yellow.

*light is located above the player's head(camera).

When my terrain's color = {0.0, 0.0, 0.0}, the terrain color is perfectly calculated with attenuation, no problems.

*light is located above the player's head(camera).

Question: I can't understand why the 0.1 in the RED color spot has so much impact when terrain pixels get closer to the light(ie: attenuation value gets closer to 1.0)?

Here's the basis of the final generation of color in my pixel shader:

varying vec4 color;

float constantAttenuationPlayer=0.0;
float linearAttenuationPlayer=0.0;

float dist = length(gl_LightSource[2].position - v);
float att = 1.0/(constantAttenuationPlayer + (linearAttenuationPlayer * dist) + (quadraticAttenuationPlayer * dist * dist));

gl_FragColor = color * att;

0

Share on other sites

Thank you for taking the time to respond so quickly.

I would like to propose a solution and have your feedback, or your solution if you have a better one.

I think I should prevent attenuation factor from being added if any value of 'color' is already at it's maximum(1):

In the pixel shader,

final_color=color*att; // no components have reached maximum

if (att factor>1 AND any component of 'color' is already at maximum){ then

final_color=color; // do nothing(instead of turning yellow)

}

EDIT*

My solution failed and creates a blob where yellow starts to get added. I definitely didn't think my solution through.

Edited by Shawn619
0

Share on other sites

Solved.

My final solution involved taking the highest attenuation value before any color component reaches 1.0(the point at which other RGB values may also reach, thus losing the 'green' ratio and turning into the yellow ratio(ie:1.0,1.0,z)), then taking that highest attenuation value and distributing across the entire zone at which I would have lost my green-ratio and turned yellow, if that makes sense.

Thanks!

0

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

Followers 0

• 14
• 12
• 23
• 11
• 28