From 43cdd2176190797e67f69f80a1981744198f4ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=91=D0=B5=D0=BB=D0=BE=D0=B2?= Date: Thu, 19 Dec 2024 23:55:53 +0300 Subject: [PATCH] Another fix for fragment shader --- prismarine-viewer/examples/Cube.frag.wgsl | 17 ++--------------- prismarine-viewer/examples/Cube.vert.wgsl | 17 +++++++---------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/prismarine-viewer/examples/Cube.frag.wgsl b/prismarine-viewer/examples/Cube.frag.wgsl index f17d8c2c7..98d58f2e1 100644 --- a/prismarine-viewer/examples/Cube.frag.wgsl +++ b/prismarine-viewer/examples/Cube.frag.wgsl @@ -1,25 +1,12 @@ @group(0) @binding(1) var mySampler: sampler; @group(0) @binding(2) var myTexture: texture_2d; -@group(0) @binding(5) var tileSize: vec2; @fragment fn main( @location(0) fragUV: vec2f, - @location(2) @interpolate(flat) ColorBlend: vec3f, - @location(3) @interpolate(flat) ChunkOpacity: f32 + @location(1) @interpolate(flat) ColorBlend: vec4f, ) -> @location(0) vec4f { let pixelColor = textureSample(myTexture, mySampler, fragUV); // return vec4f(pixelColor.rgb * ColorBlend / 255, pixelColor.a); // Set alpha to 1.0 for full opacity - return vec4f(pixelColor.rgb * ColorBlend / 255, 1.0 * ChunkOpacity); // Set alpha to 1.0 for full opacity -// only gray: -// let t = textureSample(myTexture, mySampler, fragUV / tilesPerTexture + vec2f(trunc(TextureIndex % tilesPerTexture.y), trunc(TextureIndex / tilesPerTexture.x)) / tilesPerTexture); -// // return vec4f(pixelColor.rgb * ColorBlend / 255, pixelColor.a); // Set alpha to 1.0 for full opacity - -// if (abs(t.x-t.y) <=0.03 || abs(t.x-t.z)<=0.03 ||abs(t.y-t.z) <=0.03) -// { -// return vec4f(t.rgb * ColorBlend / 255, 1.0); -// } -// else { -// return vec4f(t.rgb, 1.0); -// } + return vec4f(pixelColor.rgb, 1.0) * ColorBlend; // Set alpha to 1.0 for full opacity } diff --git a/prismarine-viewer/examples/Cube.vert.wgsl b/prismarine-viewer/examples/Cube.vert.wgsl index 490d3275a..764411217 100644 --- a/prismarine-viewer/examples/Cube.vert.wgsl +++ b/prismarine-viewer/examples/Cube.vert.wgsl @@ -24,8 +24,7 @@ struct CubeModel { struct VertexOutput { @builtin(position) Position: vec4f, @location(0) fragUV: vec2f, - @location(2) @interpolate(flat) ColorBlend: vec3f, - @location(3) @interpolate(flat) ChunkOpacity: f32 + @location(1) @interpolate(flat) ColorBlend: vec4f, } @group(1) @binding(0) var cubes: array; @group(0) @binding(0) var ViewProjectionMatrix: mat4x4; @@ -59,11 +58,9 @@ fn main( let cube_position = vec4f(positionX, positionY, positionZ, 0.0); - let colorBlendR : f32 = f32(cube.cube[1] & 255); - let colorBlendG : f32 = f32((cube.cube[1] >> 8) & 255); - let colorBlendB : f32 = f32((cube.cube[1] >> 16) & 255); - let colorBlend = vec3f(colorBlendR, colorBlendG, colorBlendB); - + var colorBlend = vec4f(unpack4xU8(cube.cube[1])); + colorBlend.a = f32(chunk.opacity); + colorBlend /= 255; var normal : mat4x4; var Uv = vec2(uv.x, (1.0 - uv.y)); normal = rotatations[normalIndex]; @@ -95,13 +92,13 @@ fn main( } } - let textureSize: vec2 = vec2(textureDimensions(myTexture)); - let tilesPerTexture: vec2 = textureSize / tileSize; + let textureSize = vec2f(textureDimensions(myTexture)); + let tilesPerTexture= textureSize / tileSize; Uv = vec2(Uv / tilesPerTexture + vec2f(trunc(f32(textureIndex) % tilesPerTexture.y), trunc(f32(textureIndex) / tilesPerTexture.x)) / tilesPerTexture); + var output: VertexOutput; output.Position = ViewProjectionMatrix * (position * normal + cube_position); output.fragUV = Uv; - output.ChunkOpacity = f32(chunk.opacity) / 255; output.ColorBlend = colorBlend; return output; }