glsl

SSAO artefacts in Three

北慕城南 提交于 2019-12-01 10:39:50
I'm really struggling to fix an issue with my SSAO shader and could desperately use some help. Basically the shader seems to work on some objects, but looks really bad on others. From the below you can see the sphere looks correct, but the cube seems to be doing occlusion on normals that it shouldn't. Here is a screenshot: I am basing my shaders off of this tutorial: http://devmaster.net/posts/3095/shader-effects-screen-space-ambient-occlusion In my render chain I render 2 render targets which get used in some post process effects later on. One of them stores the position and depth. The other

How to normalize image coordinates for texture space in OpenGL?

爷,独闯天下 提交于 2019-12-01 10:36:24
Say I have an image of size 320x240 . Now, sampling from an sampler2D with integer image coordinates ux, uy I must normalize for texture coordinates in range [0, size] (size may be width or height). Now, I wonder if I should normalize like this texture(image, vec2(ux/320.0, uy/240.0)) or like this texture(image, vec2(ux/319.0, uy/239.0)) Because ux = 0 ... 319 and uy = 0 ... 239 . The latter one will actually cover the whole range of [0, 1] correct? That means 0 corresponds to the e.g. left-most pixels and 1 corresponds to the right most pixels, right? Also I want to maintain filtering, so I

How do I pass vertex color through the shader pipeline?

这一生的挚爱 提交于 2019-12-01 09:54:46
问题 I am trying to pass vertex color through the vertex, geometry and fragment shader: glBegin(GL_POINTS); glVertex3f(-2.0f, 0.0f, 0.0); glColor3f(0.0,1.0,0.0); glVertex3f(+2.0f, 0.0f, 0.0); glColor3f(0.0,0.0,1.0); glEnd(); vertex shader: # version 130 varying vec4 colorv; void main() { // pass trough: gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; colorv = gl_Color; } geometry shader: #version 150 layout(points) in; // origo of cell layout(points, max_vertices = 1) out;

GLSL Shader will not render color from uniform variable

不想你离开。 提交于 2019-12-01 09:27:07
I am currently building an app for Android, but have run into some problems with a shader that refuses to render. Consider the following fragment shader: uniform vec4 color; void main(){ gl_FragColor = vec4(1.0); } This shader works fine for drawing an object in a solid color (white in this case). The uniform vector color is optimized away, and cannot be found with glGetUniformLocation() (returns -1). Trying to get the color from the uniform variable can be done like so: uniform vec4 color; void main(){ gl_FragColor = color; } However, when I use this, nothing renders. The shader is created

Should layout quantifier (location) differ between uniform/in/out?

南笙酒味 提交于 2019-12-01 09:18:48
I am now setting up layout quantifier (location) for my GLSL shaders. And this question hits me whether those quantifier ID need differ with each other. Does it have to be: layout (location = 0) uniform vec3 v1; layout (location = 1) in vec3 v2; layout (location = 2) uniform vec3 v3; layout (location = 3) in vec3 v4; Or it can be (as the location can be specified as uniforms or inputs): layout (location = 0) uniform vec3 v1; layout (location = 0) in vec3 v2; layout (location = 1) uniform vec3 v3; layout (location = 1) in vec3 v4; Thanks. While for vertex shader attributes the layout location

How vertex and fragment shaders communicate in OpenGL?

人盡茶涼 提交于 2019-12-01 08:54:46
问题 I really do not understand how fragment shader works. I know that vertex shader runs once per vertices fragment shader runs once per fragment Since fragment shader does not work per vertex but per fragment how can it send data to the fragment shader? The amount of vertices and amount of fragments are not equal. How can it decide which fragment belong to which vertex? 回答1: To make sense of this, you'll need to consider the whole render pipeline. The outputs of the vertex shader (besides the

How to draw from the inside of the light geometry in deferred shading

余生颓废 提交于 2019-12-01 08:30:42
问题 I'm trying to implement a deferred shader with OpenGL and GLSL and I'm having trouble with the light geometry. These are the steps I'm taking: Bind multitarget framebuffer Render color, position, normal and depth Unbind framebuffer Enable blend Disable depth testing Render every light Enable depth testing Disable blend Render to screen But since I'm only rendering the front face, when I'm inside a light it disappears completely, rendering the back face does not work, since I would get double

How to normalize image coordinates for texture space in OpenGL?

旧城冷巷雨未停 提交于 2019-12-01 07:42:33
问题 Say I have an image of size 320x240 . Now, sampling from an sampler2D with integer image coordinates ux, uy I must normalize for texture coordinates in range [0, size] (size may be width or height). Now, I wonder if I should normalize like this texture(image, vec2(ux/320.0, uy/240.0)) or like this texture(image, vec2(ux/319.0, uy/239.0)) Because ux = 0 ... 319 and uy = 0 ... 239 . The latter one will actually cover the whole range of [0, 1] correct? That means 0 corresponds to the e.g. left

Should layout quantifier (location) differ between uniform/in/out?

随声附和 提交于 2019-12-01 07:22:45
问题 I am now setting up layout quantifier (location) for my GLSL shaders. And this question hits me whether those quantifier ID need differ with each other. Does it have to be: layout (location = 0) uniform vec3 v1; layout (location = 1) in vec3 v2; layout (location = 2) uniform vec3 v3; layout (location = 3) in vec3 v4; Or it can be (as the location can be specified as uniforms or inputs): layout (location = 0) uniform vec3 v1; layout (location = 0) in vec3 v2; layout (location = 1) uniform vec3

GLSL Shader will not render color from uniform variable

梦想的初衷 提交于 2019-12-01 07:04:55
问题 I am currently building an app for Android, but have run into some problems with a shader that refuses to render. Consider the following fragment shader: uniform vec4 color; void main(){ gl_FragColor = vec4(1.0); } This shader works fine for drawing an object in a solid color (white in this case). The uniform vector color is optimized away, and cannot be found with glGetUniformLocation() (returns -1). Trying to get the color from the uniform variable can be done like so: uniform vec4 color;