glsl

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

有些话、适合烂在心里 提交于 2019-12-03 03:10:35
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 vector. This approach worked 'well enough', since even my largest curves don't need much more than 8

Colorize sprites from grayscale to color

别来无恙 提交于 2019-12-03 03:07:18
I have a lot of same graphics but different colors. I want to optimize it by colorizing from grayscale image. Also, I would like to change it color on a fly, during gameplay for a live sprite object. Also gradually change color values from one color type to another. Don't know it it useful - Image-Transformation-Grayscale-to-Color. To tone a grayscale sprite, can be done by a simple fragment shader, which multiplies the color of the texel of the texture, with a tint color. This causes that a constant color is varayed in the brightness by the grayscale texture. All the following shaders

Gaussian Blur - standard deviation, radius and kernel size

ⅰ亾dé卋堺 提交于 2019-12-03 03:01:27
I've implemented a gaussian blur fragment shader in GLSL. I understand the main concepts behind all of it: convolution, separation of x and y using linearity, multiple passes to increase radius... I still have a few questions though: What's the relationship between sigma and radius? I've read that sigma is equivalent to radius, I don't see how sigma is expressed in pixels. Or is "radius" just a name for sigma, not related to pixels? How do I choose sigma? Considering I use multiple passes to increase sigma, how do I choose a good sigma to obtain the sigma I want at any given pass? If the

How to debug a GLSL shader?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to debug a GLSL program but I don't know how to output intermediate result. Is it possible to make some debug traces (like with printf) with GLSL ? 回答1: You can't easily communicate back to the CPU from within GLSL. Using glslDevil or other tools is your best bet. A printf would require trying to get back to the CPU from the GPU running the GLSL code. Instead, you can try pushing ahead to the display. Instead of trying to output text, output something visually distinctive to the screen. For example you can paint something a specific

How to debug GLSL Fragment shader (Program Linking error after code change)

匿名 (未验证) 提交于 2019-12-03 02:43:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: (original Title) Please help me debug my glsl lighting shader so that it will compile! This is my first time debugging glsl Hello I am VERY new to opengl. I am working on modifying another shader I found online. The version I found online works just great, however somewhere along in my code I made a mistake while editing. The problem is I have combed through it and can not see it, I was hoping for some fresh eyes. To be clear it is not that what is being drawn is incorrect, it flat out wont compile #version 330 core struct Material {

GLSL Half (floating point) attribute type

匿名 (未验证) 提交于 2019-12-03 02:43:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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? 回答1: In the absence of a MCVE demonstrating otherwise I assume you tried something like: half float aHalfFloat; However, " half " is a reserved keyword in #version 410 : OpenGL Shading Language 4.10 Specification , page 15 (emphasis mine): The following are the

glsl infinity constant

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does GLSL have any pre-defined constants for +/-infinity or NaN? I'm doing this as a workaround but I wonder if there is a cleaner way: // GLSL FRAGMENT SHADER #version 410 <snip> const float infinity = 1. / 0.; void main () { <snip> } I am aware of the isinf function but I need to assign infinity to a variable so that does not help me. 回答1: Like Nicol mentioned, there are no pre-defined constants. However, from OpenGL 4.1 on, your solution is at least guaranteed to work and correctly generate an infinite value. See for example in glsl 4.4 :

Simple GLSL convolution shader is atrociously slow

不羁岁月 提交于 2019-12-03 02:27:41
问题 I'm trying to implement a 2D outline shader in OpenGL ES2.0 for iOS. It is insanely slow. As in 5fps slow. I've tracked it down to the texture2D() calls. However, without those any convolution shader is undoable. I've tried using lowp instead of mediump, but with that everything is just black, although it does give another 5fps, but it's still unusable. Here is my fragment shader. varying mediump vec4 colorVarying; varying mediump vec2 texCoord; uniform bool enableTexture; uniform sampler2D

GCC, stringification, and inline GLSL?

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'd like to declare GLSL shader strings inline using macro stringification: #define STRINGIFY ( A ) #A const GLchar * vert = STRINGIFY ( #version 120\n attribute vec2 position ; void main () { gl_Position = vec4 ( position , 0.0 , 1.0 ); } ); This builds and runs fine using VS2010 but fails to compile on gcc with: error : invalid preprocessing directive #version Is there a way to use stringification like this in a portable manner? I'm trying to avoid per-line quotes: const GLchar * vert = "#version 120\n" "attribute vec2 position;"

GLSL/OpenGL shader tessellation flickering and failure

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I just started with OpenGL tessellation and have run into a bit a trouble. I am tessellating series of patches formed by one vertex each. These vertices/patches are structured in a gridlike fashion to later form a terrain generated by Perlin Noise. The problem I have run into is that starting from the second patch, and every 5 th patch after that, sometimes have a lot of tessellation (not the way i configured) but most of the time it doesn't get tessellated at all. Like so: The two white circles mark the highly/over tessellated