opengl es 2.0 varying interpolation - Raspberry Pi Forums
normals vertex shader fragment shader through varying.
vertex shader code:
attribute vec4 a_position;
attribute vec3 a_normal;
varying vec3 v_normal;
uniform mat4 u_world;
uniform mat4 u_view;
void main() {
gl_position = u_view * u_world * a_position;
v_normal = u_view * u_world * a_normal;
}
fragment shader code:
varying vec3 v_normal;
void main() {
gl_fragcolor = vec4(abs(v_normal.xy), 0.0, 1.0);
// absolute check correctness visualizing
// fbo texture (underlying fragment). idea cube,
// seen front ( normal: 0.0, 0.0, -1.0) should not visible
// on underlying texture.
}
here cube mesh:
# cube.obj
#
g cube
v 0.0 0.0 0.0
v 0.0 0.0 1.0
v 0.0 1.0 0.0
v 0.0 1.0 1.0
v 1.0 0.0 0.0
v 1.0 0.0 1.0
v 1.0 1.0 0.0
v 1.0 1.0 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
vn 1.0 0.0 0.0
vn -1.0 0.0 0.0
f 1//2 7//2 5//2
f 1//2 3//2 7//2
f 1//6 4//6 3//6
f 1//6 2//6 4//6
f 3//3 8//3 7//3
f 3//3 4//3 8//3
f 5//5 7//5 8//5
f 5//5 8//5 6//5
f 1//4 5//4 6//4
f 1//4 6//4 2//4
f 2//1 6//1 8//1
f 2//1 8//1 4//1
oddly enough, visible. see attached file screenshot, visualise (absolute) x value of 2 triangles. normal given (0.0, 0.0, -1.0) there should not x value , therefore whole texture should black.
opengl es specification: https://www.khronos.org/registry/gles/s ... 1.0.17.pdf
says under "4.3.5 varying" varyings interpolated between vertices of given primitive.
in case primitive gl_triangles , supplying same normal vertices of each triangle. therefore expect "v_normal" in fragment shader have same value a_normal in vertex shader (modulo the view * world projection). not seem case.
if edit cube mesh , remove faces first 2 - ones can visible on screen - expected result: black texture.
leads me believe varying interpolation not local current primitive computed somehow differently. how , why not sure though.
comments or insights welcome.
"if edit cube mesh , remove faces first 2 - ones can visible on screen - expected result: black texture. "
colour comming face ? isn't obvious me why isn't being draw.
petero
colour comming face ? isn't obvious me why isn't being draw.
petero
raspberrypi
Comments
Post a Comment