java - What is wrong with my normal calculations? -
java - What is wrong with my normal calculations? -
i attempted utilize algorithm described @ opengl - how calculate normals in terrain height grid?. popped in vertex shader , using perlin noise functions test it, , worked charm, when ported java, didn't work well.
float nx = 0; float ny = 0; float nz = 0; vector3 p = new vector3(vpx,vpy,vpz); vector3 off = new vector3(1,1,0); float hl = trygetheight(_mempoints2,p.x - off.x,p.z - off.z); float hr = trygetheight(_mempoints2,p.x + off.x,p.z + off.z); float hd = trygetheight(_mempoints2,p.x - off.z,p.z - off.y); float hu = trygetheight(_mempoints2,p.x + off.z,p.z + off.y); nx = hl - hr; ny = hd - hu; nz = 2.0f; vector3 v = new vector3(nx,ny,nz); v = v.nor(); nx = v.x; ny = v.y; nz = v.z;
the results algorithm in vertex shader:
the results algorithm in buffer setup:
(sorry blur, testing depth of field stuff when snapped these.)
the results algorithm in vertex shader:
normals should not calculated in shader stage. vertex shader doesn't have info neighboring vertices, geometry shader performance hog, tesselation shaders deliver normals local tesselation. , doing screen space normal calculations in fragment shader weird. precalculate normals on cpu , pass them vertex attribute.
v = v.nor();
the nor
function not think does. normalizes vector unit length. (vector normalization =/= surface normal calculation). calculate normal must calculate cross product of local slope vectors.
java opengl opengl-es lighting terrain
Comments
Post a Comment