normals

Running normal maps / bump maps on Pixi.js

删除回忆录丶 提交于 2020-07-16 09:41:23
问题 I would really like to use normal maps in pixi.js but I don't know how. I've came across a good example with THREE.js and using webgl shaders - clickOnDemo (sometimes it's necessary to click once on the image to work). So I really wanted to replicate it but using pixi, I gave it a shot aand black screen - myDemo . I don't get errors and I'm not sure what I'm doing wrong. Could the problem be in the way I'm creating the mesh or the shader? var material = new PIXI.Shader.from(null, shaderCode,

Running normal maps / bump maps on Pixi.js

孤者浪人 提交于 2020-07-16 09:40:34
问题 I would really like to use normal maps in pixi.js but I don't know how. I've came across a good example with THREE.js and using webgl shaders - clickOnDemo (sometimes it's necessary to click once on the image to work). So I really wanted to replicate it but using pixi, I gave it a shot aand black screen - myDemo . I don't get errors and I'm not sure what I'm doing wrong. Could the problem be in the way I'm creating the mesh or the shader? var material = new PIXI.Shader.from(null, shaderCode,

CPU to GPU normal mapping

大憨熊 提交于 2020-06-27 18:32:06
问题 I'm creating a terrain mesh, and following this SO answer I'm trying to migrate my CPU computed normals to a shader based version, in order to improve performances by reducing my mesh resolution and using a normal map computed in the fragment shader. I'm using MapBox height map for the terrain data. Tiles look like this: And elevation at each pixel is given by the following formula: const elevation = -10000.0 + ((red * 256.0 * 256.0 + green * 256.0 + blue) * 0.1); My original code first

Calculate if two 3D triangles are on the same plane

旧时模样 提交于 2020-01-02 06:21:09
问题 For a 3D game engine I'm working on I need to calculate if two 3D triangles are on the same plane to display it accordingly. How do I calculate the angles of a triangle in 3D space? Would calculating a surface normal and comparing those ever give me 2 equivalent normals? 回答1: Why do you want to do that? What is the number of triangle you expect to test? It seems a little bit complex for a real time rendering algorithm! Anyway: Compute the normal n of the triangle. Then compute the plane

Calculating normals in a triangle mesh

£可爱£侵袭症+ 提交于 2019-12-27 11:00:17
问题 I have drawn a triangle mesh with 10000 vertices(100x100) and it will be a grass ground. I used gldrawelements() for it. I have looked all day and still can't understand how to calculate the normals for this. Does each vertex have its own normals or does each triangle have its own normals? Can someone point me in the right direction on how to edit my code to incorporate normals? struct vertices { GLfloat x; GLfloat y; GLfloat z; }vertices[10000]; GLuint indices[60000]; /* 99..9999 98..9998 ..

OpenGL ES20 - Light a cube, how to get normals?

ぃ、小莉子 提交于 2019-12-25 16:57:23
问题 To add some lightning to my OpenGL ES20 cube, I need to calculate the normals for each plane. I've found a "tutorial" on lightning, but they simply hard-coded the normals into the cube, which appears to me as not the best option, since it seems limited? So my approach to the cube is as follows: private float[] mVertices = { -1, -1, -1, // bottom left 1, -1, -1, // bottom right back 1, 1, -1, // top right -1, 1, -1, // top left -1, -1, 1, // bottom left 1, -1, 1, // bottom right front 1, 1, 1,

Calculating normals for a height map

偶尔善良 提交于 2019-12-23 08:28:35
问题 I have a small problem calculating normals for my heightmap. It has a strange behavior. At the higher and the lower points the normals are fine, but in the middle they seem wrong. They are lighted by a point light. UNFIXED SOURCE REMOVED EDIT: Tried 2 new approaches: This is per-face-normal. It looks fine but you see the single faces. Position normal = crossP(vectorize(pOL, pUR), vectorize(pOR, pUL)); I also tried to do it per-vertex this way, but also with a strange output. This is the

How to find the normal vector at a point on a curve in MatLab

青春壹個敷衍的年華 提交于 2019-12-22 09:48:04
问题 I have a curve and I want to find the normal vector at a given point on this curve, later I have to find the dot product of this normal vector with another vector. I tried the gradient function of MatLab, but I guess it doesnt work when we need to find the gradient at a specific point still I am not sure if I am wrong. Please guide me how can I achieve this in MatLab. Thanks in advance. 回答1: Using the explanation from this incredible SO question: if we define dx=x2-x1 and dy=y2-y1, then the