TextureInstancedActor grass packing fix
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-03-27 21:52:20 -04:00
parent 732c9700c4
commit d87c262955
4 changed files with 17 additions and 15 deletions

View File

@ -37,9 +37,9 @@ uniform float time;
/** /**
Size of a column of data Size of a row of data
*/ */
uniform int colSize; uniform int rowSize;
//output buffers //output buffers
@ -75,8 +75,8 @@ void main() {
ivec2 texSize = textureSize(material.diffuse,0); ivec2 texSize = textureSize(material.diffuse,0);
int sampleX = (gl_InstanceID / colSize) * 5; int sampleX = (gl_InstanceID % rowSize) * 5;
int sampleY = (gl_InstanceID % colSize); int sampleY = (gl_InstanceID / rowSize);
//grab data out of texture //grab data out of texture
float xOffset = texelFetch(material.diffuse,ivec2(0 + sampleX,sampleY),0).r; float xOffset = texelFetch(material.diffuse,ivec2(0 + sampleX,sampleY),0).r;

View File

@ -1349,6 +1349,7 @@ Fix UI Testing debug menu
Fix orphan tooltips from inventory screen Fix orphan tooltips from inventory screen
Code formatting Code formatting
File-controlled foliage coloration File-controlled foliage coloration
Fix TextureInstancedActor packing data texture incorrectly (column major instead of row major)
# TODO # TODO

View File

@ -242,7 +242,7 @@ public class FoliageModel {
QueuedTexture queuedAsset = new QueuedTexture(QueuedTextureType.DATA_BUFF,buffer,textureWidth,textureHeight); QueuedTexture queuedAsset = new QueuedTexture(QueuedTextureType.DATA_BUFF,buffer,textureWidth,textureHeight);
Globals.assetManager.queuedAsset(queuedAsset); Globals.assetManager.queuedAsset(queuedAsset);
TextureInstancedActor actor = TextureInstancedActor.attachTextureInstancedActor(rVal, foliageType.getGraphicsTemplate().getModel().getPath(), vertexPath, fragmentPath, queuedAsset, drawCount, textureHeight); TextureInstancedActor actor = TextureInstancedActor.attachTextureInstancedActor(rVal, foliageType.getGraphicsTemplate().getModel().getPath(), vertexPath, fragmentPath, queuedAsset, drawCount, textureWidth / 5);
ClientEntityUtils.initiallyPositionEntity(rVal, realPos, new Quaterniond()); ClientEntityUtils.initiallyPositionEntity(rVal, realPos, new Quaterniond());
EntityUtils.getScale(rVal).set(1,1,1); EntityUtils.getScale(rVal).set(1,1,1);
//add ambient foliage behavior tree //add ambient foliage behavior tree

View File

@ -24,9 +24,9 @@ import electrosphere.renderer.texture.Texture;
public class TextureInstancedActor { public class TextureInstancedActor {
/** /**
* Uniform location for the column size uniform * Uniform location for the row size uniform
*/ */
static final String uniformColSize = "colSize"; static final String uniformRowSize = "rowSize";
//path of the model that this instanced actor uses //path of the model that this instanced actor uses
String modelPath; String modelPath;
@ -38,9 +38,10 @@ public class TextureInstancedActor {
int drawCount; int drawCount;
/** /**
* Size of a column of data * Size of a row of data
* Used because textures are packed row-major, not column-major
*/ */
int colSize = 1; int rowSize = 1;
/** /**
* The queued texture * The queued texture
@ -78,12 +79,12 @@ public class TextureInstancedActor {
* Creates an instanced actor * Creates an instanced actor
* @param modelPath The path of the model this actor uses * @param modelPath The path of the model this actor uses
*/ */
protected TextureInstancedActor(String modelPath, String vertexShaderPath, String fragmentShaderPath, QueuedTexture dataTexture, int drawCount, int colSize){ protected TextureInstancedActor(String modelPath, String vertexShaderPath, String fragmentShaderPath, QueuedTexture dataTexture, int drawCount, int rowSize){
this.modelPath = modelPath; this.modelPath = modelPath;
this.material = new Material(); this.material = new Material();
this.queuedTexture = dataTexture; this.queuedTexture = dataTexture;
this.drawCount = drawCount; this.drawCount = drawCount;
this.colSize = colSize; this.rowSize = rowSize;
this.vertexShaderPath = vertexShaderPath; this.vertexShaderPath = vertexShaderPath;
this.fragmentShaderPath = fragmentShaderPath; this.fragmentShaderPath = fragmentShaderPath;
} }
@ -107,11 +108,11 @@ public class TextureInstancedActor {
* @param fragmentShaderPath The path to the fragment shader to use * @param fragmentShaderPath The path to the fragment shader to use
* @param dataTexture The data texture containing data for this actor * @param dataTexture The data texture containing data for this actor
* @param drawCount The number of instances to draw * @param drawCount The number of instances to draw
* @param colSize The size of a column of data * @param rowSize The size of a row of data
* @return The TextureInstancedActor that was attached to the entity * @return The TextureInstancedActor that was attached to the entity
*/ */
public static TextureInstancedActor attachTextureInstancedActor(Entity parent, String modelPath, String vertexShaderPath, String fragmentShaderPath, QueuedTexture dataTexture, int drawCount, int colSize){ public static TextureInstancedActor attachTextureInstancedActor(Entity parent, String modelPath, String vertexShaderPath, String fragmentShaderPath, QueuedTexture dataTexture, int drawCount, int rowSize){
TextureInstancedActor newActor = new TextureInstancedActor(modelPath, vertexShaderPath, fragmentShaderPath, dataTexture, drawCount, colSize); TextureInstancedActor newActor = new TextureInstancedActor(modelPath, vertexShaderPath, fragmentShaderPath, dataTexture, drawCount, rowSize);
parent.putData(EntityDataStrings.TEXTURE_INSTANCED_ACTOR, newActor); parent.putData(EntityDataStrings.TEXTURE_INSTANCED_ACTOR, newActor);
return newActor; return newActor;
} }
@ -157,7 +158,7 @@ public class TextureInstancedActor {
openGLState.setActiveShader(renderPipelineState, shader); openGLState.setActiveShader(renderPipelineState, shader);
shader.setUniform(openGLState, uniformColSize, colSize); shader.setUniform(openGLState, uniformRowSize, rowSize);
this.material.apply_material(openGLState); this.material.apply_material(openGLState);
//apply uniform overrides //apply uniform overrides