glsl

Rendering to cube map

蹲街弑〆低调 提交于 2019-11-27 05:34:20
问题 According to ARB_geometry_shader4 it is possible to render a scene onto the 6 faces of a cube map with a geometry shader and the cube map attached to a framebuffer object. I want to create a shadow map using this way. However there seems to be a conflict that I can't resolve: I can only attach a texture with GL_DEPTH_COMPONENT as internal type to the GL_DEPTH_ATTACHMENT_EXT. A depth texture can only be 1D or 2D. If I want to attach a cube map, all other attached textures must be cube maps as

GCC, stringification, and inline GLSL?

南笙酒味 提交于 2019-11-27 04:38:13
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;" "void main()" "{" " gl_Position = vec4( position, 0.0, 1.0 );" "}" ; ..

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

人走茶凉 提交于 2019-11-27 04:23:39
问题 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? 回答1: 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

WebGL - is there an alternative to embedding shaders in HTML?

帅比萌擦擦* 提交于 2019-11-27 04:15:28
问题 The popular way of using GLSL shaders in WebGL seems to be to embed them in the main html file. The vertex and fragments shaders are embedded in tags like: <script id="shader-fs" type="x-shader/x-fragment"> This is the same convention I see in the WebGL samples in the Mozilla Developer Network page. This works fine for simple apps, but when you have a complex app with a number of shaders, the html file gets cluttered. (I keep editing the wrong shader!) Also if you want to reuse your shaders,

How do you pack one 32bit int Into 4, 8bit ints in glsl / webgl?

余生长醉 提交于 2019-11-27 03:51:58
I'm looking to parallelize some complex math, and webgl looks like the perfect way to do it. The problem is, you can only read 8 bit integers from textures. I would ideally like to get 32 bit numbers out of the texture. I had the idea of using the 4 color channels to get 32 bits per pixel, instead of 4 times 8 bits. My problem is, glsl doesn't have a "%" operator or any bitwise operator! TLDR: How do I convert a 32bit number to 4 8bit numbers by using the operators in glsl. Some extra info on the technique (using bitwise operators): How to store a 64 bit integer in two 32 bit integers and

How does vertex shader pass color information to fragment shader?

旧城冷巷雨未停 提交于 2019-11-27 02:35:29
问题 In a simple hello-world OpenGL program, which simply draws a static triangle on the window, when I set the 3 vertex of the triangle to red, green and blue color, the triangle is filled with gradient. But when I use shaders like this: Vertex Shader: attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main(void) { gl_Position = gl_ModelViewMatrix * gl_ProjectionMatrix * aVertex; vColor = aColor; } where the attributes aVertex and aColor comes from a vertex buffer, passed

How to debug a GLSL shader?

匆匆过客 提交于 2019-11-27 02:34:42
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 ? 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 color only if you reach the point of your code where you

GLSL fixed function fragment program replacement

匆匆过客 提交于 2019-11-27 02:12:20
When using the OpenGL fixed function pipeline for vertex setup, how a fragment program looks like that is compatible to the fixed function vertex setup? I guess that usually depends on the number of light sources and texture layers etc.. So for example how does a simple non-texture one-lightsource goraud shading fragment program look like that replaces GL's fixed function shader? While Gouraud shading calculates the light in the the vertex shader, Phong shading calculates the light in the fragment shader. The standard OpenGL light model is a Gouraud shading model, with a Blinn-Phong light

Depth as distance to camera plane in GLSL

亡梦爱人 提交于 2019-11-27 01:42:01
问题 I have a pair of GLSL shaders that give me the depth map of the objects in my scene. What I get now is the distance from each pixel to the camera. What I need is to get the distance from the pixel to the camera plane. Let me illustrate with a little drawing * |--* / | / | C-----* C-----* \ | \ | * |--* The 3 asterisks are pixels and the C is the camera. The lines from the asterisks are the "depth". In the first case, I get the distance from the pixel to the camera. In the second, I wish to

Omnidirectional shadow mapping with depth cubemap

▼魔方 西西 提交于 2019-11-27 01:25:33
问题 I'm working with omnidirectional point lights. I already implemented shadow mapping using a cubemap texture as color attachement of 6 framebuffers, and encoding the light-to-fragment distance in each pixel of it. Now I would like, if this is possible, to change my implementation this way: 1) attach a depth cubemap texture to the depth buffer of my framebuffers, instead of colors. 2) render depth only, do not write color in this pass 3) in the main pass, read the depth from the cubemap texture