refactor
This commit is contained in:
@@ -3,6 +3,8 @@ package chess.view.DDDrender.shader;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import chess.view.DDDrender.Camera;
|
||||
|
||||
public class PieceShader extends ShaderProgram {
|
||||
|
||||
private static String vertexShader = """
|
||||
@@ -12,7 +14,8 @@ public class PieceShader extends ShaderProgram {
|
||||
layout(location = 1) in vec2 uv;
|
||||
layout(location = 2) in vec3 normal;
|
||||
|
||||
uniform mat4 camMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 modelTransform;
|
||||
uniform vec3 lightPosition = vec3(0, 1, 0);
|
||||
|
||||
@@ -25,7 +28,7 @@ public class PieceShader extends ShaderProgram {
|
||||
toLightVector = lightPosition - worldPos.xyz;
|
||||
surfaceNormal = (modelTransform * vec4(normal, 0.0)).xyz;
|
||||
|
||||
gl_Position = camMatrix * worldPos;
|
||||
gl_Position = projectionMatrix * viewMatrix * worldPos;
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -53,7 +56,8 @@ public class PieceShader extends ShaderProgram {
|
||||
}
|
||||
""";
|
||||
|
||||
private int location_CamMatrix = 0;
|
||||
private int location_ProjectionMatrix = 0;
|
||||
private int location_ViewMatrix = 0;
|
||||
private int location_ModelTransform = 0;
|
||||
private int location_ModelColor = 0;
|
||||
|
||||
@@ -67,13 +71,15 @@ public class PieceShader extends ShaderProgram {
|
||||
|
||||
@Override
|
||||
protected void GetAllUniformLocation() {
|
||||
location_CamMatrix = GetUniformLocation("camMatrix");
|
||||
location_ProjectionMatrix = GetUniformLocation("projectionMatrix");
|
||||
location_ViewMatrix = GetUniformLocation("viewMatrix");
|
||||
location_ModelTransform = GetUniformLocation("modelTransform");
|
||||
location_ModelColor = GetUniformLocation("modelColor");
|
||||
}
|
||||
|
||||
public void SetCamMatrix(Matrix4f mat) {
|
||||
LoadMat4(location_CamMatrix, mat);
|
||||
public void SetCamMatrix(Camera camera) {
|
||||
LoadMat4(location_ProjectionMatrix, camera.getPerspectiveMatrix());
|
||||
LoadMat4(location_ViewMatrix, camera.getViewMatrix());
|
||||
}
|
||||
|
||||
public void setModelTransform(Matrix4f mat) {
|
||||
|
||||
Reference in New Issue
Block a user