omg ça marche
This commit is contained in:
@@ -11,13 +11,19 @@ public class BoardShader extends ShaderProgram {
|
||||
layout(location = 1) in vec3 color;
|
||||
|
||||
uniform mat4 camMatrix;
|
||||
uniform vec3 lightPosition;
|
||||
|
||||
flat out vec3 pass_color;
|
||||
out vec3 toLightVector;
|
||||
|
||||
void main(void){
|
||||
gl_Position = camMatrix * vec4(position, 1.0);
|
||||
|
||||
toLightVector = lightPosition - position;
|
||||
|
||||
pass_color = color;
|
||||
}
|
||||
|
||||
""";
|
||||
|
||||
private static String fragmentShader = """
|
||||
@@ -25,11 +31,34 @@ public class BoardShader extends ShaderProgram {
|
||||
|
||||
flat in vec3 pass_color;
|
||||
|
||||
in vec3 toLightVector;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
out_color = vec4(pass_color, 1.0);
|
||||
const float shineDamper = 10.0;
|
||||
const float reflectivity = 1.0;
|
||||
|
||||
float lightDistance = length(toLightVector);
|
||||
|
||||
const vec3 attenuation = vec3(0.3, 0.03, 0);
|
||||
float attenuationFactor = attenuation.x + attenuation.y * lightDistance + attenuation.z * lightDistance * lightDistance;
|
||||
|
||||
vec3 unitNormal = vec3(0, 1, 0);
|
||||
vec3 unitLightVector = normalize(toLightVector);
|
||||
|
||||
vec3 lightDirection = -unitLightVector;
|
||||
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
|
||||
|
||||
float diffuse = max(0.2, dot(unitNormal, unitLightVector));
|
||||
|
||||
float brightness = diffuse / attenuationFactor;
|
||||
|
||||
out_color = brightness * vec4(pass_color, 1.0);
|
||||
out_color.w = 1.0;
|
||||
|
||||
}
|
||||
|
||||
""";
|
||||
|
||||
private int location_CamMatrix = 0;
|
||||
|
||||
Reference in New Issue
Block a user