Skip to content

Commit 305f397

Browse files
committed
Models render scuffed right now but they render.
1 parent 4dd526b commit 305f397

File tree

17 files changed

+316
-349
lines changed

17 files changed

+316
-349
lines changed

settings.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/library/java/gg/generations/rarecandy/pokeutils/MaterialReference.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ public static Material process(MaterialReference reference, List<String> imageNa
7575

7676
var effectRef = reference.effect;
7777

78+
7879
var effect = switch (reference.effect) {
7980
case "galaxy" -> 1;
8081
case "pastel" -> 2;
8182
case "shadow" -> 3;
8283
case "sketch" -> 4;
8384
case "vintage" -> 5;
84-
default -> 0;
85-
};
85+
case null, default -> 0;
86+
};
8687

8788
return new Material(
8889
images,

src/library/java/gg/generations/rarecandy/renderer/components/MultiRenderObject.java

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
*
3232
*/
33-
public class MultiRenderObject {
33+
public abstract class MultiRenderObject {
3434
public Map<String, Integer> meshNameToId;
3535
public Map<String, Integer> materialNameToId;
3636
public Map<String, Integer> variantNameToId;
@@ -115,35 +115,7 @@ public Material getMaterial(int mesh, int variant) {
115115
return materials[getVariant(mesh,variant).material()];
116116
}
117117

118-
public void render(TraditionalPipeline pipeline, RenderStage stage, List<ObjectInstance> instances) {
119-
for (var instance : instances) {
120-
121-
pipeline.bindInstance(instance, this);
122-
123-
for (int mesh = 0; mesh < meshes.length; mesh++) {
124-
if (shouldRender(mesh, instance)) {
125-
var model = this.meshes[mesh];
126-
127-
if (model == null) {
128-
continue;
129-
}
130-
131-
pipeline.bindDraw(instance, this, mesh);
132-
133-
var material = getMaterial(mesh, instance.variant());
134-
pipeline.preDraw(material);
135-
var transparent = material.blendType() != BlendType.None;
136-
137-
if (transparent && stage == RenderStage.TRANSPARENT || stage == RenderStage.SOLID) {
138-
model.render();
139-
}
140-
141-
pipeline.postDraw(material);
142-
}
143-
144-
}
145-
}
146-
}
118+
abstract public void render(RenderStage stage, List<ObjectInstance> instances);
147119

148120
public boolean shouldRender(int mesh, ObjectInstance instance) {
149121
if(instance instanceof AnimatedObjectInstance animationInstance) {

src/library/java/gg/generations/rarecandy/renderer/loading/ModelLoader.java

Lines changed: 31 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void processModel(
9090

9191
indexBytes *= Integer.BYTES;
9292

93-
int vertexBytes = vertexCount * 24;
93+
int vertexBytes = vertexCount * 80;
9494

9595
int indexOffset = alignUp(vertexBytes, alignment);
9696
int totalBytes = indexOffset + indexBytes;
@@ -457,90 +457,47 @@ private static DrawRecord processPrimitiveModel(
457457

458458
var isEmpty = IntStream.range(0, ids.length).allMatch(a -> ids[a] == 0);
459459

460-
var indexArray = new int[amount];
461-
462460
for (int i = 0; i < amount; i++) {
463461

464462
var position = aiVert.get(i);
465463
var uv = aiUV.get(i);
466464
var normal = aiNormals.get(i);
467465

468-
// vertexBuffer.putFloat(position.x());
469-
// vertexBuffer.putFloat(position.y());
470-
// vertexBuffer.putFloat(position.z());
471-
// vertexBuffer.putFloat(0);
472-
// vertexBuffer.putFloat(uv.x());
473-
// vertexBuffer.putFloat(1 - uv.y());
474-
// vertexBuffer.putFloat(0);
475-
// vertexBuffer.putFloat(0);
476-
// vertexBuffer.putFloat(normal.x());
477-
// vertexBuffer.putFloat(normal.y());
478-
// vertexBuffer.putFloat(normal.z());
479-
// vertexBuffer.putFloat(0);
480-
//
481-
// if(isEmpty) {
482-
// vertexBuffer.putInt(1);
483-
// vertexBuffer.putInt(0);
484-
// vertexBuffer.putInt(0);
485-
// vertexBuffer.putInt(0);
486-
//
487-
// vertexBuffer.putFloat(1);
488-
// vertexBuffer.putFloat(0);
489-
// vertexBuffer.putFloat(0);
490-
// vertexBuffer.putFloat(0);
491-
// } else {
492-
// vertexBuffer.putInt(ids[i * 4]);
493-
// vertexBuffer.putInt(ids[i * 4 + 1]);
494-
// vertexBuffer.putInt(ids[i * 4 + 2]);
495-
// vertexBuffer.putInt(ids[i * 4 + 3]);
496-
//
497-
// vertexBuffer.putFloat(weights[i * 4]);
498-
// vertexBuffer.putFloat(weights[i * 4 + 1]);
499-
// vertexBuffer.putFloat(weights[i * 4 + 2]);
500-
// vertexBuffer.putFloat(weights[i * 4 + 3]);
501-
// }
502-
503-
short qx = (short) Math.round(position.x() * 1000f);
504-
short qy = (short) Math.round(position.y() * 1000f);
505-
short qz = (short) Math.round(position.z() * 1000f);
506-
507-
int uvPacked = (floatToHalf(1.0f - uv.y()) << 16) | (floatToHalf(uv.x()) & 0xFFFF);
508-
509-
int nx = Math.round(normal.x() * 511.0f);
510-
int ny = Math.round(normal.y() * 511.0f);
511-
int nz = Math.round(normal.z() * 511.0f);
512-
int packedNormal = (nx & 0x3FF) | ((ny & 0x3FF) << 10) | ((nz & 0x3FF) << 20);
513-
514-
int boneIdPacked;
515-
516-
int boneWeightPacked;
466+
vertexBuffer.putFloat(position.x());
467+
vertexBuffer.putFloat(position.y());
468+
vertexBuffer.putFloat(position.z());
469+
vertexBuffer.putFloat(0);
470+
vertexBuffer.putFloat(uv.x());
471+
vertexBuffer.putFloat(1 - uv.y());
472+
vertexBuffer.putFloat(0);
473+
vertexBuffer.putFloat(0);
474+
vertexBuffer.putFloat(normal.x());
475+
vertexBuffer.putFloat(normal.y());
476+
vertexBuffer.putFloat(normal.z());
477+
vertexBuffer.putFloat(0);
517478

518479
if(isEmpty) {
519-
boneIdPacked = 1;
520-
boneWeightPacked = 255;
480+
vertexBuffer.putInt(1);
481+
vertexBuffer.putInt(0);
482+
vertexBuffer.putInt(0);
483+
vertexBuffer.putInt(0);
484+
485+
vertexBuffer.putFloat(1);
486+
vertexBuffer.putFloat(0);
487+
vertexBuffer.putFloat(0);
488+
vertexBuffer.putFloat(0);
521489
} else {
522-
boneIdPacked =
523-
(ids[i * 4] & 0xFF) |
524-
((ids[i * 4 + 1] & 0xFF) << 8) |
525-
((ids[i * 4 + 2] & 0xFF) << 16) |
526-
((ids[i * 4 + 3] & 0xFF) << 24);
527-
528-
boneWeightPacked =
529-
((int)(weights[i * 4] * 255.0f) & 0xFF) |
530-
(((int)(weights[i * 4 + 1] * 255.0f) & 0xFF) << 8) |
531-
(((int)(weights[i * 4 + 2] * 255.0f) & 0xFF) << 16) |
532-
(((int)(weights[i * 4 + 3] * 255.0f) & 0xFF) << 24);
490+
vertexBuffer.putInt(ids[i * 4]);
491+
vertexBuffer.putInt(ids[i * 4 + 1]);
492+
vertexBuffer.putInt(ids[i * 4 + 2]);
493+
vertexBuffer.putInt(ids[i * 4 + 3]);
494+
495+
vertexBuffer.putFloat(weights[i * 4]);
496+
vertexBuffer.putFloat(weights[i * 4 + 1]);
497+
vertexBuffer.putFloat(weights[i * 4 + 2]);
498+
vertexBuffer.putFloat(weights[i * 4 + 3]);
533499
}
534500

535-
vertexBuffer.putShort(qx);
536-
vertexBuffer.putShort(qy);
537-
vertexBuffer.putShort(qz);
538-
vertexBuffer.putShort((short) 0);
539-
vertexBuffer.putInt(uvPacked);
540-
vertexBuffer.putInt(packedNormal);
541-
vertexBuffer.putInt(boneIdPacked);
542-
vertexBuffer.putInt(boneWeightPacked);
543-
544501
dimensions.max(temp.set(position.x(), position.y(), position.z()));
545502
}
546503

@@ -643,10 +600,6 @@ private static void vertexAttribPointer(Attribute data, int binding) {
643600
0);
644601
}
645602

646-
public MultiRenderObject createObject(@NotNull Supplier<PixelAsset> is, Consumer<MultiRenderObject> onFinish) {
647-
return createObject(MultiRenderObject::new, is, MaterialReference::process, onFinish);
648-
}
649-
650603
public record Names(List<String> meshes, List<String> variants, List<String> images, List<String> materials) {
651604
public Names() {
652605
this(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>());

src/library/java/gg/generations/rarecandy/renderer/pipeline/util/Uniform.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public void uploadImage2D(TextureArray texture, ITexture.ComputeAccess access, i
145145
public void uploadImage2D(int texture, ITexture.Type type, ITexture.ComputeAccess access, int unit, int layer) {
146146
var layered = layer > -1;
147147

148+
layer = layer == -1 ? 0 : layer;
149+
148150
glBindImageTexture(
149151
unit, // image unit = layout(binding=unit)
150152
texture, // GL texture ID from ITexture

src/library/java/gg/generations/rarecandy/renderer/textures/BlankTexture.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import java.io.IOException;
77
import java.util.Objects;
88

9+
import static org.lwjgl.opengl.GL11.*;
10+
import static org.lwjgl.opengl.GL12.GL_TEXTURE_BASE_LEVEL;
11+
import static org.lwjgl.opengl.GL12.GL_TEXTURE_MAX_LEVEL;
912
import static org.lwjgl.opengl.GL42.glTexStorage2D;
1013

1114
public final class BlankTexture implements ITexture {
@@ -25,6 +28,14 @@ public BlankTexture(Texture.Type type, int width, int height, ComputeAccess acce
2528
id = GL11.glGenTextures();
2629
GL11C.glBindTexture(GL11C.GL_TEXTURE_2D, id);
2730
glTexStorage2D(GL11C.GL_TEXTURE_2D, 1, type.internalFormat, width, height);
31+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // or GL_LINEAR
32+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // or GL_LINEAR
33+
34+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
35+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
36+
37+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
38+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
2839
GL11C.glBindTexture(GL11C.GL_TEXTURE_2D, 0);
2940
}
3041

@@ -85,7 +96,7 @@ public void close() throws IOException {
8596
GL11.glDeleteTextures(id);
8697
}
8798

88-
public ComputeAccess getAccess() {
99+
public ComputeAccess access() {
89100
return access;
90101
}
91102

src/library/java/gg/generations/rarecandy/renderer/textures/TextureDetailsSTB.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
import java.nio.ByteBuffer;
88

9+
import static org.lwjgl.opengl.GL11.*;
10+
import static org.lwjgl.opengl.GL12.GL_TEXTURE_BASE_LEVEL;
11+
import static org.lwjgl.opengl.GL12.GL_TEXTURE_MAX_LEVEL;
12+
913
record TextureDetailsSTB(ByteBuffer buffer, Texture.Type type, int width, int height) implements TextureDetails {
1014
@Override
1115
public void close() {}
@@ -14,7 +18,14 @@ public int init() {
1418
var id = GL11.glGenTextures();
1519
GL11C.glBindTexture(GL11C.GL_TEXTURE_2D, id);
1620
GL11C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, type.internalFormat, width, height, 0, type.format, type.type, buffer);
21+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // or GL_LINEAR
22+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // or GL_LINEAR
23+
24+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
25+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1726

27+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
28+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1829
MemoryUtil.memFree(buffer);
1930

2031
return id;

0 commit comments

Comments
 (0)