2017-08-20 7 views
-1

アップルからオーカーの例のように水の材料を作る方法を知っていますか?BadgerのようなSceneKitの水の例

"scene.scn"に "geotherm_01"オブジェクトがあり、このオブジェクトには現実的に見えるスローアニメーションの水を生成する "_1_terrasses_orange_water"と "_1_terrasses_eau"という素材があります。

テストプロジェクトで同じ資料を繰り返してみましたが、同じ結果が得られません。

答えて

3

この水効果は、XcodeのSceneKit Scene Editorに示されているようにshader modifiersを使用して達成されました。最も重要な材料特性は、完全に平坦なジオメトリ上のウェーブレットをシミュレートするために照明に影響を及ぼすために使用されるnormal mapです。

Badger

具体的.surfaceエントリポイントのための修飾子は

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); 

ここでは、コードのコメントバージョンですされています

// Elapsed time in seconds 
float waterSpeed = u_time * -0.1; 

// Texture coordinates that will be used to sample the normal map 
vec2 uvs = _surface.normalTexcoord; 
uvs.x *= 2; 

// Sample the normal map 
vec3 tn = texture2D(u_normalTexture, vec2(uvs.x, uvs.y + waterSpeed)).xyz; 

// The texture stores values in the [0, 1] range 
// Express the coordinates of the normal vector in the [-1, +1] range 
tn = tn * 2 - 1; 

// Sample the normal map again, using the `waterSpeed` offset this time 
// in order to produce the 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 the two normals (static and animated) to produce a richer (more complex and less uniform) effect 
vec3 rn = (tn + tn2) * 0.5; 

// Normals in the normal map are expressed in tangent space 
// Convert them to object space and override the surface normal to simulate wavelets 
mat3 ts = mat3(_surface.tangent, _surface.bitangent, _surface.geometryNormal); 
_surface.normal = normalize(ts * rn); 
+0

はあなたにmnuagesをありがとうございます。 – Nils

関連する問題