Hi all, I’m using shader chunks and having some problems. The goal is to reflect a texture based on the character’s position. I can’t stabilize the texture, either it repeats itself or I’m getting undesired behavior.
P.S.: I’m using both chunks.diffusePS and chunks.combinePS at the same time. (combinePS is for combineColor
(dealing in here) - diffusePS is for terrain’s 3 textures)
I’ll provide the same shader with 2 different versions so you can understand the problem clearly.
Here is Shader Version #1;
uniform vec2 character_position;
//scale = vec2(map_height, map_widht); 100x100
//my_cord = $UV;
vec3 combineColor() {
float dist = distance(character_position, vPositionW.xz);
float r = 0.1;
float shape = (smoothstep(r-0.1, r, dist)*0.75 + 0.25) - smoothstep(r, r + 0.1, dist);
vec4 texture = texture2DSRGB(texture_splat, my_cord * scale - vec2(0.5));
return texture.rgb + dAlbedo;
// vec3 tt = mix(dAlbedo, texture.rgb, shape);
// return tt * dDiffuseLight;
}
I get this result with this shader (it repeats itself all over the material);
Here is my Shader Version #2;
uniform vec2 character_position;
//scale = vec2(map_height, map_widht); 100x100
//my_cord = $UV;
vec3 combineColor() {
float dist = distance(character_position, vPositionW.xz);
float r = 0.1;
float shape = (smoothstep(r-0.1, r, dist)*0.75 + 0.25) - smoothstep(r, r + 0.1, dist);
vec4 texture = texture2DSRGB(texture_splat, my_cord * scale - vec2(0.5));
// NOW COMMENTING OUT THIS
//return texture.rgb + dAlbedo;
// AND ENABLE THESE
vec3 tt = mix(dAlbedo, texture.rgb, shape);
return tt * dDiffuseLight;
}
And with this I get this result (Also I have the video here: Screen Recording 2022-11-17 at 13.01.40.mov - VEED);