glsl

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

拥有回忆 提交于 2019-12-02 13:59: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 . NeARAZ Variables shared between both examples: GLint i; GLint count; GLint size; // size of the variable GLenum type; // type of the variable (float, vec3 or mat4, etc) const GLsizei bufSize =

How does the fragment shader know what variable to use for the color of a pixel?

微笑、不失礼 提交于 2019-12-02 13:54:17
I see a lot of different fragment shaders, #version 130 out vec4 flatColor; void main(void) { flatColor = vec4(0.0,1.0,0.0,0.5); } And they all use a different variable for the "out color" (in this case flatColor ). So how does OpenGL know what you're trying to do? I'm guessing this works because flatColor is the only variable defined as out , but you're allowed to add more out variables aren't you? Or would that just crash? Actually, as a test, I just ran this: #version 330 in vec2 TexCoord0; uniform sampler2D TexSampler; out vec4 x; out vec4 y; void main() { y = texture2D(TexSampler,

Fragment shader on plane with modified vertices

落花浮王杯 提交于 2019-12-02 11:52:43
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 understand what's happening on the plane?! I thought that since each spike has different normals, they

Fragment shader inexplicable bahaviour

假如想象 提交于 2019-12-02 11:50:55
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 the lights. I've tested these struct so I'm sure the work as expected. When I declare material

OpenGL ES write depth data to color

余生颓废 提交于 2019-12-02 11:19:29
I'm trying to implement DepthBuffer-like functionality using OpenGL ES on Android. In other words I'm trying to get the 3D point on surface that is rendered on point [x, y] on the user device. In order to make that I need to be able to read the distance of the fragment at that given point. Answer in different circumstances: When using normal OpenGL you could achieve this by creating FrameBuffer and then attach either RenderBuffer or Texture with depth component to it. Both of those approaches use glReadPixels , with internal format of GL_DEPTH_COMPONENT to retrieve the data from the buffer

GLSL point light shader moving with camera

风格不统一 提交于 2019-12-02 10:16:14
问题 I've been trying to make a basic static point light using shaders for an LWJGL game, but it appears as if the light is moving as the camera's position is being translated and rotated. These shaders are slightly modified from the OpenGL 4.3 guide, so I'm not sure why they aren't working as intended. Can anyone explain why these shaders aren't working as intended and what I can do to get them to work? Vertex Shader: varying vec3 color, normal; varying vec4 vertexPos; void main() { color = vec3

THREE.JS GLSL sprite always front to camera

本小妞迷上赌 提交于 2019-12-02 09:29:11
I'm creating a glow effect for car stop lights and found a shader that makes it possible to always face the camera: uniform vec3 viewVector; uniform float c; uniform float p; varying float intensity; void main() { vec3 vNormal = normalize( normalMatrix * normal ); vec3 vNormel = normalize( normalMatrix * -viewVector ); intensity = pow( c - dot(vNormal, vNormel), p ); gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); } This solution is quite simple and almost works. It reacts to camera movement and it would be great. BUT this element is a child of a car. The car itself

glsl & perspective correction of varying values

核能气质少年 提交于 2019-12-02 07:58:54
问题 is every varying vertex value (or in newer versions of glsl values that go "out" of a vertex shader) interpolated by the rasterizer using perspective correction? is this hardware dependant? when clipping occurs, how are the values at the clipping vertices calculated? I try to undo perspective correction and notice strange behaviour for polygons that are clipped and I would like to understand better what is going on behind the scenes. 回答1: Pre-GL 3.0, the only way to affect perspective-correct

GLSL Half (floating point) attribute type

别说谁变了你拦得住时间么 提交于 2019-12-02 07:48:52
I have been trying to get a 16bit float (half-floating point) as an attribute into my GLSL vertex shader. It won't let me compile saying: error C7506: OpenGL does not define the global type half but my #version is 410 and so it should support half? Am I missing something obvious? solidpixel OpenGL and OpenGL ES define two concurrent types of precision. Storage precision in buffers Minimum computational precision used in shaders. Storage precision is defined by your vertex attribute upload, such as GL_FLOAT or GL_HALF_FLOAT . This will be the precision used to store the data in memory. Usage

How to implemen shadertoy code into three.js - clarifying the details

别等时光非礼了梦想. 提交于 2019-12-02 07:29:12
问题 So here is a previous question: How to implement a ShaderToy shader in three.js Tried to implement the steps from the link above into this code unsucessfully: three.js/blob/master/examples/webgl_shader.html So I replaced the original vertex shader and the origianl fragment shader so I got this code: <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * mvPosition;