Passing cube normals to shader

Started by
1 comment, last by Plerion 9 years, 3 months ago

Hello all

Im using cube rendering. Basically per cube im using 8 vertices and 36 indices as one might expect. The problem im currently facing is passing normals accordingly to the shader. Putting them in the vertex buffer seems impractical since each vertex has 3 independent normals. My first guess was just sending an vec3 array as uniform to the shader and index it gl_VertexID but since that is not an option in WebGL im kinda out of ideas.

Is the best way to do so by using 36 vertices or is there a simpler way to accomplish this? Essentially I could use the average normal on each vertex and then the average of the 4 vertices of each face would be correct again. But obviously I can only access the one normal of the vertex. In the fragment shader its the interpolated value but not the average of the 4 vertices of the quad.

Thanks for any tips

Cromon

Advertisement

Putting them in the vertex buffer seems impractical since each vertex has 3 independent normals.

Why is this impractical? Normals make all of the vertices unique, thus increasing the count of the vertices in the buffer. It’s a fact of life.

Is the best way to do so by using 36 vertices

It is the de facto way. You are over-thinking. (By the way, it will actually only be 24 vertices.)


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Hello L. Spiro

Thanks for your answer, i already thought that it will be like that. For your second quote: I of course meant "without using 36 (24) vertices". /EDIT: No, actually i didnt, i wasnt remembering my posting correctly/

Anyway, I was able to store 3d position, normal, texcoord and color in 8 bytes per vertex, so ill just stick with the inreased vertex count (the devices its going to be running on have limited gpu memory available).

Greetings

Plerion

This topic is closed to new replies.

Advertisement