glsl

glsl sampler2DShadow and shadow2D clarification

不想你离开。 提交于 2019-11-27 00:58:18
问题 Quick background of where I'm at (to make sure we're on the same page, and sanity check if I'm missing/assuming something stupid): Goal: I want to render my scene with shadows, using deferred lighting and shadowmaps. Struggle: finding clear and consistent documentation regarding how to use shadow2D and sampler2DShadow. Here's what I'm currently doing: In the fragment shader of my final rendering pass (the one that actually calculates final frag values), I have the MVP matrices from the pass

volume rendering (using glsl) with ray casting algorithm

对着背影说爱祢 提交于 2019-11-27 00:30:44
问题 I am learning volume rendering using ray casting algorithm. I have found a good demo and tuturial in here. but the problem is that I have a ATI graphic card instead of nVidia which make me can't using the cg shader in the demo, so I want to change the cg shader to glsl shader. I have gone through the red book (7 edition) of OpenGL, but not familiar with glsl and cg. does anyone can help me change the cg shader in the demo to glsl? or is there any materials to the simplest demo of volume

Why does my OpenGL Phong shader behave like a flat shader?

点点圈 提交于 2019-11-26 23:56:42
问题 I've been learning OpenGL for the past couple of weeks and I've run into some trouble implementing a Phong shader. It appears to do no interpolation between vertexes despite my use of the smooth qualifier. Am I missing something here? To give credit where credit is due, the code for the vertex and fragment shaders cribs heavily from the OpenGL SuperBible Fifth Edition. I would highly recommend this book! Vertex Shader: #version 330 in vec4 vVertex; in vec3 vNormal; uniform mat4 mvpMatrix; //

How can I do these image processing tasks using OpenGL ES 2.0 shaders?

一世执手 提交于 2019-11-26 23:30:42
How can I perform the following image processing tasks using OpenGL ES 2.0 shaders? Colorspace transform ( RGB/YUV/HSL/Lab ) Swirling of the image Converting to a sketch Converting to an oil painting I just added filters to my open source GPUImage framework that perform three of the four processing tasks you describe (swirling, sketch filtering, and converting to an oil painting). While I don't yet have colorspace transforms as filters, I do have the ability to apply a matrix to transform colors. As examples of these filters in action, here is a sepia tone color conversion: a swirl distortion:

Packing float into vec4 - how does this code work?

泪湿孤枕 提交于 2019-11-26 22:53:55
问题 I am trying to study shadow mapping in WebGL. I see same piece of shader code copied in various libraries and examples that achieve this. However nowhere did I find the explanation of how it works. The idea is to save a depth value (a single float) into the color buffer (vec4). There is a pack function that saves float to vec4 and unpack function that retrieves the float from vec4. vec4 pack_depth(const in float depth) { const vec4 bit_shift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);

Multiple textures in GLSL - only one works

情到浓时终转凉″ 提交于 2019-11-26 22:53:33
问题 My problem is getting more than one texture accessible in a GLSL shader. Here's what I'm doing: Shader: uniform sampler2D sampler0; uniform sampler2D sampler1; uniform float blend; void main( void ) { vec2 coords = gl_TexCoord[0]; vec4 col = texture2D(sampler0, coords); vec4 col2 = texture2D(sampler1, coords); if (blend > 0.5){ gl_FragColor = col; } else { gl_FragColor = col2; } }; So, I simply choose between the two color values based on a uniform variable. Simple enough (this is a test),

How do you get the modelview and projection matrices in OpenGL?

拈花ヽ惹草 提交于 2019-11-26 22:38:48
问题 I am trying to use the OpenGL Shading Language (GLSL) version 1.5 to make vertex and geometry shaders. I have learned that in GLSL version 1.5, the built-in variables like gl_ModelViewProjectionMatrix are deprecated so you have to pass them in manually. If I have already set the modelview and projection matrices (using gluLookAt and gluPerspective for example) then how do I get the matrices to pass into the vertex and geometry shaders? I've done some searching and some sites seem to mention a

Proper way to delete GLSL shader?

﹥>﹥吖頭↗ 提交于 2019-11-26 22:34:55
问题 My code approaches GLSL shader management in the way, that it creates each shader and the associated program and deletes each shader and program. I recently read http://www.opengl.org/wiki/GLSL_Object and there it is stated that: The shader object, due to being attached to the program object, will continue to exist even if you delete the shader object. It will only be deleted by the system when it is no longer attached to any program object (and when the user has asked to delete it, of course

How to calculate Tangent and Binormal?

梦想与她 提交于 2019-11-26 21:31:40
Talking about bump mapping, specular highlight and these kind of things in OpenGL Shading Language (GLSL) I have: An array of vertices (e.g. {0.2,0.5,0.1, 0.2,0.4,0.5, ...}) An array of normals (e.g. {0.0,0.0,1.0, 0.0,1.0,0.0, ...}) The position of a point light in world space (e.g. {0.0,1.0,-5.0}) The position of the viewer in world space (e.g. {0.0,0.0,0.0}) (assume the viewer is in the center of the world) Now, how can I calculate the Binormal and Tangent for each vertex? I mean, what is the formula to calculate the Binormals, what I have to use based on those informations? And about the

Passing a list of values to fragment shader

戏子无情 提交于 2019-11-26 21:21:40
I want to send a list of values into a fragment shader. It is a possibly large (couple of thousand items long) list of single precision floats. The fragment shader needs random access to this list and I want to refresh the values from the CPU on each frame. I'm considering my options on how this could be done: As a uniform variable of array type ("uniform float x[10];"). But there seems to be limits here, on my GPU sending more than a few hundred values is very slow and also I'd have to hard-code the upper limit in the shader when I'd rather would like to change that in runtime. As a texture