![]() Of course then you need to normalize the vector in the fragment (!) shader because it does not have constant size of 1 (which I need for the dot product). between vertex and fragment shaders it is automatically interpolated with the normal vectors of the other two vertices). ![]() This is the key to the trick! Then this zero normal vector is passed to the fragment shader, (i.e. Wrong.Īttempt#3: I did everything as in attempt#2 except I assigned the normal vector in the cone-tip vertices equal to zero vector vec3(0.0f, 0.0f, 0.0f). Well this was better because I had smooth lighting in the part closer to the base of the cone but not smooth near the tip. This was easy for the vertices on the circular base of the cone but what should be used for the tip of the cone? I used the normal vector of the whole triangle (i.e. Wrong.Īttempt#2: I calculated the normal vector for each vertex separately. This was simple but did not achieve smooth lighting, each face had a constant color because all fragments of the triangle had the same normal vector. all vertices of one triangle had the same normal vector. Let me start with what I did and found unsatisfactory:Īttempt#1: Each cone face (triangle) was using a constant normal vector, i.e. Then the transformed positions, normal vectors and untransformed colors were passed to fragment shader where I calculated the dot product of light direction and normal vector and multiplied this number with the color. In my vertex shader I was only transforming the vertex positions (multiplying by projection and model-view matrix) and also transforming the normal vectors (multiplying by transformed inverse of model-view matrix). ![]() Normal_vector: vec3 (was kept as vec3 in the shaders as it was used for calculation dot product with the light direction) Position: vec3 (was automatically converted to vec4 in the shader by adding 1.0f as the last element) In all my work I use the following simple vertex structure: I did not care about the bottom face (circular base) as this is really straightforward. I have an array of triangles (obviously each has 3 vertices) which form the cone surface. shaders) made up from triangles a bit but then I found a surprisingly simple solution! I would say it is much better and simpler than what is suggested in the currently accepted answer. I was struggling with cones in modern OpenGL (i.e. We can cut the cone into multiple "stacks", so that the edge discontinuities are only visible at the tip of the cone rather than along the whole thing, but there will still be a tip!Īnybody have any tricks for smooth-shaded low-poly cones? But all we have to work with are triangles. Then we could specify each face with a degenerate quad, allowing us to specify a different normal for the two adjoining edges of each triangle. In a perfect world, the GPU could rasterize a true quad, not just triangles. Here is a detail of what choosing the average normal for each tip vertex looks like. You can compromise by choosing a tip normal that is the average of the two edges, but now none of your edges look good. But because you can only specify one normal at each vertex of a triangle, you can match one edge or the other, but not both. If you subdivide a cone into an 8-sided pyramid, calculating normals based on their position, you get stuck on the tip of the cone (technically the vertex of the cone, but let's call it the tip to avoid confusion with the mesh vertices).įor each triangular face, you want to match the normals along both edges. ![]() If you subdivide a cylinder into an 8-sided prism, calculating vertex normals based on their position ("smooth shading"), it looks pretty good.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |