1
Graphics / Re: GLSL Interpolate between 2 colours
« on: July 16, 2018, 04:20:02 pm »
Hi Laurent,
Thanks for pointing me towards the mix function, it was exactly what i was looking for to implement this functionality. I feel like i'm finally starting to pick up on some shader techniques Thanks a lot for your help.
Just in case it might help anyone, here's the shader i'm using for my day/night cycle.
Thanks for pointing me towards the mix function, it was exactly what i was looking for to implement this functionality. I feel like i'm finally starting to pick up on some shader techniques Thanks a lot for your help.
Just in case it might help anyone, here's the shader i'm using for my day/night cycle.
uniform sampler2D texture;
uniform sampler2D lightmap;
uniform vec4 nighttime;
uniform vec2 resolution;
uniform float theta;
uniform float ambientIntensity;
uniform vec3 daytime;
void main()
{
float timeOfDay = (0.5 * sin(theta) + 0.5);
vec4 diffuse = texture2D(texture, gl_TexCoord[0].xy);
vec2 lightcoord = (gl_FragCoord.xy / resolution.xy);
vec4 light = texture2D(lightmap, lightcoord);
//offset by 0.2 so ambientColour is never 0
vec3 ambientColour = mix(nighttime.rgb, daytime, timeOfDay + 0.2);
vec3 intensity = (ambientColour + (light.rgb * mix(ambientIntensity, 0, timeOfDay)));
vec3 result = diffuse.rgb * intensity;
gl_FragColor = vec4(result, diffuse.a);
}
uniform sampler2D lightmap;
uniform vec4 nighttime;
uniform vec2 resolution;
uniform float theta;
uniform float ambientIntensity;
uniform vec3 daytime;
void main()
{
float timeOfDay = (0.5 * sin(theta) + 0.5);
vec4 diffuse = texture2D(texture, gl_TexCoord[0].xy);
vec2 lightcoord = (gl_FragCoord.xy / resolution.xy);
vec4 light = texture2D(lightmap, lightcoord);
//offset by 0.2 so ambientColour is never 0
vec3 ambientColour = mix(nighttime.rgb, daytime, timeOfDay + 0.2);
vec3 intensity = (ambientColour + (light.rgb * mix(ambientIntensity, 0, timeOfDay)));
vec3 result = diffuse.rgb * intensity;
gl_FragColor = vec4(result, diffuse.a);
}