glsl

Why would it be beneficial to have a separate projection matrix, yet combine model and view matrix?

隐身守侯 提交于 2019-12-20 08:24:57
问题 When you are learning 3D programming, you are taught that it's easiest think in terms of 3 transformation matrices: The Model Matrix . This matrix is individual to every single model and it rotates and scales the object as desired and finally moves it to its final position within your 3D world. "The Model Matrix transforms model coordinates to world coordinates". The View Matrix . This matrix is usually the same for a large number of objects (if not for all of them) and it rotates and moves

How to calculate the normal matrix?

不打扰是莪最后的温柔 提交于 2019-12-20 08:19:11
问题 I have some trouble with my normal matrix. vs.glsl #version 440 in vec3 vPosition; in vec3 vNormal; out vec4 eyeCordFs; out vec4 eyeNormalFs; uniform mat4 model; uniform mat4 view; uniform mat4 proj; void main() { mat4 modelView = view * model; mat4 normalMatrix = view * transpose(inverse(model)); vec4 eyeNorm = normalize(normalMatrix * vec4(vNormal, 0.0)); vec4 eyeCord= modelView * vec4(vPosition, 1.0); eyeCordFs = eyeCord; eyeNormalFs = eyeNorm; gl_Position = proj * modelView * vec4(

In OpenGL is there a way to get a list of all uniforms & attribs used by a shader program?

北战南征 提交于 2019-12-20 07:58:35
问题 I'd like to get a list of all the uniforms & attribs used by a shader program object. glGetAttribLocation() & glGetUniformLocation() can be used to map a string to a location, but what I would really like is the list of strings without having to parse the glsl code. Note: In OpenGL 2.0 glGetObjectParameteriv() is replaced by glGetProgramiv() . And the enum is GL_ACTIVE_UNIFORMS & GL_ACTIVE_ATTRIBUTES . 回答1: Variables shared between both examples: GLint i; GLint count; GLint size; // size of

Fragment shader inexplicable bahaviour

℡╲_俬逩灬. 提交于 2019-12-20 07:16:59
问题 I have written a C++ program where I draw a teapot and apply lighting. It is itself simple, but I also use shaders. Simple I'm new with GLSL I just tried a simple fragment shader, but the screen output is inexplicable. In this file I initialize glew in the init method, where I also compile the vertex and fragment shader. They're in the "vertex_shader" and "fragment_shader" files. The thing you may not recognize is what's Light and Material. They're just some structs containing all info about

Fragment shader on plane with modified vertices

冷暖自知 提交于 2019-12-20 06:57:51
问题 I have a PlaneGeometry and I'm randomly animating the vertices in order to create random spikes. I use this FragmentShader : void main() { vec3 light = vec3(cos(time),sin(time),1.0); light = normalize(light); float dProd = max(0.0, dot(vNormal, light)); gl_FragColor = vec4(dProd,dProd,dProd,1.0); } I expected to have some faces of each spike colored in black, but instead I got a solid color. I placed a Sphere on my plane and applied the same shader: When I turn the wireframe OFF : Not sure I

Fragment shader on plane with modified vertices

一曲冷凌霜 提交于 2019-12-20 06:57:33
问题 I have a PlaneGeometry and I'm randomly animating the vertices in order to create random spikes. I use this FragmentShader : void main() { vec3 light = vec3(cos(time),sin(time),1.0); light = normalize(light); float dProd = max(0.0, dot(vNormal, light)); gl_FragColor = vec4(dProd,dProd,dProd,1.0); } I expected to have some faces of each spike colored in black, but instead I got a solid color. I placed a Sphere on my plane and applied the same shader: When I turn the wireframe OFF : Not sure I

Fragment shader on plane with modified vertices

核能气质少年 提交于 2019-12-20 06:56:55
问题 I have a PlaneGeometry and I'm randomly animating the vertices in order to create random spikes. I use this FragmentShader : void main() { vec3 light = vec3(cos(time),sin(time),1.0); light = normalize(light); float dProd = max(0.0, dot(vNormal, light)); gl_FragColor = vec4(dProd,dProd,dProd,1.0); } I expected to have some faces of each spike colored in black, but instead I got a solid color. I placed a Sphere on my plane and applied the same shader: When I turn the wireframe OFF : Not sure I

Max Varying Vectors and Floats for GLES 2.0

夙愿已清 提交于 2019-12-20 04:13:30
问题 I am trying to figure out what is the maximum number of varying vectors and uniforms I can use on a device that is OpenGL ES 2.0 compatible. I am trying to understand how MAX_VARYING_VECTORS works. So if MAX_VARYING_VECTORS is 8, does that mean I can store 8 * 4 bytes of data for varyings or does it mean that I can only define 8 varyings irrespective of the data type? 回答1: MAX_VARYING_VECTORS is measured in units of 4-member float vectors ( vec4 ). So with the minimum guaranteed value of 8,

Scenekit SCNShadable accessing _surface.diffuseTexcoord paints the object white

我的未来我决定 提交于 2019-12-20 04:12:30
问题 I'm experiencing odd behaviour when trying to extend a PBR material from scenekit. All i want to do is read a texture, map it using the first uv channel (same as normal). As soon as i mention _surface.diffuseTexcoord , _surface.diffuse seems to turn to white. It doesn't seem to be constant ( _output.rgb = vec3(1.) ) but rather color white is passed through the lighting pipeline. let myShader = "#pragma arguments\n" + "sampler uMaskTex;\n" + "uniform sampler2D uMaskTex;\n" + "#pragma body\n" +

Scenekit SCNShadable accessing _surface.diffuseTexcoord paints the object white

故事扮演 提交于 2019-12-20 04:12:13
问题 I'm experiencing odd behaviour when trying to extend a PBR material from scenekit. All i want to do is read a texture, map it using the first uv channel (same as normal). As soon as i mention _surface.diffuseTexcoord , _surface.diffuse seems to turn to white. It doesn't seem to be constant ( _output.rgb = vec3(1.) ) but rather color white is passed through the lighting pipeline. let myShader = "#pragma arguments\n" + "sampler uMaskTex;\n" + "uniform sampler2D uMaskTex;\n" + "#pragma body\n" +