Skip to content

Commit

Permalink
Fixed mip cutoff level
Browse files Browse the repository at this point in the history
  • Loading branch information
MCRcortex committed Jun 27, 2023
1 parent 86d7415 commit 2f93bef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version=0.14.21
fabric_version=0.84.0+1.20.1

# Mod Properties
mod_version=0.1.12-alpha
mod_version=0.1.13-alpha
maven_group=me.cortex
archives_base_name=nvidium
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void uploadChunkGeometry(long uploadBuffer, short[] outOffsets, Ch
//Update the meta bits of the model format
dst = uploadBuffer + offset * 4L * formatSize;
for (int j = 0; j < (segment.elementCount()/6)*4; j++) {
short flags = (short) 0b01;//No alpha, Yes mipping
short flags = (short) 0b100;//Yes mipping, No alpha cut
MemoryUtil.memPutShort(dst+ (long) j *formatSize+ 6L, flags);//Note: the 6 here is the offset into the vertex format
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public static void uploadChunkGeometry(long uploadBuffer, short[] outOffsets, Ch
//Update the meta bits of the model format
dst = uploadBuffer + offset * 4L * formatSize;
for (int j = 0; j < (segment.elementCount()/6)*4; j++) {
short flags = (short) 0b10;//alpha, No mipping
short flags = (short) 0b001;//No mipping, 0.1 alpha cut
MemoryUtil.memPutShort(dst+ (long) j *formatSize+ 6L, flags);//Note: the 6 here is the offset into the vertex format
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public static void uploadChunkGeometry(long uploadBuffer, short[] outOffsets, Ch
//Update the meta bits of the model format
dst = uploadBuffer + offset * 4L * formatSize;
for (int j = 0; j < (segment.elementCount()/6)*4; j++) {
short flags = (short) 0b11;//alpha, Yes mipping
short flags = (short) 0b110;//mipping, 0.5 cut
MemoryUtil.memPutShort(dst+ (long) j *formatSize+ 6L, flags);//Note: the 6 here is the offset into the vertex format
}

Expand Down Expand Up @@ -193,7 +193,7 @@ public static void uploadChunkGeometry(long uploadBuffer, short[] outOffsets, Ch
//Update the meta bits of the model format
dst = uploadBuffer + translucent * 4L * formatSize;
for (int j = 0; j < (segment.elementCount()/6)*4; j++) {
short flags = (short) 0b00;//No alpha, No mipping
short flags = (short) 0b000;//No mipping, No alpha cut
MemoryUtil.memPutShort(dst+ (long) j *formatSize+ 6L, flags);//Note: the 6 here is the offset into the vertex format
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/resources/assets/nvidium/shaders/terrain/frag.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ layout(location = 0) out vec4 colour;
layout(location = 1) in Interpolants {
vec4 tint;
vec4 addin;
vec3 uv_bias;
flat bool hasAlpha;
vec4 uv_bias_cutoff;
};


Expand All @@ -29,8 +28,8 @@ void main() {
//uint uid = gl_PrimitiveID*132471+123571;
//colour = vec4(float((uid>>0)&7)/7, float((uid>>3)&7)/7, float((uid>>6)&7)/7, 1.0);
//colour = vec4(1.0,1.0,0,1);
colour = texture(tex_diffuse, uv_bias.xy, uv_bias.z);
if (colour.a < 0.05f && hasAlpha) discard;
colour = texture(tex_diffuse, uv_bias_cutoff.xy, uv_bias_cutoff.z);
if (colour.a < uv_bias_cutoff.w) discard;
colour *= tint;
colour += addin;
//colour = vec4(1.0,(uv_bias.z/-8.1f)+0.001f,0,1);
Expand Down
16 changes: 6 additions & 10 deletions src/main/resources/assets/nvidium/shaders/terrain/mesh.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ taskNV in Task {
layout(location=1) out Interpolants {
vec4 tint;
vec4 addin;
vec3 uv_bias;
flat bool hasAlpha;
vec4 uv_bias_cutoff;
} OUT[];

vec3 decodeVertex(Vertex v) {
Expand Down Expand Up @@ -58,20 +57,17 @@ void main() {
vec3 posB = decodeVertex(B)+originAndBaseData.xyz;
gl_MeshVerticesNV[(gl_LocalInvocationID.x<<1)].gl_Position = MVP*vec4(posA,1.0);
gl_MeshVerticesNV[(gl_LocalInvocationID.x<<1)|1].gl_Position = MVP*vec4(posB,1.0);
//TODO: see if ternary or array is faster

bool isA = (gl_LocalInvocationID.x&1)==0;
gl_PrimitiveIndicesNV[primId] = (isA?0:2)+idxBase;
gl_PrimitiveIndicesNV[primId+1] = (isA?1:3)+idxBase;
gl_PrimitiveIndicesNV[primId+2] = (isA?2:0)+idxBase;

bool hasMipping = (A.d&int16_t(1))!=int16_t(0);
bool hasAlpha = (A.d&int16_t(2))!=int16_t(0);

OUT[(gl_LocalInvocationID.x<<1)|0].hasAlpha = hasAlpha;
OUT[(gl_LocalInvocationID.x<<1)|1].hasAlpha = hasAlpha;
bool hasMipping = (A.d&int16_t(4))!=int16_t(0);
float alphaCutoff = (float[](0.0f, 0.1f,0.5f))[(A.d&int16_t(3))];

OUT[(gl_LocalInvocationID.x<<1)|0].uv_bias = vec3(vec2(A.g,A.h)*(1f/65536), hasMipping?0.0f:-8.0f);
OUT[(gl_LocalInvocationID.x<<1)|1].uv_bias = vec3(vec2(B.g,B.h)*(1f/65536), hasMipping?0.0f:-8.0f);
OUT[(gl_LocalInvocationID.x<<1)|0].uv_bias_cutoff = vec4(vec2(A.g,A.h)*(1f/65536), hasMipping?0.0f:-8.0f, alphaCutoff);
OUT[(gl_LocalInvocationID.x<<1)|1].uv_bias_cutoff = vec4(vec2(B.g,B.h)*(1f/65536), hasMipping?0.0f:-8.0f, alphaCutoff);


vec4 tintA = vec4(A.e&int16_t(0xFF),(A.e>>8)&int16_t(0xFF),A.f&int16_t(0xFF),(A.f>>8)&int16_t(0xFF))/255;
Expand Down

0 comments on commit 2f93bef

Please sign in to comment.