Hi everyone,
I am new to Three.js & 3D
My goal is to MIX multiple textures to a single face, with % opacity
texture splatting Texture splatting - Wikipedia
some questions (beginner)
-
is there a basic example out there ? with three js; i can’t find
Something very basic, to understand the process
a Plan
2 textures GREEN & WHITE.
<Green - Mix of green & white + White>
dot
the best example i could found is this one :
It’s very nice, but i have 2 majors issues wih this ;
- This section,that seems the most important, sounds like magic black voodoo Math
vec4 water = (smoothstep(0.01, 0.25, vAmount) - smoothstep(0.24, 0.26, vAmount)) * texture2D( oceanTexture, vUV * 10.0 );
vec4 sandy = (smoothstep(0.24, 0.27, vAmount) - smoothstep(0.28, 0.31, vAmount)) * texture2D( sandyTexture, vUV * 10.0 );
vec4 grass = (smoothstep(0.28, 0.32, vAmount) - smoothstep(0.35, 0.40, vAmount)) * texture2D( grassTexture, vUV * 20.0 );
vec4 rocky = (smoothstep(0.30, 0.50, vAmount) - smoothstep(0.40, 0.70, vAmount)) * texture2D( rockyTexture, vUV * 20.0 );
vec4 snowy = (smoothstep(0.50, 0.65, vAmount)) * texture2D( snowyTexture, vUV * 10.0 );
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) + water + sandy + grass + rocky + snowy;
can someone explain me further ?
i Guess some “segmentation” 0.01, 0.25 , 0.24, 0.27 … but its all i can understand.
smoothstep(0.01, 0.25, vAmount) - smoothstep(0.24, 0.26, vAmount)) * texture2D( oceanTexture, vUV * 10.0
// - 0.24 .26 ? why 24-26
// … * 10 .? why * 10
// last segment why does it stop at 50-65 and not 99 ?
I guess the global idea is “this pixel has 5% grass texture + 10% ocean texture + 25% water…” but my brain can make no link between this idea & the math behind…
I ll welcome anyone who can help me
-
Why use Shader ?
I see Shader as “live - perf - post processing”,
.
lets say i have a 128*128 2D Array, my LAND & “type”
Array[10][11] = {height: 1 ; type: FOREST }
Array[10][15] = {height:6 ; type: SNOW}
…
i have a FOREST texture
i have a SNOW texture
at render, i am looking for this kind of result
Array[10][11] => apply FOREST TEXTURE
Array[10][15] => apply SNOW TEXTURE
Array [10][12] => Apply 75% FOREST + 25 SNOW Array [10][13] => Apply 50 FOREST + 50 SNOW Array [10][14] => Apply 25 FOREST + 75 % SNOW
And it will never change. Am i not supposed to pre-compute a static “RGB” myself at LOADING, instead of postprocessing shader ?
Is the previous example still ok, lets say, if you have 25 differents grounds instead of 5 ?
Also in some other tutorials i ve seen, ppl are explaning
AddTexture (texture1 ) AlphaChannel = "opactity"
AddTexture (texture2 )
AddTexture (texture3 )
Playing with the AlphaChannel to "combine"
and there is no mention of shader doing the job... ..i thought texture opacity was enough
I am a bit lost,
Thx for reading and help