Advertisement

questions on handling of colors (addition, multiplication)

Started by July 16, 2019 09:11 AM
4 comments, last by cebugdev 5 years, 6 months ago

hi,

this is related to lighting materials.

I dont know if this is basic or advance but i am still confuse until now why the materials for ambient, diffuse are added and

then multiplied by the colored sampled from the texture of the object.

whats the science/color theory behind it?

example in shaders (GLSL):

 


vec3 result = (ambient + diffuse) * objectColor; 
FragColor = vec4(result, 1.0);

 

why not add all of them or why are the materials added and the texture color multiplied to it?
sorry for being dummy on this area.

You can point me to any material to read, etc. to know what is the theory behind the color manipulation/handling above.

Hi.

The ambient light is just a 'fix' for not having enough computational power. Usually, light is reflected multiple times from multiple surfaces. In reality, if you have a single point light in a room (a light bulb for example), then you would still get some light that reaches areas which have no direct "line of sight" to the light source. Therefore, shadows are not just black areas. On the computer (if you are not using raytracing) you don't calculate multiple reflections since it is really expensive. You just compute the light that comes directly from the light source and reflects directly into the camera (diffuse light). In result, you get totally black shadows, which doesn't look realistic. So you add some kind of base lighting to the whole scene so that shadows aren't pitch black anymore. You basically approximate the light which would result from more than one reflection by a constant value.

You add them because you are calculating the total amount of light at a position. If you had multiple point lights, you would also add them up to get the total amount of light.

So what about the multiplication? Surfaces absorb and reflect certain wavelengths of the light. The colour we see is just the light which was reflected. So if a specific wavelength (or colour) is fully absorbed, its value needs to be zero. How do we achieve this? Just multiply by 0! On the other hand, if a colour is fully reflected, it needs to be multiplied by 1. if a colour is absorbed by 50%... just multiply by 0.5 per cent. I think you get the pattern here ;)

 

 

59 minutes ago, cebugdev said:

why are the materials added

 

You add the different light amounts, not the materials. You just need the reflectivity from the material inside of your diffuse light calculation to calculate the right amount of reflected light towards the camera.

In general, you calculate the light (colour) intensity that reaches a certain pixel of the camera and use it as the output of your fragment shader. It's like our eyes work. The colour you see is determined by the light that reaches each part of the retina. Therefore, you need to know how light is reflected depending on the angle (this happens in the diffuse calculation) and which wavelengths/colours are reflected (this is the multiplication with the colour).

 

Greetings

Advertisement
1 hour ago, cebugdev said:

whats the science/color theory behind it?

I assume it is the Phong model (and its derivatives).

In short ambient is a scalar that refers to "light that is present everywhere" while diffuse is a scalar of computed normal/light dot product lightning and shadow. Those can be combined differently to multiply the sampled texture color though.

Such as :

float component=max(ambient,diffuse);

vec3 result=component*objectColor;

 

21 hours ago, DerTroll said:

Hi.

The ambient light is just a 'fix' for not having enough computational power. Usually, light is reflected multiple times from multiple surfaces. In reality, if you have a single point light in a room (a light bulb for example), then you would still get some light that reaches areas which have no direct "line of sight" to the light source. Therefore, shadows are not just black areas. On the computer (if you are not using raytracing) you don't calculate multiple reflections since it is really expensive. You just compute the light that comes directly from the light source and reflects directly into the camera (diffuse light). In result, you get totally black shadows, which doesn't look realistic. So you add some kind of base lighting to the whole scene so that shadows aren't pitch black anymore. You basically approximate the light which would result from more than one reflection by a constant value.

You add them because you are calculating the total amount of light at a position. If you had multiple point lights, you would also add them up to get the total amount of light.

So what about the multiplication? Surfaces absorb and reflect certain wavelengths of the light. The colour we see is just the light which was reflected. So if a specific wavelength (or colour) is fully absorbed, its value needs to be zero. How do we achieve this? Just multiply by 0! On the other hand, if a colour is fully reflected, it needs to be multiplied by 1. if a colour is absorbed by 50%... just multiply by 0.5 per cent. I think you get the pattern here ;)

 

 

 

You add the different light amounts, not the materials. You just need the reflectivity from the material inside of your diffuse light calculation to calculate the right amount of reflected light towards the camera.

In general, you calculate the light (colour) intensity that reaches a certain pixel of the camera and use it as the output of your fragment shader. It's like our eyes work. The colour you see is determined by the light that reaches each part of the retina. Therefore, you need to know how light is reflected depending on the angle (this happens in the diffuse calculation) and which wavelengths/colours are reflected (this is the multiplication with the colour).

 

Greetings

this is why i post in here !! Thank you for your explanation, helps a lot

 

This topic is closed to new replies.

Advertisement