opengl - Sphere Tessellation wrong coordinates -
i'm trying apply tessellation on gpu simple sphere. tessellation working simple plan, it's not working sphere. of course, know coordinates mapping aren't same, tried many ways it. example, tried use gl_tesscoord (x , y) in tessellation evaluation longitude et latitude mapped plane. convert them spherical coordinates, 'really' didn't work.
for tessellation control, i'm splitting patches 2 outer , 2 inner level.
here code draw sphere :
glbindvertexarray(vertexarrayobject); glpatchparameteri(gl_patch_vertices, 4); glbindbuffer(gl_element_array_buffer, indicesbuffer); gldrawelements(gl_patches, indices.length, gl_unsigned_int, 0); glbindvertexarray(0);
here current code in tessellation evaluation :
#version 430 layout(quads, fractional_even_spacing, ccw) in; uniform mat4 u_projectionmatrix; uniform mat4 u_viewmatrix; uniform mat4 u_transformmatrix; uniform float u_radius; uniform vec3 u_cameraposition; void main(void){ vec4 position = gl_in[0].gl_position; position.xz += gl_tesscoord.xy * 2.0 - 1.0; gl_position = u_projectionmatrix * u_viewmatrix * u_transformmatrix * position; }
here indices :
int indptr = 0;
for(int r=0; r< mrings-1; r++) for(int s=0; s<msectors-1; s++){ indices[indptr++] = r * msectors + s; indices[indptr++] = r * msectors + (s+1); indices[indptr++] = (r+1) * msectors + (s+1); indices[indptr++] = (r+1) * msectors + s; }
to draw sphere, followed example : creating 3d sphere in opengl using visual c++ credits go him (and thank way !).
here 2 images showing result :
if have hint me solve problem, it'd cool. thank you. note : if need other informations, please ask me , i'll post them.
seems you're taking first vertex (which lies on sphere) , offset horizontally (on xz plane) gl_tesscoord.xy:
vec4 position = gl_in[0].gl_position; position.xz += gl_tesscoord.xy * 2.0 - 1.0;
since you're producing quads, take gl_in
of size 4 points. you're interrested in first three. final position can interpolated this:
vec4 = mix(gl_in[1].gl_position, gl_in[0].gl_position, gl_tesscoord.x); vec4 b = mix(gl_in[2].gl_position, gl_in[3].gl_position, gl_tesscoord.x); gl_position = projectionmatrix * viewmatrix * transformmatrix * mix(a, b, gl_tesscoord.y);
(source)
that should fix problem.
p.s. normals, following (if sphere generated around origin):
vec3 normal = mat3x3(viewmatrix*transformmatrix) * normalize(position.xyz);
Comments
Post a Comment