opengl - Triplanar texturing in glsl -


i followed paper called "gpu based algorithms terrain texturing" , says following:

the main algorithm apply triplanar texturing simple. first, check whether slope relatively large in same way slope based texturing. these regions high slope regions aected algorithm. check larger component of normal is, out of x , z. if x larger component, use geometry z coordinate texture coordinate s, , geometry y coordinate texture coordinate t. if z larger component, use geometry x coordinate texture coordinate s, , geometry y coordinate texture coordinate t.

so tried implement it. heightmap: heightmap

note added white lines in borders experiment, have maximum-height walls surrounding map.

now following articles, here's implementation in vertex shader:

#version 430  uniform mat4 projectionmatrix; uniform mat4 cameramatrix;  uniform vec3 scale;  layout(location = 0) in vec3 vertex; layout(location = 1) in vec3 normal;  out vec3 fsvertex; out vec3 fsnormal; out vec2 fsuvs;  void main() {     fsvertex = vertex;     fsnormal = normalize(normal);      if(fsnormal.y < 0.75) {         if(fsnormal.x > fsnormal.z)             fsuvs = vertex.zy * scale.zy;         else             fsuvs = vertex.xy * scale.xy;     }     else         fsuvs = vertex.xz * scale.xz;      gl_position = projectionmatrix * cameramatrix * vec4(vertex * scale, 1.0); } 

here's fragment shader, if helps.

this get: outcome

here's further look, proportion. top , left walls (of heightmap) rendered ok, , bottom , right walls still suffer stretching. these weird stretches spots next beginning of walls.

what cause of this?

if want check if normal's x or z coordinate longer, should use abs function:

if(abs(fsnormal.x) > abs(fsnormal.z)) 

furthermore, y > 0.75 seems coarse approximation, enough in cases. actually, maximum of abs(x), abs(y), abs(z) gives correct plane.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -