Based crumbling

- Fix crumbling on instancing engine by passing a baseInstance uniform
This commit is contained in:
Jozufozu 2024-03-29 17:40:49 -07:00
parent 227d753e73
commit 395f4b1dfc
4 changed files with 23 additions and 11 deletions

View file

@ -2,7 +2,6 @@ package com.jozufozu.flywheel.backend.engine.instancing;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.backend.engine.GroupKey;
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
import com.jozufozu.flywheel.backend.engine.MeshPool;
import com.jozufozu.flywheel.backend.gl.TextureBuffer;
@ -47,16 +46,11 @@ public class InstancedDraw {
mesh.draw(instancer.instanceCount());
}
public void renderOne(TextureBuffer buffer, InstanceHandleImpl impl) {
public void renderOne(TextureBuffer buffer) {
if (mesh.isInvalid()) {
return;
}
int instanceCount = instancer.instanceCount();
if (instanceCount <= 0 || impl.index >= instanceCount) {
return;
}
instancer.bind(buffer);
mesh.draw(1);

View file

@ -172,7 +172,9 @@ public class InstancedDrawManager extends DrawManager<InstancedInstancer<?>> {
for (var instanceHandlePair : progressEntry.getValue()) {
InstancedInstancer<?> instancer = instanceHandlePair.first();
var handle = instanceHandlePair.second();
var index = instanceHandlePair.second().index;
program.setInt("_flw_baseInstance", index);
for (InstancedDraw draw : instancer.draws()) {
CommonCrumbling.applyCrumblingProperties(crumblingMaterial, draw.material());
@ -182,7 +184,7 @@ public class InstancedDrawManager extends DrawManager<InstancedInstancer<?>> {
Samplers.INSTANCE_BUFFER.makeActive();
draw.renderOne(instanceTexture, handle);
draw.renderOne(instanceTexture);
}
}
}

View file

@ -10,6 +10,7 @@ import static org.lwjgl.opengl.GL20.glUniform3f;
import static org.lwjgl.opengl.GL20.glUniform4f;
import static org.lwjgl.opengl.GL20.glUniformMatrix3fv;
import static org.lwjgl.opengl.GL20.glUniformMatrix4fv;
import static org.lwjgl.opengl.GL30.glUniform1ui;
import static org.lwjgl.opengl.GL31.GL_INVALID_INDEX;
import static org.lwjgl.opengl.GL31.glGetUniformBlockIndex;
import static org.lwjgl.opengl.GL31.glUniformBlockBinding;
@ -104,13 +105,27 @@ public class GlProgram extends GlObject {
}
public void setBool(String glslName, boolean bool) {
setInt(glslName, bool ? 1 : 0);
}
public void setUInt(String glslName, int value) {
int uniform = getUniformLocation(glslName);
if (uniform < 0) {
return;
}
glUniform1i(uniform, bool ? 1 : 0);
glUniform1ui(uniform, value);
}
public void setInt(String glslName, int value) {
int uniform = getUniformLocation(glslName);
if (uniform < 0) {
return;
}
glUniform1i(uniform, value);
}
/**

View file

@ -2,12 +2,13 @@
#include "flywheel:internal/packed_material.glsl"
uniform uvec4 _flw_packedMaterial;
uniform int _flw_baseInstance = 0;
void main() {
_flw_uberMaterialVertexIndex = _flw_packedMaterial.x;
_flw_unpackMaterialProperties(_flw_packedMaterial.w, flw_material);
FlwInstance instance = _flw_unpackInstance(gl_InstanceID);
FlwInstance instance = _flw_unpackInstance(_flw_baseInstance + gl_InstanceID);
_flw_main(instance, uint(gl_InstanceID));
}