glsl

Calculate clipspace.w from clipspace.xyz and (inv) projection matrix

喜你入骨 提交于 2019-11-29 10:34:46
问题 I'm using a logarithmic depth algorithmic which results in someFunc(clipspace.z) being written to the depth buffer and no implicit perspective divide . I'm doing RTT / postprocessing so later on in a fragment shader I want to recompute eyespace.xyz, given ndc.xy (from the fragment coordinates) and clipspace.z (from someFuncInv() on the value stored in the depth buffer). Note that I do not have clipspace.w, and my stored value is not clipspace.z / clipspace.w (as it would be when using fixed

Variable array index not possible in webgl shaders?

余生颓废 提交于 2019-11-29 09:18:44
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? 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 expression." Did you try it? If it didn't work, there are a couple options. If you have a small number of

GLSL SpinLock only Mostly Works

為{幸葍}努か 提交于 2019-11-29 08:49:46
I have implemented a depth peeling algorithm using a GLSL spinlock (inspired by this ). In the following visualization, notice how overall the depth peeling algorithm functions correctly (first layer top left, second layer top right, third layer bottom left, fourth layer bottom right). The four depth layers are stored into a single RGBA texture. Unfortunately, the spinlock sometimes fails to prevent errors--you can see little white speckles, particularly in the fourth layer. There's also one on the wing of the spaceship in the second layer. These speckles vary each frame. In my GLSL spinlock,

SSBO as bigger UBO?

吃可爱长大的小学妹 提交于 2019-11-29 07:03:50
i am currently doing so rendering in OpenGL 4.3 using UBOs to store all my constant data on the GPU. (Stuff like material descriptions, matrices, ...). It works however the small size of UBO (64kB on my implementation) forces me to switch buffers numerous times slowing rendering, i am looking for similar a way to store a few MB. After a little research i saw that SSBO allow exactly that but also have unwanted 'features' : they can be written from the shader and might be slower to read. Is there a better solution than SSBO for supplying big chunks of data to shaders ? I feel like i am missing

Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1

允我心安 提交于 2019-11-29 06:48:30
In theory, mesa 10.0.1 should support OpenGL 3.3 but currently I'm only getting 3.0 support. glxinfo gives some confusing results... [pdel@architect build]$ glxinfo | grep -i opengl OpenGL vendor string: Intel Open Source Technology Center OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.0.1 OpenGL core profile shading language version string: 3.30 OpenGL core profile context flags: (none) OpenGL core profile profile mask: core profile OpenGL core profile extensions: OpenGL version string: 3.0 Mesa 10.0.1 OpenGL shading

OpenGL ES 2.0 Rendering with a Texture

二次信任 提交于 2019-11-29 06:48:22
问题 The iPhone SDK has an example of using ES 2.0 with a set of (Vertex & Fragment) GLSL shaders to render a varying colored box. Is there an example out there on how to render a simple texture using this API? I basically want to take a quad, and draw a texture onto it. The old ES 1.1 API's don't work at all anymore, so I'm needing a bit of help getting started. Most shader references talk mainly about advanced shading topics, but I'm really unsure about how to tell the shader to use the bound

Using a matrix as vertex attribute in OpenGL3 Core Profile

雨燕双飞 提交于 2019-11-29 04:27:12
I am using OpenGL3.2 Core Profile on OSX. And I want to do instanced drawing (glDrawArraysInstanced), where I pass a matrix for each instance. My vertex shader builds just fine: #version 150 in mediump vec4 position; in mediump mat4 trf; in lowp vec4 rgb; out lowp vec4 colour; uniform highp mat4 modelcamviewprojmat; void main() { mediump vec4 tpos = trf * position; gl_Position = modelcamviewprojmat * tpos; colour = rgb; } The binding of 'trf' went fine: glBindAttribLocation(program, ATTRIB_TRF, "trf" ); But how can I pass in my data? glVertexAttribPointer can not pass values larger than 4

Do uniform values remain in GLSL shader if unbound?

拥有回忆 提交于 2019-11-29 03:01:00
I am making a program that uses two different shaders for different different primitives. My question is, if I bind a program, send it uniform variables, then use another shader program and come back to the first one, will the passed uniform values remain? Here is some pseudocode: glUseProgram(shader1); glUniform(shader1,...); //stuff for(elements in a list) { if(element.type = 1) { glUseProgram(shader2); element.draw(); } else { glUseProgram(shader1); //Here, do the uniforms from above remain, if shader2 was bound before? element.draw(); } } Yes, uniforms are specific to a program, and will

GLSL for simple water surface effects

北慕城南 提交于 2019-11-29 02:49:50
问题 I'm looking for some pointers on how to implement simple water surface effects in OpenGL ES 2.0. Nothing fancy like reflection or refraction, just a basic ripple/wave effect that modulates over time. Performance is critical. I'm assuming this will be best done in a shader. Any pointers on how to best handle this? 回答1: There is an old trick to simulate water waves & ripples using minimum effort in terms of equations. It's used in many places, and I can't find the original, but you can grab it,

GLSL Problem: Multiple shaders in one program

妖精的绣舞 提交于 2019-11-29 02:47:42
问题 I must have misunderstood something with shaders: I thought that as you can attach multiple shaders to one program, you'd be able to simply attach more than one fragment shader, as an example: A crate texture rendered with a color modulation and refraction. But apparently this is not the case, as you can have only one main function per program. How can I work around the main function limit and allow for any dynamic combination of multiple fragment shaders which are in the same program and