Almost all works
This commit is contained in:
@@ -12,12 +12,17 @@ layout(binding = 0, std140) uniform SceneUniform {
|
||||
};
|
||||
|
||||
struct BlockModel {
|
||||
uint faceColours[6];
|
||||
uint faceData[6];
|
||||
uint _pad[10];
|
||||
};
|
||||
|
||||
struct SectionMeta {
|
||||
uvec4 header;
|
||||
uvec4 drawdata;
|
||||
uint posA;
|
||||
uint posB;
|
||||
uint AABB;
|
||||
uint _padA;
|
||||
uint ptr;
|
||||
uint cnt;
|
||||
};
|
||||
|
||||
//TODO: see if making the stride 2*4*4 bytes or something cause you get that 16 byte write
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//TODO: FIXME: this isnt actually correct cause depending on the face (i think) it could be 1/64 th of a position off
|
||||
// but im going to assume that since we are dealing with huge render distances, this shouldent matter that much
|
||||
float extractFaceIndentation(uint faceData) {
|
||||
return float((faceData>>16)&63)/63;
|
||||
}
|
||||
|
||||
vec4 extractFaceSizes(uint faceData) {
|
||||
return (vec4(faceData&0xF, (faceData>>4)&0xF, (faceData>>8)&0xF, (faceData>>12)&0xF)/16)+vec4(0,1f/16,0,1f/16);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ uint extractFace(uint64_t quad) {
|
||||
}
|
||||
|
||||
uint extractStateId(uint64_t quad) {
|
||||
return Eu32(quad, 20, 26);
|
||||
return Eu32(quad, 16, 26);
|
||||
}
|
||||
|
||||
uint extractBiomeId(uint64_t quad) {
|
||||
|
||||
@@ -4,10 +4,14 @@ layout(binding = 0) uniform sampler2D blockModelAtlas;
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 1) in flat vec2 baseUV;
|
||||
layout(location = 2) in flat vec4 colourTinting;
|
||||
layout(location = 3) in flat int discardAlpha;
|
||||
|
||||
layout(location = 0) out vec4 outColour;
|
||||
void main() {
|
||||
vec2 uv = mod(uv, vec2(1))*(1f/(vec2(3,2)*256f));
|
||||
|
||||
outColour = texture(blockModelAtlas, uv + baseUV) * colourTinting;
|
||||
vec4 colour = texture(blockModelAtlas, uv + baseUV);
|
||||
if (discardAlpha == 1 && colour.a == 0.0f) {
|
||||
discard;
|
||||
}
|
||||
outColour = colour * colourTinting;
|
||||
}
|
||||
@@ -3,10 +3,13 @@
|
||||
|
||||
#import <zenith:lod/gl46/quad_format.glsl>
|
||||
#import <zenith:lod/gl46/bindings.glsl>
|
||||
#import <zenith:lod/gl46/block_model.glsl>
|
||||
#line 8
|
||||
|
||||
layout(location = 0) out vec2 uv;
|
||||
layout(location = 1) out flat vec2 baseUV;
|
||||
layout(location = 2) out flat vec4 colourTinting;
|
||||
layout(location = 3) out flat int discardAlpha;
|
||||
|
||||
uint extractLodLevel() {
|
||||
return uint(gl_BaseInstance)>>29;
|
||||
@@ -22,59 +25,69 @@ vec4 uint2vec4RGBA(uint colour) {
|
||||
return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255;
|
||||
}
|
||||
|
||||
//Gets the face offset with respect to the face direction (e.g. some will be + some will be -)
|
||||
float getFaceOffset(BlockModel model, uint face) {
|
||||
float offset = extractFaceIndentation(model.faceData[face]);
|
||||
return offset * (1-((int(face)&1)*2));
|
||||
}
|
||||
|
||||
vec2 getFaceSizeOffset(BlockModel model, uint face, uint corner) {
|
||||
vec4 faceOffsetsSizes = extractFaceSizes(model.faceData[face]);
|
||||
return mix(faceOffsetsSizes.xz, -(1-faceOffsetsSizes.yw), bvec2(((corner>>1)&1)==1, (corner&1)==1));
|
||||
}
|
||||
|
||||
//TODO: add a mechanism so that some quads can ignore backface culling
|
||||
// this would help alot with stuff like crops as they would look kinda weird i think,
|
||||
// same with flowers etc
|
||||
void main() {
|
||||
int cornerIdx = gl_VertexID&3;
|
||||
|
||||
Quad quad = quadData[uint(gl_VertexID)>>2];
|
||||
vec3 innerPos = extractPos(quad);
|
||||
|
||||
uint face = extractFace(quad);
|
||||
uint modelId = extractStateId(quad);
|
||||
BlockModel model = modelData[modelId];
|
||||
|
||||
//Change the ordering due to backface culling
|
||||
//NOTE: when rendering, backface culling is disabled as we simply dispatch calls for each face
|
||||
// this has the advantage of having "unassigned" geometry, that is geometry where the backface isnt culled
|
||||
//if (face == 0 || (face>>1 != 0 && (face&1)==1)) {
|
||||
// cornerIdx ^= 1;
|
||||
//}
|
||||
|
||||
uint lodLevel = extractLodLevel();
|
||||
ivec3 lodCorner = ((extractRelativeLodPos()<<lodLevel) - (baseSectionPos&(ivec3((1<<lodLevel)-1))))<<5;
|
||||
vec3 corner = innerPos * (1<<lodLevel) + lodCorner;
|
||||
|
||||
//TODO: see if backface culling is even needed, since everything (should) be back culled already
|
||||
//Flip the quad rotation by its face (backface culling)
|
||||
if ((face&1) != 0) {
|
||||
cornerIdx ^= 1;
|
||||
vec2 faceOffset = getFaceSizeOffset(model, face, cornerIdx);
|
||||
vec2 quadSize = vec2(extractSize(quad) * ivec2((cornerIdx>>1)&1, cornerIdx&1));
|
||||
vec2 size = (quadSize + faceOffset) * (1<<lodLevel);
|
||||
|
||||
vec3 offset = vec3(size, (float(face&1) + getFaceOffset(model, face)) * (1<<lodLevel));
|
||||
|
||||
if ((face>>1) == 0) {//Up/down
|
||||
offset = offset.xzy;
|
||||
}
|
||||
if ((face>>1) == 0) {
|
||||
cornerIdx ^= 1;
|
||||
//Not needed, here for readability
|
||||
//if ((face>>1) == 1) {//north/south
|
||||
// offset = offset.xyz;
|
||||
//}
|
||||
if ((face>>1) == 2) {//west/east
|
||||
offset = offset.zxy;
|
||||
}
|
||||
|
||||
ivec2 sizePreLod = extractSize(quad) * ivec2((cornerIdx>>1)&1, cornerIdx&1);
|
||||
ivec2 size = sizePreLod * (1<<lodLevel);
|
||||
gl_Position = MVP * vec4(corner + offset,1);
|
||||
|
||||
vec3 pos = corner;
|
||||
|
||||
//NOTE: can just make instead of face, make it axis (can also make it 2 bit instead of 3 bit then)
|
||||
// since the only reason face is needed is to ensure backface culling orientation thing
|
||||
uint axis = face>>1;
|
||||
if (axis == 0) {
|
||||
pos.xz += size;
|
||||
pos.y += (face&1)<<lodLevel;
|
||||
} else if (axis == 1) {
|
||||
pos.xy += size;
|
||||
pos.z += (face&1)<<lodLevel;
|
||||
} else {
|
||||
pos.yz += size;
|
||||
pos.x += (face&1)<<lodLevel;
|
||||
}
|
||||
|
||||
gl_Position = MVP * vec4(pos,1);
|
||||
|
||||
uint stateId = extractStateId(quad);
|
||||
uint biomeId = extractBiomeId(quad);
|
||||
|
||||
uv = vec2(sizePreLod);
|
||||
|
||||
vec2 modelUV = vec2(stateId&0xFF, (stateId>>8)&0xFF)*(1f/(256f));
|
||||
|
||||
//Compute the uv coordinates
|
||||
vec2 modelUV = vec2(modelId&0xFF, (modelId>>8)&0xFF)*(1f/(256f));
|
||||
//TODO: make the face orientated by 2x3 so that division is not a integer div and modulo isnt needed
|
||||
// as these are very slow ops
|
||||
baseUV = modelUV + (vec2(face%3, face/3) * (1f/(vec2(3,2)*256f)));
|
||||
uv = quadSize + faceOffset;//Add in the face offset for 0,0 uv
|
||||
|
||||
discardAlpha = 0;
|
||||
|
||||
//Compute lighting
|
||||
colourTinting = getLighting(extractLightId(quad));
|
||||
//Apply face tint
|
||||
if (face == 0) {
|
||||
@@ -82,21 +95,4 @@ void main() {
|
||||
} else if (face != 1) {
|
||||
colourTinting.xyz *= vec3((float(face-2)/4)*0.6 + 0.4);
|
||||
}
|
||||
|
||||
}
|
||||
//gl_Position = MVP * vec4(vec3(((cornerIdx)&1)+10,10,((cornerIdx>>1)&1)+10),1);
|
||||
//uint i = uint(quad>>32);
|
||||
//uint i = uint(gl_BaseInstance);
|
||||
//i ^= i>>16;
|
||||
//i *= 124128573;
|
||||
//i ^= i>>16;
|
||||
//i *= 4211346123;
|
||||
//i ^= i>>16;
|
||||
//i *= 462312435;
|
||||
//i ^= i>>16;
|
||||
//i *= 542354341;
|
||||
//i ^= i>>16;
|
||||
|
||||
//uint i = uint(lodLevel+12)*215387625;
|
||||
//colour *= vec4(vec3(float((uint(i)>>2)&7)/7,float((uint(i)>>5)&7)/7,float((uint(i)>>8)&7)/7)*0.7+0.3,1);
|
||||
//colour = vec4(vec3(float((uint(i)>>2)&7)/7,float((uint(i)>>5)&7)/7,float((uint(i)>>8)&7)/7),1);
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
uint extractDetail(SectionMeta section) {
|
||||
return section.header.x>>28;
|
||||
return section.posA>>28;
|
||||
}
|
||||
|
||||
ivec3 extractPosition(SectionMeta section) {
|
||||
int y = ((int(section.header.x)<<4)>>24);
|
||||
int x = (int(section.header.y)<<4)>>8;
|
||||
int z = int((section.header.x&((1<<20)-1))<<4);
|
||||
z |= int(section.header.y>>28);
|
||||
int y = ((int(section.posA)<<4)>>24);
|
||||
int x = (int(section.posB)<<4)>>8;
|
||||
int z = int((section.posA&((1<<20)-1))<<4);
|
||||
z |= int(section.posB>>28);
|
||||
z <<= 8;
|
||||
z >>= 8;
|
||||
return ivec3(x,y,z);
|
||||
}
|
||||
|
||||
uint extractQuadStart(SectionMeta meta) {
|
||||
return meta.drawdata.x;
|
||||
return meta.ptr;
|
||||
}
|
||||
|
||||
uint extractQuadCount(SectionMeta meta) {
|
||||
return meta.drawdata.y;
|
||||
return meta.cnt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user