glsl

How do I convert gl_FragCoord to a world space point in a fragment shader?

允我心安 提交于 2019-11-29 17:03:19
My understanding is that you can convert gl_FragCoord to a point in world coordinates in the fragment shader if you have the inverse of the view projection matrix, the screen width, and the screen height. First, you convert gl_FragCoord.x and gl_FragCoord.y from screen space to normalized device coordinates by dividing by the width and height respectively, then scaling and offsetting them into the range [-1, 1]. Next you transform by the inverse view projection matrix to get a world space point that you can use only if you divide by the w component. Below is the fragment shader code I have

Debug GLSL code in webgl

為{幸葍}努か 提交于 2019-11-29 16:58:17
问题 Is it possible to debug GLSL code or print the variable values from within the glsl code while using it with webgl ? Do three.js or scene.js contain any such functionality? 回答1: Not really, The way I usually debug GLSL is to output colors. So for example, given 2 shaders like // vertex shader uniform mat4 worldViewProjection; uniform vec3 lightWorldPos; uniform mat4 world; uniform mat4 viewInverse; uniform mat4 worldInverseTranspose; attribute vec4 position; attribute vec3 normal; attribute

GLSL custom/no interpolation of triangles with vertex colors

坚强是说给别人听的谎言 提交于 2019-11-29 16:52:41
The effect I want to achieve is vertex color with sharp contours. So inside the triangle the fragment shader should use the color of whatever vertex is closest to that fragment. Now when thinking about it, the only solution I can come up with is assigning tex coords 1,0,0 0,1,0 and 0,0,1 to the three vertices and have 2 (reoordered) duplicates of the vertex color array and then choose from the color aray of which the corresponding tex coord is highest. This method would at least add 9 more floats to each vertex. Which will slow down the application as my meshes are changing quit often and

How can i make gradient sphere on glsl?

流过昼夜 提交于 2019-11-29 16:52:23
I'm just a noob to GLSL and don't know how to do this in GLSL. What I trying to do is making alpha value to 1 on center of sphere and drop gradually on outer. So I made a prototype using Blender node editor and that's how I did. Now I am trying to do this in glsl. Maybe i can use gl_Normal to replace "normal on Geometry" on Blender. (Though it's removed after version 140, my final goal is just "make" it, so ignore that.) And there are also dot function to calculate "dot product on vector math" on glsl. Now i need is "View vector of camera data" and "ColorRamp". I think "ColorRamp" can be done

How to project top and bottom area of openGL control

回眸只為那壹抹淺笑 提交于 2019-11-29 15:55:18
Using below code I can display an image in openGL control. Which is in rectangular shape. Now I want to project top and bottom area of this rectangular to a cylindrical shape.I mean need to perform a rectangular to cylidrical projection on openGL. How can I achieve this? private void CreateShaders() { /***********Vert Shader********************/ vertShader = GL.CreateShader(ShaderType.VertexShader); GL.ShaderSource(vertShader, @"attribute vec3 a_position; varying vec2 vTexCoord; void main() { vTexCoord = (a_position.xy + 1) / 2; gl_Position = vec4(a_position, 1); }"); GL.CompileShader

Can you tell if a vertex attribute is enabled from within a vertex shader?

江枫思渺然 提交于 2019-11-29 14:05:56
I was wondering if there was a way to tell if a vertex attribute is enabled from within a vertex shader? I know that if the vertex attribute is disabled all the values will be treated as 0.0, so I could do a test like the following: if (attribute == 0) { // Do something different to normal. } else { // Use the attribute. } But this has the obvious problem for the case that the attribute is enabled and the value is just set to 0 (it will be treated as if it's disabled)! The other solution would be to just use a uniform variable that states whether or not to use the attribute, but I wondered if

What version of GLSL is used in the iPhone(s)?

别等时光非礼了梦想. 提交于 2019-11-29 13:20:24
I know that iPhone uses OpenGL ES 2.0, but I don't know the version of the underlying language GLSL. Is it 1.3, 1.4, 2.0, or other? Ok, I found it myself, thanks to the _____VERSION_____ predefined macro. The GLSL ES specification used is the 1.0, which is based on the GLSL version 1.20. The OpengGL ES 2.0 and GLSL ES 1.0 specifications are available for download at http://www.khronos.org/registry/gles/ . Angus Forbes printf("GLSL Version = %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); printf("GL Version = %s\n", glGetString(GL_VERSION)); On IOS 5.1, this prints out: GL Version = OpenGL ES

Creating a smudge/liquify effect on mouse move that continuously animates back to the original state using webgl

北慕城南 提交于 2019-11-29 13:04:37
I am trying to find information or examples that I can use to create a smudge/liquify effect that continuously animates back to the original state. Initially I was looking at using three.js or pixi.js to render some text and then use mouse events and ray casting to drag the mesh out of position, the closest thing I have found is this. https://codepen.io/shshaw/pen/qqVgbg let renderer = PIXI.autoDetectRenderer(window.innerWidth, window.innerHeight, { transparent: true }); I think that ideally I would render the text as an image and then the smudge effect would be applied to the pixels and they

Can I pack both floats and ints into the same array buffer?

你离开我真会死。 提交于 2019-11-29 12:42:17
...because the floats seem to be coming out fine, but there's something wrong with the ints. Essentially I have a struct called "BlockInstance" which holds a vec3 and an int . I've got an array of these BlockInstances which I buffer like so (translating from C# to C for clarity): glBindBuffer(GL_ARRAY_BUFFER, bufferHandle); glBufferData(GL_ARRAY_BUFFER, sizeof(BlockInstance)*numBlocks, blockData, GL_DYNAMIC_DRAW); glVertexAttribPointer(3,3,GL_FLOAT,false,16,0); glVertexAttribPointer(4,1,GL_INT,false,16,12); glVertexAttribDivisor(3,1); glVertexAttribDivisor(4,1); And my vertex shader looks like

How to define constant array in GLSL (OpenGL ES 2.0)?

亡梦爱人 提交于 2019-11-29 12:04:44
问题 I just want to store an array of weights that needs to every fragment calculation. This: float weights[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1); Just throws this: ERROR: 0:30: ']' : syntax error syntax error ERROR: 0:30: ';' : syntax error syntax error 回答1: From the OpenGL ES SL 1.0 spec, paragraph 4.1.9 Arrays (p. 24): There is no mechanism for initializing arrays at declaration time from within a shader. Note that this has been intentionally left out . According to this post, the OpenGL ES SL