normals

Normals for height map data

折月煮酒 提交于 2019-12-04 15:24:23
I want to find normals for height map data. I am using gl_triangles in my code for indices. How would I find normals for this? Given a triangle (vert1, vert2, vert3) its normal is ((vert2 - vert1).cross(vert3 - vert1)).normalize() . For smooth, per-vertex normals: Foreach vertex, sum together the face normals for each triangle that vertex is a part of, then normalize the sum. EDIT : Example: #include <GL/glut.h> #include <vector> #include <cmath> #include <Eigen/Core> #include <Eigen/Geometry> using namespace std; using namespace Eigen; typedef Matrix< Vector3f, Dynamic, Dynamic > VecMat; //

Generating Smooth Normals from active Vertex Array

岁酱吖の 提交于 2019-12-04 15:22:06
I'm attempting to hack and modify several rendering features of an old opengl fixed pipeline game, by hooking into OpenGl calls, and my current mission is to implement shader lighting. I've already created an appropriate shader program that lights most of my objects correctly, but this game's terrain is drawn with no normal data provided. The game calls: void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); and void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices);` to define and draw the terrain, thus I have these functions both

Understanding normals indices with Wavefront Obj

徘徊边缘 提交于 2019-12-04 13:03:51
I've written a C++ Obj file loader that I can't get to work correctly. The problem is that while parsing a simple obj file like the following: # Blender v2.62 (sub 0) OBJ File: '' # www.blender.org mtllib cube.mtl o Cube v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 -1.000000 -1.000000 v 1.000000 1.000000 -0.999999 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 vn 0.000000 0.000000 -1.000000 vn -1.000000 -0.000000 -0.000000 vn -0.000000 -0.000000 1.000000 vn 1.000000 -0.000000 0.000000 vn 1

Rotate Normals in Shader

爷,独闯天下 提交于 2019-12-04 08:13:03
I have a scene with several models with individual positions and rotations. Given normals, the shaders apply simple bidirectional lighting to each pixel. That is my vertex shader. #version 150 in vec3 position; in vec3 normal; in vec2 texcoord; out vec3 f_normal; out vec2 f_texcoord; uniform mat4 model; uniform mat4 view; uniform mat4 proj; void main() { mat4 mvp = proj * view * model; f_normal = normal; f_texcoord = texcoord; gl_Position = mvp * vec4(position, 1.0); } And here is the fragment shader. #version 150 in vec3 f_normal; in vec2 f_texcoord; uniform sampler2D tex; vec3 sun = vec3(0.5

Per-Vertex Normals from perlin noise?

假如想象 提交于 2019-12-04 03:12:48
I'm generating terrain in Opengl geometry shader and am having trouble calculating normals for lighting. I'm generating the terrain dynamically each frame with a perlin noise function implemented in the geometry shader. Because of this, I need an efficient way to calculate normals per-vertex based on the noise function (no texture or anything). I am able to take cross product of 2 side to get face normals, but they are generated dynamically with the geometry so I cannot then go back and smooth the face normals for vertex normals. How can I get vertex normals on the fly just using the noise

Smooth cone normals

倾然丶 夕夏残阳落幕 提交于 2019-12-04 02:00:13
问题 I'm trying to calculate smooth normals for a cone. In looking around for code samples and explanations, I consistently come across directions for face normals. I've posted a couple pictures below of what I'm doing. The first -- which basically just normalizes the vertex position -- gives me decently smooth shading, but the edges are "missing" and the bottom face isn't solid. The second has edges, but the shading is flat (face normals) and my light isn't reflecting off of them correctly. The

Integral Image normal estimation from kinect depth image

China☆狼群 提交于 2019-12-03 21:15:59
I am doing the following to try and estimate surface normals from a point cloud generated from a Kinect depth image: pcl::PointCloud<pcl::PointXYZRGB>::Ptr create_point_cloud_ptr(Mat& depthImage, Mat& rgbImage){ pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>()); cloud->width = depthImage.rows; //Dimensions must be initialized to use 2-D indexing cloud->height = depthImage.cols; cloud->resize(cloud->width*cloud->height); int min_depth = INT_MAX; int num_of_points_added = 0; for(int v=0; v< depthImage.rows; v++){ //2-D indexing for(int u=0; u< depthImage.cols;

Computing face normals and winding

≯℡__Kan透↙ 提交于 2019-12-03 17:46:03
Given a convex polyhedron with defined vertices (x, y, z) that specifies the faces of the polyhedron. How can I go about calculating the surface normal of each face of the polyhedron? I need the surface normal in order to compute the vertex normal to perform Gouraud shading . The only clue I could find about how to do this is Newell's method, but how do I make sure the normals are outward normals and not inward? Thanks for any help. Compute the face normal You have to compute the cross product of two vectors spanning the plane that contains the given face. It gives you the (non-unit) normal

What is a normal in OpenGL?

£可爱£侵袭症+ 提交于 2019-12-03 06:00:56
I heard that I should use normals instead of colors, because colors are deprecated. (Is that true?) Normals have something to do with the reflection of light, but I can't find a clear and intuitive explanation. What is a normal? A normal in general is a unit vector whose direction is perpendicular to a surface at a specific point. Therefore it tells you in which direction a surface is facing. The main use case for normals are lighting calculations, where you have to determine the angle (or practically often its cosine) between the normal at a given surface point and the direction towards a

Normal vectors for an eight vertex cube

拈花ヽ惹草 提交于 2019-12-02 13:26:27
问题 I was playing around with WEBGL and today and a encountered a problem with my cube's vertex normals . I checked my code with a cube mesh from internet and it works great. The thing is that the cube from internet has 24 vertices (4 for each face * 6 faces) which is way to much for I cube I think. FIDDLE MY CUBE | FIDDLE INTERNET CUBE (my code stars at line 200) I figured out that a cube needs no more than 8 vertices and 12 indices. But when I render my cube I get a weird shape on screen like