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;
|
||||
|
||||
@@ -13,11 +13,20 @@ public class PieceShader extends ShaderProgram {
|
||||
|
||||
uniform mat4 camMatrix;
|
||||
uniform mat4 modelTransform;
|
||||
uniform vec3 lightPosition = vec3(0, 1, 0);
|
||||
|
||||
out vec3 toLightVector;
|
||||
out vec3 surfaceNormal;
|
||||
|
||||
flat out vec3 pass_color;
|
||||
|
||||
void main(void){
|
||||
gl_Position = camMatrix * modelTransform * vec4(position, 1.0);
|
||||
vec4 worldPos = modelTransform * vec4(position, 1.0);
|
||||
|
||||
toLightVector = lightPosition - worldPos.xyz;
|
||||
surfaceNormal = (modelTransform * vec4(normal, 0.0)).xyz;
|
||||
|
||||
gl_Position = camMatrix * worldPos;
|
||||
pass_color = position;
|
||||
}
|
||||
""";
|
||||
@@ -25,12 +34,24 @@ public class PieceShader extends ShaderProgram {
|
||||
private static String fragmentShader = """
|
||||
#version 330
|
||||
|
||||
in vec3 toLightVector;
|
||||
in vec3 surfaceNormal;
|
||||
|
||||
flat in vec3 pass_color;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
out_color = vec4(pass_color, 1.0);
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
vec3 unitLightVector = normalize(toLightVector);
|
||||
|
||||
float diffuse = max(0.5, dot(unitNormal, unitLightVector));
|
||||
|
||||
float brightness = diffuse;
|
||||
|
||||
out_color = vec4(pass_color, 1.0) * brightness;
|
||||
out_color.w = 1.0;
|
||||
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user