glsl

Blending anti-aliased circles with regl

孤街醉人 提交于 2019-12-04 10:55:35
I'm rendering circles using regl, and have three goals: The canvas should be transparent, showing HTML content behind it. Circles should be antialiased smoothly. Overlapping circles should look reasonable (blend colors, no corners showing) So far, I have this: Glitch code and demo . UPDATE: The demo links now reflect the working, accepted answer. Code below is unchanged. index.js const regl = require('regl'); const glsl = require('glslify'); const vertexShader = glsl.file('../shaders/vertex.glsl'); const fragmentShader = glsl.file('../shaders/fragment.glsl'); // Create webgl context and clear.

Multi-pass shaders in OpenGL ES 2.0

☆樱花仙子☆ 提交于 2019-12-04 10:40:49
First - Does subroutines require GLSL 4.0+? So it unavailable in GLSL version of OpenGL ES 2.0? I quite understand what multi-pass shaders are. Well what is my picture: Draw group of something (e.g. sprites) to FBO using some shader. Think of FBO as big texture for big screen sized quad and use another shader, which, for example, turn texture colors to grayscale. Draw FBO textured quad to screen with grayscaled colors. Or is this called else? So multi-pass = use another shader output to another shader input? So we render one object twice or more? How shader output get to another shader input?

OpenGL point sprites rotation in fragment shader

假如想象 提交于 2019-12-04 09:39:46
问题 I'm following this tutorial to learn something more about OpenGL and in particular point sprites. But I'm stuck on one of the exercises at the end of the page: Try to rotate the point sprites 45 degrees by changing the fragment shader. There are no hints about this sort of thing in the chapter, nor in the previous ones. And I didn't find any documentation on how to do it. These are my vertex and fragment shaders: Vertex Shader #version 140 attribute vec2 coord2d; varying vec4 f_color; uniform

Is it possible to thicken a quadratic Bézier curve using the GPU only?

筅森魡賤 提交于 2019-12-04 09:12:54
问题 I draw lots of quadratic Bézier curves in my OpenGL program. Right now, the curves are one-pixel thin and software-generated, because I'm at a rather early stage, and it is enough to see what works. Simply enough, given 3 control points ( P 0 to P 2 ), I evaluate the following equation with t varying from 0 to 1 (with steps of 1/8) in software and use GL_LINE_STRIP to link them together: B( t ) = (1 - t ) 2 P 0 + 2(1 - t ) t P 1 + t 2 P 2 Where B , obviously enough, results in a 2-dimensional

Is it safe to use the block index as the binding point for UniformBufferObject, ShaderStorageBufferObjects, etc?

和自甴很熟 提交于 2019-12-04 08:18:50
I'm curious about the *BlockBinding argument used in several of OpenGLs buffer object related functions. For example the uniformBlockBinding parameter in glUniformBlockBinding , storageBlockBinding​ in glShaderStorageBlockBinding , and the corresponding index parameter in glBindBufferRange and glBindBufferBase . I know that calls to glUniformBlockBinding and glShaderStorageBlockBinding aren't necessary if binding points are set in the shaders using layout qualifiers such as: layout (binding = 0) blockName {...} and from testing around on my machine I've noticed three things: 1) setting binding

Rotate Normals in Shader

爷,独闯天下 提交于 2019-12-04 08:13:03
I have a scene with several models with individual positions and rotations. Given normals, the shaders apply simple bidirectional lighting to each pixel. That is my vertex shader. #version 150 in vec3 position; in vec3 normal; in vec2 texcoord; out vec3 f_normal; out vec2 f_texcoord; uniform mat4 model; uniform mat4 view; uniform mat4 proj; void main() { mat4 mvp = proj * view * model; f_normal = normal; f_texcoord = texcoord; gl_Position = mvp * vec4(position, 1.0); } And here is the fragment shader. #version 150 in vec3 f_normal; in vec2 f_texcoord; uniform sampler2D tex; vec3 sun = vec3(0.5

Organizing GLSL shaders in OpenGL engine

ぐ巨炮叔叔 提交于 2019-12-04 07:42:16
问题 Which is better ? To have one shader program with a lot of uniforms specifying lights to use, or mappings to do (e.g. I need one mesh to be parallax mapped, and another one parallax/specular mapped). I'd make a cached list of uniforms for lazy transfers, and just change a couple of uniforms for every next mesh if it needs to do so. To have a lot of shader programs for every needed case, each one with small amount of uniforms, and do the lazy bind with glUseProgram for every mesh if it needs

glsl shader compilation issue at runtime

陌路散爱 提交于 2019-12-04 07:35:24
I'm working on a project that uses OpenGL 4.0 shaders. I have to supply the call to glShaderSource() with an array of char arrays, which represents the source of the shader. The shader compilation is failing, with the following errors: (0) : error C0206: invalid token "<null atom>" in version line (0) : error C0000: syntax error, unexpected $end at token "<EOF>" Here's my (hello world) shader - straight from OpenGL 4.0 shading language cookbook #version 400 in vec3 VertexPosition; in vec3 VertexColor; out vec3 Color; void main() { Color = VertexColor; gl_Position = vec4( VertexColor, 1.0 ); }

OpenGL Getting Shader Attached to Program

…衆ロ難τιáo~ 提交于 2019-12-04 06:57:25
Is there a way to access the shaders attached to a program? That is, given a program, can I do something like: vertexShader = getVertexShaderFromProgram(program); (I would like to log shader compilation status within my function that validates my program, but I only keep a reference to the program, not the shaders.) glGetAttachedShaders() to get the names of the shaders attached to the given program object. glGetShaderiv( ..., GL_SHADER_TYPE, ... ) to get the type (vertex, geometry, fragment) of shader. glGetShaderiv( ..., GL_SHADER_SOURCE_LENGTH, ... ) on each shader name to figure out how

'error: sampler arrays indexed with non-constant expressions are forbidden in GLSL 1.30 and later' in fragment shader

人走茶凉 提交于 2019-12-04 06:47:52
问题 I am writing the following fragment shader for a game engine: #version 330 core layout (location = 0) out vec4 color; uniform vec4 colour; uniform vec2 light_pos; in DATA { vec4 position; vec2 uv; float tid; vec4 color; } fs_in; uniform sampler2D textures[32]; void main() { float intensity = 1.0 / length(fs_in.position.xy - light_pos); vec4 texColor = fs_in.color; if(fs_in.tid > 0.0){ int tid = int(fs_in.tid + 0.5); texColor = texture(textures[tid], fs_in.uv); } color = texColor * intensity;