Skip to content

Commit 99c93d0

Browse files
committed
emissive models
1 parent 63e6d87 commit 99c93d0

2 files changed

Lines changed: 89 additions & 41 deletions

File tree

src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.minecraft.core.registries.Registries;
2525
import net.minecraft.resources.Identifier;
2626
import net.minecraft.world.level.BlockAndTintGetter;
27+
import net.minecraft.world.level.BlockGetter;
2728
import net.minecraft.world.level.ColorResolver;
2829
import net.minecraft.world.level.LightLayer;
2930
import net.minecraft.world.level.biome.Biome;

src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java

Lines changed: 88 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,17 @@ private static boolean shouldMeshNonOpaqueBlockFace(int face, long quad, long me
362362

363363
private static void meshNonOpaqueFace(int face, long quad, long meta, long neighborQuad, long neighborMeta, Mesher mesher) {
364364
if (shouldMeshNonOpaqueBlockFace(face, quad, meta, neighborQuad, neighborMeta)) {
365-
mesher.putNext((long) (face&1) |
365+
mesher.putNext(applyQuadLight(
366+
(long) (face&1) |
366367
(quad&~LM) |
367-
((ModelQueries.faceUsesSelfLighting(meta, face)?quad:neighborQuad) & LM));
368+
((ModelQueries.faceUsesSelfLighting(meta, face)?quad:neighborQuad) & LM),
369+
meta));
368370
} else {
369371
mesher.skip(1);
370372
}
371373
}
372374

373-
private static long getQuadLight(long quad, long selfmeta) {
375+
private static long applyQuadLight(long quad, long selfmeta) {
374376
final long BLMSK = 0xFL<<(55+4);//block light mask
375377
long bl = quad&BLMSK;
376378
bl = Math.max(bl, ModelQueries.lightEmission(selfmeta)<<(55+4));
@@ -419,6 +421,7 @@ private void generateYZOpaqueInnerGeometry(int axis) {
419421
int iB = idx * 2 + (facingForward == 1 ? shift : 0);
420422

421423
long selfModel = this.sectionData[iA];
424+
long selfMeta = this.sectionData[iA+1];
422425
long nextModel = this.sectionData[iB];
423426

424427
//Check if next culls this face
@@ -433,10 +436,13 @@ private void generateYZOpaqueInnerGeometry(int axis) {
433436
}
434437
}
435438

436-
this.blockMesher.putNext(((long) facingForward) |//Facing
439+
this.blockMesher.putNext(
440+
applyQuadLight(
441+
((long) facingForward) |//Facing
437442
(selfModel&~LM) |
438-
(nextModel&LM)//Apply lighting
439-
);
443+
(nextModel&LM),//Apply lighting
444+
selfMeta
445+
));
440446
}
441447
}
442448

@@ -479,9 +485,12 @@ private void generateYZOpaqueOuterGeometry(int axis) {
479485
int neighborIdx = ((axis+1)*32*32 * 2)+(side)*32*32;
480486
long neighborId = this.neighboringFaces[neighborIdx + (other*32) + index];
481487
long A = this.sectionData[idx * 2];
488+
long selfMeta = this.sectionData[idx * 2 +1];
482489

483490
int nib = Mapper.getBlockId(neighborId);
484491
if (nib != 0) {//Not air
492+
//FIXME need to use selfMeta to check for if it can be culled against this block
493+
485494
int cid = this.modelMan.getModelId(nib);
486495
long meta = this.modelMan.getModelMetadataFromClientId(cid);
487496
if (ModelQueries.isFullyOpaque(meta)) {//Dont mesh this face
@@ -504,9 +513,12 @@ private void generateYZOpaqueOuterGeometry(int axis) {
504513

505514

506515

507-
this.blockMesher.putNext(((side == 0) ? 0L : 1L) |
516+
this.blockMesher.putNext(applyQuadLight(
517+
((side == 0) ? 0L : 1L) |
508518
(A&~LM) |
509-
((neighborId & (0xFFL << 56)) >>> 1)
519+
((neighborId & (0xFFL << 56)) >>> 1),
520+
selfMeta
521+
)
510522
);
511523
}
512524
}
@@ -588,9 +600,11 @@ private void generateYZFluidInnerGeometry(int axis) {
588600
// lighter = this.sectionData[bi];
589601
//}
590602

591-
this.blockMesher.putNext(((long) facingForward) |//Facing
603+
this.blockMesher.putNext(applyQuadLight(
604+
((long) facingForward) |//Facing
592605
(A&~LM) |
593-
(lighter&LM)//Apply lighting
606+
(lighter&LM),//Apply lighting
607+
Am)
594608
);
595609
}
596610
}
@@ -635,17 +649,17 @@ private void generateYZFluidOuterGeometry(int axis) {
635649
long neighborId = this.neighboringFaces[neighborIdx + (other*32) + index];
636650

637651
long A = this.sectionData[idx * 2];
638-
long B = this.sectionData[idx * 2 + 1];
652+
long Am = this.sectionData[idx * 2 + 1];
639653

640-
if (ModelQueries.containsFluid(B)) {
654+
if (ModelQueries.containsFluid(Am)) {
641655
int modelId = (int) ((A>>26)&0xFFFF);
642656
A &= ~(0xFFFFL<<26);
643657
int fluidId = this.modelMan.getFluidClientStateId(modelId);
644658
A |= Integer.toUnsignedLong(fluidId)<<26;
645-
B = this.modelMan.getModelMetadataFromClientId(fluidId);
659+
Am = this.modelMan.getModelMetadataFromClientId(fluidId);
646660

647661
//We need to update the typing info for A
648-
A &= ~0b110L; A |= getQuadTyping(B);
662+
A &= ~0b110L; A |= getQuadTyping(Am);
649663
}
650664

651665
//Check and test if can cull W.R.T neighbor
@@ -655,7 +669,7 @@ private void generateYZFluidOuterGeometry(int axis) {
655669
if (ModelQueries.containsFluid(meta)) {
656670
modelId = this.modelMan.getFluidClientStateId(modelId);
657671
}
658-
if (ModelQueries.cullsSame(B)) {
672+
if (ModelQueries.cullsSame(Am)) {
659673
if (modelId == ((A>>26)&0xFFFF)) {
660674
this.blockMesher.skip(1);
661675
continue;
@@ -670,9 +684,11 @@ private void generateYZFluidOuterGeometry(int axis) {
670684
}
671685
}
672686

673-
this.blockMesher.putNext((side == 0 ? 0L : 1L) |
687+
this.blockMesher.putNext(applyQuadLight(
688+
(side == 0 ? 0L : 1L) |
674689
(A&~LM) |
675-
((neighborId&(0xFFL<<56))>>>1)
690+
((neighborId&(0xFFL<<56))>>>1),
691+
Am)
676692
);
677693
}
678694
}
@@ -778,15 +794,15 @@ private void generateYZNonOpaqueOuterGeometry(int axis) {
778794
long neighborId = this.neighboringFaces[neighborIdx + (other*32) + index];
779795

780796
long A = this.sectionData[idx * 2];
781-
long B = this.sectionData[idx * 2 + 1];
797+
long Am = this.sectionData[idx * 2 + 1];
782798

783799
boolean fail = false;
784800
//Check and test if can cull W.R.T neighbor
785801
if (Mapper.getBlockId(neighborId) != 0) {//Not air
786802
int modelId = this.modelMan.getModelId(Mapper.getBlockId(neighborId));
787803

788804

789-
if (ModelQueries.cullsSame(B) && modelId == ((A>>26)&0xFFFF)) {//TODO: FIXME, this technically isnt correct as need to check self occulsion, thinks?
805+
if (ModelQueries.cullsSame(Am) && modelId == ((A>>26)&0xFFFF)) {//TODO: FIXME, this technically isnt correct as need to check self occulsion, thinks?
790806
//TODO: check self occlsuion in the if statment
791807
fail = true;
792808
} else {
@@ -814,19 +830,23 @@ private void generateYZNonOpaqueOuterGeometry(int axis) {
814830

815831

816832
//TODO: LIGHTING
817-
if (ModelQueries.faceExists(B, (axis<<1)|1) && ((side==1&&!fail) || (side==0&&!failB))) {
818-
this.blockMesher.putNext((long) (false ? 0L : 1L) |
833+
if (ModelQueries.faceExists(Am, (axis<<1)|1) && ((side==1&&!fail) || (side==0&&!failB))) {
834+
this.blockMesher.putNext(applyQuadLight(
835+
(long) (false ? 0L : 1L) |
819836
A |
820-
0//((ModelQueries.faceUsesSelfLighting(B, (axis<<1)|1)?A:) & (0xFFL << 55))
837+
0,//((ModelQueries.faceUsesSelfLighting(B, (axis<<1)|1)?A:) & (0xFFL << 55))//TODO:THIS
838+
Am)
821839
);
822840
} else {
823841
this.blockMesher.skip(1);
824842
}
825843

826-
if (ModelQueries.faceExists(B, (axis<<1)|0) && ((side==0&&!fail) || (side==1&&!failB))) {
827-
this.seondaryblockMesher.putNext((long) (true ? 0L : 1L) |
844+
if (ModelQueries.faceExists(Am, (axis<<1)|0) && ((side==0&&!fail) || (side==1&&!failB))) {
845+
this.seondaryblockMesher.putNext(applyQuadLight(
846+
(long) (true ? 0L : 1L) |
828847
A |
829-
0//(((0xFFL) & 0xFF) << 55)
848+
0,//(((0xFFL) & 0xFF) << 55)//TODO:THIS
849+
Am)
830850
);
831851
} else {
832852
this.seondaryblockMesher.skip(1);
@@ -975,12 +995,16 @@ private void generateXOpaqueInnerGeometry() {
975995
}
976996

977997
long selfModel = this.sectionData[iA];
998+
long selfMeta = this.sectionData[iA+1];
978999
long nextModel = this.sectionData[iB];
9791000

9801001
//Example thing thats just wrong but as example
981-
mesher.putNext(((long) facingForward) |//Facing
1002+
mesher.putNext(applyQuadLight(
1003+
((long) facingForward) |//Facing
9821004
(selfModel&~LM) |
983-
(nextModel&LM)
1005+
(nextModel&LM),//TODO FIX THIS (self lighting)
1006+
selfMeta
1007+
)
9841008
);
9851009
}
9861010
}
@@ -1041,9 +1065,13 @@ private void generateXOuterOpaqueGeometry() {
10411065
if (oki) {
10421066
ma.skip(skipA); skipA = 0;
10431067
long A = this.sectionData[(i<<5) * 2];
1044-
ma.putNext(0L |
1068+
long Am = this.sectionData[(i<<5) * 2+1];
1069+
ma.putNext(applyQuadLight(
1070+
0L |
10451071
(A&~LM) |
1046-
((neighborId&(0xFFL<<56))>>>1)
1072+
((neighborId&(0xFFL<<56))>>>1),
1073+
Am
1074+
)
10471075
);
10481076
} else {skipA++;}
10491077
} else {skipA++;}
@@ -1063,9 +1091,13 @@ private void generateXOuterOpaqueGeometry() {
10631091
if (oki) {
10641092
mb.skip(skipB); skipB = 0;
10651093
long A = this.sectionData[(i*32+31) * 2];
1066-
mb.putNext(1L |
1094+
long Am = this.sectionData[(i*32+31) * 2+1];
1095+
mb.putNext(applyQuadLight(
1096+
1L |
10671097
(A&~LM) |
1068-
((neighborId&(0xFFL<<56))>>>1)
1098+
((neighborId&(0xFFL<<56))>>>1),
1099+
Am
1100+
)
10691101
);
10701102
} else {skipB++;}
10711103
} else {skipB++;}
@@ -1189,9 +1221,12 @@ private void generateXInnerFluidGeometry() {
11891221
//}
11901222

11911223
//Example thing thats just wrong but as example
1192-
mesher.putNext(((long) facingForward) |//Facing
1224+
mesher.putNext(applyQuadLight(
1225+
((long) facingForward) |//Facing
11931226
(A&~LM) |
1194-
(lighter&LM)//Lighting
1227+
(lighter&LM),//Lighting
1228+
Am
1229+
)
11951230
);
11961231
}
11971232
}
@@ -1292,9 +1327,12 @@ private void generateXOuterFluidGeometry() {
12921327
// lighter = this.sectionData[bi];
12931328
//}
12941329

1295-
ma.putNext(0L |
1330+
ma.putNext(applyQuadLight(
1331+
0L |
12961332
(A&~LM) |
1297-
lightData
1333+
lightData,
1334+
Am
1335+
)
12981336
);
12991337
} else {skipA++;}
13001338
} else {skipA++;}
@@ -1353,9 +1391,12 @@ private void generateXOuterFluidGeometry() {
13531391
// lighter = this.sectionData[bi];
13541392
//}
13551393

1356-
mb.putNext(1L |
1394+
mb.putNext(applyQuadLight(
1395+
1L |
13571396
(A&~LM) |
1358-
lightData
1397+
lightData,
1398+
Am
1399+
)
13591400
);
13601401
} else {skipB++;}
13611402
} else {skipB++;}
@@ -1481,18 +1522,24 @@ private static void dualMeshNonOpaqueOuterX(int side, long quad, long meta, int
14811522

14821523
//TODO: Check (neighborAId!=0) && works oki
14831524
if ((neighborAId==0 && ModelQueries.faceExists(meta, ((2<<1)|0)^side))||(neighborAId!=0&&shouldMeshNonOpaqueBlockFace(((2<<1)|0)^side, quad, meta, ((long)neighborAId)<<26, neighborAMeta))) {
1484-
ma.putNext(((long)side)|
1525+
ma.putNext(applyQuadLight(
1526+
((long)side)|
14851527
(quad&~LM) |
1486-
(ModelQueries.faceUsesSelfLighting(meta, ((2<<1)|0)^side)?quad:(((long)neighborLight)<<55))
1528+
(ModelQueries.faceUsesSelfLighting(meta, ((2<<1)|0)^side)?quad:(((long)neighborLight)<<55)),
1529+
meta
1530+
)
14871531
);
14881532
} else {
14891533
ma.skip(1);
14901534
}
14911535

14921536
if (shouldMeshNonOpaqueBlockFace(((2<<1)|1)^side, quad, meta, neighborBQuad, neighborBMeta)) {
1493-
mb.putNext(((long)(side^1))|
1537+
mb.putNext(applyQuadLight(
1538+
((long)(side^1))|
14941539
(quad&~LM) |
1495-
((ModelQueries.faceUsesSelfLighting(meta, ((2<<1)|1)^side)?quad:neighborBQuad)&(0xFFL<<55))
1540+
((ModelQueries.faceUsesSelfLighting(meta, ((2<<1)|1)^side)?quad:neighborBQuad)&(0xFFL<<55)),
1541+
meta
1542+
)
14961543
);
14971544
} else {
14981545
mb.skip(1);

0 commit comments

Comments
 (0)