it work
This commit is contained in:
@@ -111,7 +111,7 @@ public class RenderDataFactory {
|
|||||||
long key = section.key;
|
long key = section.key;
|
||||||
buff = new MemoryBuffer(bufferSize * 8L);
|
buff = new MemoryBuffer(bufferSize * 8L);
|
||||||
long ptr = buff.address;
|
long ptr = buff.address;
|
||||||
MemoryUtil.memSet(ptr, -1, bufferSize * 8L);
|
MemoryUtil.memSet(ptr, 0,bufferSize * 8L);
|
||||||
int meshlet = 0;
|
int meshlet = 0;
|
||||||
int innerQuadCount = 0;
|
int innerQuadCount = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
public class MixinMinecraftClient {
|
public class MixinMinecraftClient {
|
||||||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resource/PeriodicNotificationManager;<init>(Lnet/minecraft/util/Identifier;Lit/unimi/dsi/fastutil/objects/Object2BooleanFunction;)V", shift = At.Shift.AFTER))
|
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resource/PeriodicNotificationManager;<init>(Lnet/minecraft/util/Identifier;Lit/unimi/dsi/fastutil/objects/Object2BooleanFunction;)V", shift = At.Shift.AFTER))
|
||||||
private void injectRenderDoc(RunArgs args, CallbackInfo ci) {
|
private void injectRenderDoc(RunArgs args, CallbackInfo ci) {
|
||||||
//System.load("C:\\Program Files\\RenderDoc\\renderdoc.dll");
|
System.load("C:\\Program Files\\RenderDoc\\renderdoc.dll");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void main() {
|
|||||||
|
|
||||||
uint mli = atomicAdd(drawCmd.instanceCount, total);//meshletListIndex
|
uint mli = atomicAdd(drawCmd.instanceCount, total);//meshletListIndex
|
||||||
|
|
||||||
uint meshletPtr = extractMeshletStart(meta);
|
uint meshletPtr = extractMeshletStart(meta) + (meta.cntA&0xFFFF);
|
||||||
|
|
||||||
emitMeshlets(mli, meshletPtr, a, a);
|
emitMeshlets(mli, meshletPtr, a, a);
|
||||||
emitMeshlets(mli, meshletPtr, u, (meta.cntB &0xFFFF));
|
emitMeshlets(mli, meshletPtr, u, (meta.cntB &0xFFFF));
|
||||||
|
|||||||
@@ -1,5 +1,32 @@
|
|||||||
#version 460 core
|
#version 460 core
|
||||||
|
layout(binding = 0) uniform sampler2D blockModelAtlas;
|
||||||
|
|
||||||
|
//TODO: need to fix when merged quads have discardAlpha set to false but they span multiple tiles
|
||||||
|
// however they are not a full block
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 uv;
|
||||||
|
layout(location = 1) in flat vec2 baseUV;
|
||||||
|
layout(location = 2) in flat vec4 tinting;
|
||||||
|
layout(location = 3) in flat vec4 addin;
|
||||||
|
layout(location = 4) in flat uint flags;
|
||||||
|
layout(location = 5) in flat vec4 conditionalTinting;
|
||||||
|
//layout(location = 6) in flat vec4 solidColour;
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColour;
|
layout(location = 0) out vec4 outColour;
|
||||||
void main() {
|
void main() {
|
||||||
outColour = vec4(1,0,0,1);
|
vec2 uv = mod(uv, vec2(1.0))*(1.0/(vec2(3.0,2.0)*256.0));
|
||||||
|
//vec4 colour = solidColour;
|
||||||
|
vec4 colour = texture(blockModelAtlas, uv + baseUV, ((flags>>1)&1u)*-4.0);
|
||||||
|
if ((flags&1u) == 1 && colour.a <= 0.25f) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Conditional tinting, TODO: FIXME: REPLACE WITH MASK OR SOMETHING, like encode data into the top bit of alpha
|
||||||
|
if ((flags&(1u<<2)) != 0 && abs(colour.r-colour.g) < 0.02f && abs(colour.g-colour.b) < 0.02f) {
|
||||||
|
colour *= conditionalTinting;
|
||||||
|
}
|
||||||
|
|
||||||
|
outColour = (colour * tinting) + addin;
|
||||||
|
|
||||||
|
//outColour = vec4(uv + baseUV, 0, 1);
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#define MESHLET_SIZE (QUADS_PER_MESHLET+2)
|
#define MESHLET_SIZE (QUADS_PER_MESHLET+2)
|
||||||
#import <voxy:lod/quad_format.glsl>
|
#import <voxy:lod/quad_format.glsl>
|
||||||
#import <voxy:lod/gl46mesh/bindings.glsl>
|
#import <voxy:lod/gl46mesh/bindings.glsl>
|
||||||
|
#import <voxy:lod/block_model.glsl>
|
||||||
#define PosHeader Quad
|
#define PosHeader Quad
|
||||||
|
|
||||||
|
|
||||||
@@ -59,22 +60,138 @@ bool setupMeshlet() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
layout(location = 0) out vec2 uv;
|
||||||
|
layout(location = 1) out flat vec2 baseUV;
|
||||||
|
layout(location = 2) out flat vec4 tinting;
|
||||||
|
layout(location = 3) out flat vec4 addin;
|
||||||
|
layout(location = 4) out flat uint flags;
|
||||||
|
layout(location = 5) out flat vec4 conditionalTinting;
|
||||||
|
|
||||||
|
vec4 uint2vec4RGBA(uint colour) {
|
||||||
|
return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 getFaceSize(uint faceData) {
|
||||||
|
float EPSILON = 0.001f;
|
||||||
|
vec4 faceOffsetsSizes = extractFaceSizes(faceData);
|
||||||
|
//Expand the quads by a very small amount
|
||||||
|
faceOffsetsSizes.xz -= vec2(EPSILON);
|
||||||
|
faceOffsetsSizes.yw += vec2(EPSILON);
|
||||||
|
|
||||||
|
//Make the end relative to the start
|
||||||
|
faceOffsetsSizes.yw -= faceOffsetsSizes.xz;
|
||||||
|
|
||||||
|
return faceOffsetsSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: make branchless by using ternaries i think
|
||||||
|
vec3 swizzelDataAxis(uint axis, vec3 data) {
|
||||||
|
if (axis == 0) { //Up/down
|
||||||
|
data = data.xzy;
|
||||||
|
}
|
||||||
|
//Not needed, here for readability
|
||||||
|
//if (axis == 1) {//north/south
|
||||||
|
// offset = offset.xyz;
|
||||||
|
//}
|
||||||
|
if (axis == 2) { //west/east
|
||||||
|
data = data.zxy;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
if (setupMeshlet()) {
|
if (setupMeshlet()) {
|
||||||
gl_Position = vec4(1.0f/0.0f);
|
gl_Position = vec4(1.0f/0.0f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((gl_VertexID>>2)!=0) {
|
|
||||||
gl_Position = vec4(1.0f/0.0f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint detail = extractDetail(meshletPosition);
|
uint lodLevel = extractDetail(meshletPosition);
|
||||||
ivec3 sectionPos = extractPosition(meshletPosition);
|
ivec3 sectionPos = extractPosition(meshletPosition);
|
||||||
|
|
||||||
ivec3 pos = (((sectionPos<<detail)-baseSectionPos)<<5);
|
|
||||||
pos += ivec3(gl_VertexID&1, 0, (gl_VertexID>>1)&1)*(1<<detail);
|
|
||||||
|
|
||||||
gl_Position = MVP * vec4(vec3(pos),1);
|
|
||||||
|
|
||||||
|
int cornerIdx = gl_VertexID&3;
|
||||||
|
vec3 innerPos = extractPos(quad);
|
||||||
|
uint face = extractFace(quad);
|
||||||
|
uint modelId = extractStateId(quad);
|
||||||
|
BlockModel model = modelData[modelId];
|
||||||
|
uint faceData = model.faceData[face];
|
||||||
|
bool isTranslucent = modelIsTranslucent(model);
|
||||||
|
bool hasAO = modelHasMipmaps(model);//TODO: replace with per face AO flag
|
||||||
|
bool isShaded = hasAO;//TODO: make this a per face flag
|
||||||
|
|
||||||
|
|
||||||
|
vec2 modelUV = vec2(modelId&0xFFu, (modelId>>8)&0xFFu)*(1.0/(256.0));
|
||||||
|
baseUV = modelUV + (vec2(face>>1, face&1u) * (1.0/(vec2(3.0, 2.0)*256.0)));
|
||||||
|
|
||||||
|
ivec2 quadSize = extractSize(quad);
|
||||||
|
|
||||||
|
{ //Generate tinting and flag data
|
||||||
|
flags = faceHasAlphaCuttout(faceData);
|
||||||
|
|
||||||
|
//We need to have a conditional override based on if the model size is < a full face + quadSize > 1
|
||||||
|
flags |= uint(any(greaterThan(quadSize, ivec2(1)))) & faceHasAlphaCuttoutOverride(faceData);
|
||||||
|
|
||||||
|
flags |= uint(!modelHasMipmaps(model))<<1;
|
||||||
|
|
||||||
|
//Compute lighting
|
||||||
|
tinting = getLighting(extractLightId(quad));
|
||||||
|
|
||||||
|
//Apply model colour tinting
|
||||||
|
uint tintColour = model.colourTint;
|
||||||
|
if (modelHasBiomeLUT(model)) {
|
||||||
|
tintColour = colourData[tintColour + extractBiomeId(quad)];
|
||||||
|
}
|
||||||
|
|
||||||
|
conditionalTinting = vec4(0);
|
||||||
|
if (tintColour != uint(-1)) {
|
||||||
|
flags |= 1u<<2;
|
||||||
|
conditionalTinting = uint2vec4RGBA(tintColour).yzwx;
|
||||||
|
}
|
||||||
|
|
||||||
|
addin = vec4(0.0);
|
||||||
|
if (!isTranslucent) {
|
||||||
|
tinting.w = 0.0;
|
||||||
|
//Encode the face, the lod level and
|
||||||
|
uint encodedData = 0;
|
||||||
|
encodedData |= face;
|
||||||
|
encodedData |= (lodLevel<<3);
|
||||||
|
encodedData |= uint(hasAO)<<6;
|
||||||
|
addin.w = float(encodedData)/255.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Apply face tint
|
||||||
|
if (isShaded) {
|
||||||
|
//TODO: make branchless, infact apply ahead of time to the texture itself in ModelManager since that is
|
||||||
|
// per face
|
||||||
|
if ((face>>1) == 1) {
|
||||||
|
tinting.xyz *= 0.8f;
|
||||||
|
} else if ((face>>1) == 2) {
|
||||||
|
tinting.xyz *= 0.6f;
|
||||||
|
} else if (face == 0){
|
||||||
|
tinting.xyz *= 0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vec4 faceSize = getFaceSize(faceData);
|
||||||
|
|
||||||
|
vec2 cQuadSize = (faceSize.yw + quadSize - 1) * vec2((cornerIdx>>1)&1, cornerIdx&1);
|
||||||
|
uv = faceSize.xz + cQuadSize;
|
||||||
|
|
||||||
|
vec3 cornerPos = extractPos(quad);
|
||||||
|
float depthOffset = extractFaceIndentation(faceData);
|
||||||
|
cornerPos += swizzelDataAxis(face>>1, vec3(faceSize.xz, mix(depthOffset, 1-depthOffset, float(face&1u))));
|
||||||
|
|
||||||
|
vec3 origin = vec3(((sectionPos<<lodLevel)-baseSectionPos)<<5);
|
||||||
|
gl_Position = MVP*vec4((cornerPos+swizzelDataAxis(face>>1,vec3(cQuadSize,0)))*(1<<lodLevel)+origin, 1.0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user