mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-17 04:45:02 +01:00
Shamelessly stolen light code
This commit is contained in:
parent
d1df7cd472
commit
45af69faa0
2 changed files with 81 additions and 15 deletions
|
|
@ -1,16 +1,44 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float ambient;
|
||||
uniform vec2 resolution;
|
||||
uniform vec2 mouse;
|
||||
uniform float time;
|
||||
uniform bool has_texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
// lookup the pixel in the texture
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
// The RGB values are the ambient light color
|
||||
// and the alpha is the ambient intensity
|
||||
uniform vec4 ambientData;
|
||||
// The RGB values are the light color
|
||||
// and the alpha is the light intensity
|
||||
uniform vec4 lightData;
|
||||
// Maximum radius of the light
|
||||
uniform float lightSize;
|
||||
|
||||
// multiply it by the color
|
||||
vec4 col = gl_Color;
|
||||
if (has_texture) {
|
||||
col = gl_Color * pixel;
|
||||
}
|
||||
gl_FragColor = vec4(col.x * ambient, col.y * ambient, col.z * ambient, col.w);
|
||||
void main() {
|
||||
// Light's position
|
||||
vec2 position = mouse/resolution.xx;
|
||||
|
||||
// Makes the light change its size slightly to make a fire effect
|
||||
float maxDistance = lightSize + 0.015*sin(time);
|
||||
// Gets the distance from the light's position and the fragment coord
|
||||
float distance = distance(gl_FragCoord.xy/resolution.xx, position);
|
||||
// Calculates the amount of light for the fragment
|
||||
float value = 1.0 - smoothstep(-0.2, maxDistance, distance);
|
||||
|
||||
// Gets the original color from the texture
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
if (!has_texture) {
|
||||
pixel = gl_Color;
|
||||
}
|
||||
|
||||
// Applies the ambient light to the original pixel color
|
||||
vec3 ambient = pixel.rgb * ambientData.rgb * ambientData.a;
|
||||
|
||||
// Calculates the light color for the pixel
|
||||
vec3 light = lightData.rgb * lightData.a * clamp(value, 0.0, 1.0);
|
||||
|
||||
// Applies the light to the pixel
|
||||
vec3 intensity = ambient + light;
|
||||
vec3 final = pixel.rgb * intensity;
|
||||
|
||||
gl_FragColor = vec4(final, 1.0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue