From cf647ebf504eb523d822fa79622cb59d009680da Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 13 Mar 2018 19:30:05 +0500 Subject: Implemented basic lighting --- cwd/shaders/face.fs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'cwd') diff --git a/cwd/shaders/face.fs b/cwd/shaders/face.fs index c4405d4..a4e020c 100644 --- a/cwd/shaders/face.fs +++ b/cwd/shaders/face.fs @@ -9,6 +9,7 @@ in VS_OUT { uniform sampler2D textureAtlas; uniform vec2 windowSize; +uniform float DayTime; vec3 rgb2hsv(vec3 c) { @@ -29,12 +30,19 @@ vec3 hsv2rgb(vec3 c) } void main() { - gl_FragColor = texture(textureAtlas,fs_in.Texture); - if (gl_FragColor.a < 0.3) + vec4 color = texture(textureAtlas,fs_in.Texture); + if (color.a < 0.3) discard; - vec3 hsvColor = rgb2hsv(gl_FragColor.xyz); + + vec3 hsvColor = rgb2hsv(color.xyz); hsvColor+=fs_in.Color; - gl_FragColor = vec4(hsv2rgb(hsvColor),1); - //float faceLight = clamp((fs_in.Light.x + fs_in.Light.y) / 15.0,0.2,1.0); - //gl_FragColor = vec4(gl_FragColor.rgb * faceLight,gl_FragColor.a); + color = vec4(hsv2rgb(hsvColor),1); + + float light = fs_in.Light.x / 15.0; + float skyLight = (fs_in.Light.y / 15.0) * DayTime; + + float faceLight = clamp(light + skyLight,0.2,1.0); + + color = vec4(color.rgb * faceLight, color.a); + gl_FragColor = color; } \ No newline at end of file -- cgit v1.2.3