glsl

GLSL gl_FragCoord.z Calculation and Setting gl_FragDepth

China☆狼群 提交于 2019-12-17 17:38:07
问题 So, I've got an imposter (the real geometry is a cube, possibly clipped, and the imposter geometry is a Menger sponge) and I need to calculate its depth. I can calculate the amount to offset in world space fairly easily. Unfortunately, I've spent hours failing to perturb the depth with it. The only correct results I can get are when I go: gl_FragDepth = gl_FragCoord.z Basically, I need to know how gl_FragCoord.z is calculated so that I can: Take the inverse transformation from gl_FragCoord.z

How to Using the #include in glsl support ARB_shading_language_include

大城市里の小女人 提交于 2019-12-17 15:37:51
问题 I wan't to use the #include macro to include shader files in glsl, and I heard there is a ARB_shading_language_include extension support the #include macro. Is there anyone can give me a code snippet showing how to use the #include macro? 回答1: The first thing you need to understand about shading_language_include is what it isn't . It is not "I #include a file from the disk." OpenGL doesn't know what files are; it has no concept of the file system. Instead, you must pre-load all of the files

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

不羁的心 提交于 2019-12-17 15:36:55
问题 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? 回答1: 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

Why does GL divide `gl_Position` by W for you rather than letting you do it yourself?

筅森魡賤 提交于 2019-12-17 09:35:11
问题 Note: I understand the basic math. I understand that the typical perspective function in various math libraries produces a matrix that converts z values from -zNear to -zFar back into -1 to +1 but only if the result is divided by w The specific question is what is gained by the GPU doing this for you rather than you having to do it yourself? In other words, lets say the GPU did not magically divide gl_Position by gl_Position.w and that instead you had to do it manually as in attribute vec4

How can I do these image processing tasks using OpenGL ES 2.0 shaders?

别等时光非礼了梦想. 提交于 2019-12-17 06:22:24
问题 How can I perform the following image processing tasks using OpenGL ES 2.0 shaders? Colorspace transform ( RGB/YUV/HSL/Lab ) Swirling of the image Converting to a sketch Converting to an oil painting 回答1: I just added filters to my open source GPUImage framework that perform three of the four processing tasks you describe (swirling, sketch filtering, and converting to an oil painting). While I don't yet have colorspace transforms as filters, I do have the ability to apply a matrix to

Do conditional statements slow down shaders?

烈酒焚心 提交于 2019-12-17 04:42:18
问题 I want to know if "if-statements" inside shaders (vertex / fragment / pixel...) are really slowing down the shader performance. For example: Is it better to use this: vec3 output; output = input*enable + input2*(1-enable); instead of using this: vec3 output; if(enable == 1) { output = input; } else { output = input2; } in another forum there was a talk about that (2013): http://answers.unity3d.com/questions/442688/shader-if-else-performance.html Here the guys are saying, that the If

How can I use layers on WebGL?

人走茶凉 提交于 2019-12-14 04:09:21
问题 I´m doing a tile map with light mapping, and I want to know how can I declare a tile map (rasterized in two triangules) as layer 1, and other tile map above with transparency in some parts to see the first layer? 回答1: WebGL is a rasterization API. It just draws. It has no concept of "layers". You can achieve layers by every frame, drawing your first tilemap, then drawing your second tilemap on top of the first one. This is no different than the canvas 2D API. As for how to render a tilemap

in int gl_VertexID causing error with three.js

淺唱寂寞╮ 提交于 2019-12-14 03:57:46
问题 I've been having trouble with the gl_VertexID built in vertex index, passed using in , to work with Three.js I'm not sure why, as the documentation says it works in all versions of OpenGL http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_VertexID.xml I'm using this vertex shader: uniform int freqData[64]; uniform int fftSize; in int gl_VertexID; void main() { vec3 norm = normalize(position); int modFFT = mod(gl_VertexID, fftSize); vec3 newPosition = norm * float(freqData[modFFT]); gl_Position =

Drawing tessallated LineLoops in OpenGL/GLSL

只愿长相守 提交于 2019-12-14 03:56:22
问题 I am rendering some LineLoops on a sphere (borders on a planet) and want to tessallate them into shorter lines to prevent long lines clipping into the sphere. Example: Here is my current source code: C++ draw call: void Border::Draw() const { glBindVertexArray(_vao); glPatchParameteri(GL_PATCH_VERTICES, 2); glDrawArrays(GL_PATCHES, 0, _size); glBindVertexArray(0); } Vertex Shader: #version 400 in layout(location = 0) vec3 position; void main() { gl_Position = vec4(position, 1.0); }

GLSL versions change log?

这一生的挚爱 提交于 2019-12-14 03:46:06
问题 Is there someplace I can read about the changes and additions made in GLSL from version 1.1 to 1.2 and from 1.2 to 1.3? Google seem to be at a loss for this and I really don't want to start reading the complete specification. 回答1: Version 1.3 of the spec has differences from 1.2 marked, it also lists changes from 1.2. Version 1.2 has a list of changes from 1.1. 来源: https://stackoverflow.com/questions/494800/glsl-versions-change-log