glsl

Problems converting YV12 to RGB through GLSL

99封情书 提交于 2019-11-28 03:49:27
问题 I'm trying to accomplish YV12 to RGB conversion mentioned in this post with GLSL shaders. My application loads a raw YV12 frame from the disk and tries to perform the conversion using GLSL shaders. However, the resulting image is flipped vertically and has some color issues. I think the problem may be that the image is being read as an array of char (1 byte) and then converted to an array of GLushort (2 bytes). What do you think? This is how the raw YUV frame looks like: and the raw frame

From RGB to HSV in OpenGL GLSL

风流意气都作罢 提交于 2019-11-28 03:20:54
I need to pass from RGB color space to HSV .. I searched in internet and found two different implementations, but those give me different results: A: precision mediump float; vec3 rgb2hsv(float r, float g, float b) { float h = 0.0; float s = 0.0; float v = 0.0; float min = min( min(r, g), b ); float max = max( max(r, g), b ); v = max; // v float delta = max - min; if( max != 0.0 ) s = delta / max; // s else { // r = g = b = 0 // s = 0, v is undefined s = 0.0; h = -1.0; return vec3(h, s, v); } if( r == max ) h = ( g - b ) / delta; // between yellow & magenta else if( g == max ) h = 2.0 + ( b -

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

荒凉一梦 提交于 2019-11-28 03:06:16
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; // mvp = ModelViewProjection uniform mat4 mvMatrix; // mv = ModelView uniform mat3 normalMatrix; uniform

Variable array index not possible in webgl shaders?

此生再无相见时 提交于 2019-11-28 02:46:55
问题 As the title says, I can't do vector_array[foo] (assuming foo is in-range and integer) in webgl vertex shaders, correct? Are textures the best alternative, or is there a workaround or some better way to mimick a lookup table? 回答1: http://www.khronos.org/registry/webgl/specs/latest/#DYNAMIC_INDEXING_OF_ARRAYS "WebGL only allows dynamic indexing with constant expressions, loop indices or a combination. The only exception is for uniform access in vertex shaders, which can be indexed using any

Packing float into vec4 - how does this code work?

∥☆過路亽.° 提交于 2019-11-27 20:08:44
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); const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0); vec4 res = fract(depth * bit_shift);

Multiple textures in GLSL - only one works

非 Y 不嫁゛ 提交于 2019-11-27 20:07:41
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), but instead of the expected behavior, I get all black when blend <= 0.5 . OpenGL code: m_sampler0location

What is the correct file extension for GLSL shaders? [closed]

倾然丶 夕夏残阳落幕 提交于 2019-11-27 19:45:04
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 months ago . I'm learning glsl shading and I've come across different file formats. I've seen people giving their vertex and fragment shaders .vert and .frag extensions. But I've also seen .vsh and .fsh extensions, and even both shaders together in a single .glsl file. So I'm wondering

What is the precision of highp floats in GLSL ES 2.0 (for iPhone/iPod touch/iPad)?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 19:41:06
I have a shader that ideally needs 28 bits of mantissa, though I can use less and degrade performance. How can I determine what the precision of 'highp' is in OpenGL ES? It's probably an FP24, with 16bits mantissa, but I cannot figure out for sure or how to ask OpenGL. Any ideas? You want GetShaderPrecisionFormat to query the range and precision of of shader types int range[2], precision; glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, range, &precision); will give you the range and precision of highp float. From the OpenGL ES Shading Language reference : highp - 16-bit, floating

iOS GLSL. Is There A Way To Create An Image Histogram Using a GLSL Shader?

走远了吗. 提交于 2019-11-27 19:10:15
Elsewhere on StackOverflow a question was asked regarding a depthbuffer histogram - Create depth buffer histogram texture with GLSL . I am writing an iOS image-processing app and am intrigued by this question but unclear on the answer provided. So, is it possible to create an image histogram using the GPU via GLSL? Yes, it is. It's not clearly the best approach, but it's indeed the best one available in iOS, since OpenCL is not supported. You'll lose elegance, and your code will probably not as straightforward, but almost all OpenCL features can be achieved with shaders. If it helps, DirectX11

Drawing a border on a 2d polygon with a fragment shader

倖福魔咒の 提交于 2019-11-27 18:12:02
I have some simple polygons (fewer than 20 vertices) rendering flat on a simple xy plane, using GL_TRIANGLES and a flat color, a 2d simulation. I would like to add a border of variable thickness and a different color to these polygons. I have something implemented using the same vertices and glLineWidth/GL_LINE_LOOP, which works, but is another rendering pass and repeats all the vertex transforms. I think I should be able to do this in the fragment shader using gl_FragCoord and the vertex data and/or texture coordinates, but I'm not sure, and my naive attempts have been obviously incorrect. I