Hi there, guys!
I’m having a trouble making custom shader work properly, so may be you could give me a suggestion or two.
The shader in question is a simple 3D noise, applied to every texel based on its world position:
this.material.chunks.diffuseConstPS = app.assets.get (this.shader).resource;
Shader chunk:
uniform vec3 material_diffuse;
// we have 512x512 noise map, which is used as 64x64x64 3D noise
uniform sampler2D noise_map;
void getAlbedo()
{
// texel world position
vec3 pos = vPositionW;
// we have 8x8 quadrants of 64x64 tiles
// Y coordinate is converted to quadrant index
// calculating quadrant index: 0, 1, 2, ..., 63
float index = floor (64.0 * fract (pos.y));
// quadrant [i, j] coords in 0...7 range
float j = floor (index * 0.125);
float i = index - j * 8.0;
// where to sample noise texture based on texel world position
vec2 uv = 64.0 * vec2 (i + fract (pos.x), j + fract (pos.z)) / 512.0;
vec4 noise = texture2D (noise_map, uv);
dAlbedo = material_diffuse.rgb * noise.g;
}
Here is the result:
Use WASD and Mouse Drag to move around.
While moving around you will notice a strange view-dependent moire on walls:
When you’re close to the walls it disappears, but when you move away from them it starts showing up.
It doesn’t show up on the floor, so I think that’s connected with how quadrants are calculated from Y coord.
I assume that’s some sort of floating point rounding error happening, but can’t exactly understand where.
Any ideas?