dev #12

Merged
Persson-dev merged 44 commits from dev into main 2025-05-17 15:05:24 +00:00
21 changed files with 102 additions and 18 deletions
Showing only changes of commit 7af9807127 - Show all commits

1
.gitattributes vendored
View File

@@ -6,3 +6,4 @@
# These are Windows script files and should use crlf
*.bat text eol=crlf
*.glb filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text

View File

@@ -16,5 +16,6 @@ public class OpenGLMain {
commandExecutor.executeCommand(new NewGameCommand());
ddd.run();
commandExecutor.close();
}
}

View File

@@ -16,7 +16,7 @@ public class Camera {
private float pitch = 0.0f;
public Camera() {
this.pos = new Vector3f(2, 2.0f, 0);
this.pos = new Vector3f(1.5f, 1.5f, 0);
setRotation(0.0f, -3.14150f / 2.0f);
}

View File

@@ -6,15 +6,7 @@ import chess.model.Coordinate;
class DDDPlacement {
static public Vector2f coordinates_to_vector(Coordinate coo) {
// float newX = switch (x) {
// case 0 -> -1 + 0.125f;
// case 1 -> -1 + 0.375f;
// case 2 -> -1 + 0.625f;
// case 3 -> -1 + 0.875f;
// default -> 0;
// };
return new Vector2f(-1.0f + 0.125f + coo.getX() * 0.250f, -1.0f + 0.125f + coo.getY() * 0.250f);
return new Vector2f(1.0f - 0.125f - coo.getX() * 0.250f, 1.0f - 0.125f - coo.getY() * 0.250f);
}
}

View File

@@ -124,10 +124,13 @@ public class ModelLoader {
AIScene scene = Assimp.aiImportFileFromMemory(
data,
Assimp.aiProcess_Triangulate | Assimp.aiProcess_PreTransformVertices |
Assimp.aiProcess_ValidateDataStructure,
Assimp.aiProcess_Triangulate | Assimp.aiProcess_PreTransformVertices | Assimp.aiProcess_GlobalScale
| Assimp.aiProcess_ValidateDataStructure,
"");
if (scene == null)
System.err.println(Assimp.aiGetErrorString());
List<VertexArray> vertecies = new ArrayList<>();
processNode(scene.mRootNode(), scene, vertecies);

View File

@@ -22,7 +22,8 @@ public class PieceModel implements PieceVisitor<String> {
public DDDModel getModel(Piece piece) throws IOException {
if (piece == null)
return null;
String path = basePath + colorToString(piece.getColor()) + "-" + visit(piece) + ".glb";
String path = basePath + colorToString(piece.getColor()) + "-" + visit(piece) + ".fbx";
return getModel(path);
}
@@ -47,7 +48,7 @@ public class PieceModel implements PieceVisitor<String> {
@Override
public String visitPiece(King king) {
return "knight";
return "king";
}
@Override

View File

@@ -80,7 +80,7 @@ public class Renderer {
for (int i = 0; i < BOARD_WIDTH; i++) {
for (int j = 0; j < BOARD_HEIGHT; j++) {
Vector3f color;
if ((i + j) % 2 != 0) {
if ((i + j) % 2 == 0) {
color = new Vector3f(1.0f, 1.0f, 1.0f);
} else {
color = new Vector3f(0.0f, 0.0f, 0.0f);

View File

@@ -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;

View File

@@ -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;
}
""";

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.