SceneKit water like in Badger example -
does enybody know how create water material in badger example apple?
there "geotherm_01" object in "scene.scn" , object got materials "_1_terrasses_orange_water" , "_1_terrasses_eau" creates water slow animation looks realistic.
i've tried repeat same materials in testing project can't same result.
this water effect achieved using shader modifiers shown in scenekit scene editor within xcode. important material property normal map used affect lighting in order simulate wavelets on flat geometry.
more modifier .surface
entry point is
float waterspeed = u_time * -0.1;vec2 uvs = _surface.normaltexcoord;uvs.x *= 2;vec3 tn = texture2d(u_normaltexture, vec2(uvs.x, uvs.y + waterspeed)).xyz;tn = tn * 2 - 1;vec3 tn2 = texture2d(u_normaltexture, vec2(uvs.x + 0.35 , uvs.y + 0.35 + (waterspeed * 1.3))).xyz;tn2 = tn2 * 2 - 1;vec3 rn = (tn + tn2) * 0.5;mat3 ts = mat3(_surface.tangent, _surface.bitangent, _surface.geometrynormal);_surface.normal = normalize(ts * rn);
here's commented version of code:
// elapsed time in seconds float waterspeed = u_time * -0.1; // texture coordinates used sample normal map vec2 uvs = _surface.normaltexcoord; uvs.x *= 2; // sample normal map vec3 tn = texture2d(u_normaltexture, vec2(uvs.x, uvs.y + waterspeed)).xyz; // texture stores values in [0, 1] range // express coordinates of normal vector in [-1, +1] range tn = tn * 2 - 1; // sample normal map again, using `waterspeed` offset time // in order produce animation effect vec3 tn2 = texture2d(u_normaltexture, vec2(uvs.x + 0.35 , uvs.y + 0.35 + (waterspeed * 1.3))).xyz; tn2 = tn2 * 2 - 1; // combine 2 normals (static , animated) produce richer (more complex , less uniform) effect vec3 rn = (tn + tn2) * 0.5; // normals in normal map expressed in tangent space // convert them object space , override surface normal simulate wavelets mat3 ts = mat3(_surface.tangent, _surface.bitangent, _surface.geometrynormal); _surface.normal = normalize(ts * rn);
Comments
Post a Comment