refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package chess.view.DDDrender.shader;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import chess.view.DDDrender.Camera;
|
||||
|
||||
public class BoardShader extends ShaderProgram {
|
||||
|
||||
@@ -10,14 +10,15 @@ public class BoardShader extends ShaderProgram {
|
||||
layout(location = 0) in vec3 position;
|
||||
layout(location = 1) in vec3 color;
|
||||
|
||||
uniform mat4 camMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform vec3 lightPosition;
|
||||
|
||||
flat out vec3 pass_color;
|
||||
out vec3 toLightVector;
|
||||
|
||||
void main(void){
|
||||
gl_Position = camMatrix * vec4(position, 1.0);
|
||||
gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.0);
|
||||
|
||||
toLightVector = lightPosition - position;
|
||||
|
||||
@@ -61,7 +62,8 @@ public class BoardShader extends ShaderProgram {
|
||||
|
||||
""";
|
||||
|
||||
private int location_CamMatrix = 0;
|
||||
private int location_ProjectionMatrix = 0;
|
||||
private int location_ViewMatrix = 0;
|
||||
|
||||
public BoardShader() {
|
||||
|
||||
@@ -73,10 +75,12 @@ public class BoardShader extends ShaderProgram {
|
||||
|
||||
@Override
|
||||
protected void GetAllUniformLocation() {
|
||||
location_CamMatrix = GetUniformLocation("camMatrix");
|
||||
location_ProjectionMatrix = GetUniformLocation("projectionMatrix");
|
||||
location_ViewMatrix = GetUniformLocation("viewMatrix");
|
||||
}
|
||||
|
||||
public void SetCamMatrix(Matrix4f mat) {
|
||||
LoadMat4(location_CamMatrix, mat);
|
||||
public void SetCamMatrix(Camera camera) {
|
||||
LoadMat4(location_ProjectionMatrix, camera.getPerspectiveMatrix());
|
||||
LoadMat4(location_ViewMatrix, camera.getViewMatrix());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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