Skip to content

Commit

Permalink
Support UV_LIGHTMAP from material in rail rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 24, 2024
1 parent 10a2c79 commit 6771154
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.zbx1425.mtrsteamloco.MainClient;
import cn.zbx1425.sowcer.math.Vector3f;
import cn.zbx1425.sowcer.model.Model;
import cn.zbx1425.sowcer.vertex.VertAttrType;
import cn.zbx1425.sowcerext.model.RawMesh;
import cn.zbx1425.sowcerext.model.RawModel;
import cn.zbx1425.sowcerext.model.Vertex;
Expand Down Expand Up @@ -37,7 +38,7 @@ public RailModelProperties(Component name, RawModel rawModel, float repeatInterv

this.yOffset = yOffset;

rawModel.clearAttrStates();
rawModel.clearAttrState(VertAttrType.COLOR);
rawModel.applyRotation(new Vector3f(0.577f, 0.577f, 0.577f), (float)Math.toRadians(1));
this.rawModel = rawModel;
uploadedModel = MainClient.modelManager.uploadModel(rawModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class InstancedRailChunk extends RailChunkBase {

private static final VertAttrMapping RAIL_MAPPING = new VertAttrMapping.Builder()
.set(VertAttrType.POSITION, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.COLOR, VertAttrSrc.INSTANCE_BUF)
.set(VertAttrType.COLOR, VertAttrSrc.INSTANCE_BUF_OR_GLOBAL)
.set(VertAttrType.UV_TEXTURE, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.UV_OVERLAY, VertAttrSrc.GLOBAL)
.set(VertAttrType.UV_LIGHTMAP, VertAttrSrc.INSTANCE_BUF)
.set(VertAttrType.UV_LIGHTMAP, VertAttrSrc.INSTANCE_BUF_OR_GLOBAL)
.set(VertAttrType.NORMAL, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.MATRIX_MODEL, VertAttrSrc.INSTANCE_BUF)
.build();
Expand Down Expand Up @@ -89,7 +89,7 @@ public void rebuildBuffer(Level world) {
pieceMat.store(matFloatBuf);
oStream.write(lookAtBytes);

if (RAIL_MAPPING.paddingInstance > 0) oStream.writeByte(0);
for (int k = 0; k < RAIL_MAPPING.paddingInstance; k++) oStream.writeByte(0);
} catch (IOException ignored) {

}
Expand All @@ -111,7 +111,7 @@ public void enqueue(BatchManager batchManager, ShaderProp shaderProp) {
if (instanceBuf.size < 1) return;
VertAttrState attrState = new VertAttrState().setOverlayUVNoOverlay();
if (!RailRenderDispatcher.isHoldingRailItem) attrState.setColor(-1);
batchManager.enqueue(vertArrays, new EnqueueProp(attrState, VertAttrType.COLOR), shaderProp);
batchManager.enqueue(vertArrays, new EnqueueProp(attrState), shaderProp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class MeshBuildingRailChunk extends RailChunkBase {

private static final VertAttrMapping RAIL_MAPPING = new VertAttrMapping.Builder()
.set(VertAttrType.POSITION, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.COLOR, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.COLOR, VertAttrSrc.VERTEX_BUF_OR_GLOBAL)
.set(VertAttrType.UV_TEXTURE, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.UV_OVERLAY, VertAttrSrc.GLOBAL)
.set(VertAttrType.UV_LIGHTMAP, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.UV_LIGHTMAP, VertAttrSrc.VERTEX_BUF_OR_GLOBAL)
.set(VertAttrType.NORMAL, VertAttrSrc.VERTEX_BUF)
.set(VertAttrType.MATRIX_MODEL, VertAttrSrc.GLOBAL)
.build();
Expand Down Expand Up @@ -79,7 +79,7 @@ public void enqueue(BatchManager batchManager, ShaderProp shaderProp) {
if (vertArrays == null) return;
VertAttrState attrState = new VertAttrState().setModelMatrix(shaderProp.viewMatrix).setOverlayUVNoOverlay();
if (!RailRenderDispatcher.isHoldingRailItem) attrState.setColor(-1);
batchManager.enqueue(vertArrays, new EnqueueProp(attrState, VertAttrType.COLOR), ShaderProp.DEFAULT);
batchManager.enqueue(vertArrays, new EnqueueProp(attrState), ShaderProp.DEFAULT);
}

@Override
Expand Down

0 comments on commit 6771154

Please sign in to comment.