Apply shader only to first lod

This commit is contained in:
Mark B 2022-11-04 02:06:58 +01:00
parent 52b30b44ea
commit c166518090
2 changed files with 21 additions and 16 deletions

View File

@ -97,7 +97,8 @@ export class LowresTileLoader {
textureImage: { textureImage: {
type: 't', type: 't',
value: texture value: texture
} },
lod: {value: this.lod}
}, },
vertexShader: this.vertexShader, vertexShader: this.vertexShader,
fragmentShader: this.fragmentShader, fragmentShader: this.fragmentShader,

View File

@ -49,6 +49,7 @@ uniform TileMap hiresTileMap;
uniform sampler2D textureImage; uniform sampler2D textureImage;
uniform vec2 tileSize; uniform vec2 tileSize;
uniform vec2 textureSize; uniform vec2 textureSize;
uniform int lod;
varying vec3 vPosition; varying vec3 vPosition;
varying vec3 vWorldPosition; varying vec3 vWorldPosition;
@ -75,6 +76,7 @@ vec2 posToMetaUV(vec2 pos) {
return vec2(pos.x / textureSize.x, pos.y / textureSize.y + 0.5); return vec2(pos.x / textureSize.x, pos.y / textureSize.y + 0.5);
} }
void main() { void main() {
//discard if hires tile is loaded at that position //discard if hires tile is loaded at that position
if (vDistance < 900.0 && texture(hiresTileMap.map, ((vWorldPosition.xz - hiresTileMap.translate) / hiresTileMap.scale - hiresTileMap.pos) / hiresTileMap.size + 0.5).r > 0.75) discard; if (vDistance < 900.0 && texture(hiresTileMap.map, ((vWorldPosition.xz - hiresTileMap.translate) / hiresTileMap.scale - hiresTileMap.pos) / hiresTileMap.size + 0.5).r > 0.75) discard;
@ -88,6 +90,8 @@ void main() {
float heightZ = metaToHeight(texture(textureImage, posToMetaUV(vPosition.xz + vec2(0.0, 1.0)))); float heightZ = metaToHeight(texture(textureImage, posToMetaUV(vPosition.xz + vec2(0.0, 1.0))));
float diff = (height - heightX) + (height - heightZ); float diff = (height - heightX) + (height - heightZ);
vec3 defaultRGB = color.rgb + clamp(diff * 0.04, -0.2, 0.04); vec3 defaultRGB = color.rgb + clamp(diff * 0.04, -0.2, 0.04);
if(lod == 1) {
vec3 occRGB = color.rgb + clamp(diff * 0.02, -0.1, 0.04); vec3 occRGB = color.rgb + clamp(diff * 0.02, -0.1, 0.04);
float ao = 0.0; float ao = 0.0;
@ -103,10 +107,10 @@ void main() {
} }
occRGB += ao * 0.1; occRGB += ao * 0.1;
vec3 rgb = mix(defaultRGB, occRGB, smoothstep(PI_HALF + PI_D10, PI - PI_D10, acos(clamp(viewMatrix[1][1] - 1.0, -1.0, 0.0)))); color.rgb = mix(defaultRGB, occRGB, smoothstep(PI_HALF + PI_D10, PI - PI_D10, acos(clamp(viewMatrix[1][1] - 1.0, -1.0, 0.0))));
} else {
color.rgb = rgb; color.rgb = defaultRGB;
}
float blockLight = metaToLight(meta); float blockLight = metaToLight(meta);
float light = mix(blockLight, 15.0, sunlightStrength); float light = mix(blockLight, 15.0, sunlightStrength);
color.rgb *= mix(ambientLight, 1.0, light / 15.0); color.rgb *= mix(ambientLight, 1.0, light / 15.0);