shader
What are shaders in OpenGL and what do we need them for? [closed]
The OpenGL wiki gives a good definition: A Shader is a user-defined program designed to run on some stage of a graphics processor. History lesson In the past, graphics cards were non-programmable pieces of silicon which performed a set of fixed algorithms: inputs: 3D coordinates of triangles, their colors, light sources output: a 2D image … Read more
Shader optimization: Is a ternary operator equivalent to branching?
Actually this depends on the shader language one uses. In HLSL and Cg a ternary operator will never lead to branching. Instead both possible results are always evaluated and the not used one is being discarded. To quote the HLSL documentation: Unlike short-circuit evaluation of &&, ||, and ?: in C, HLSL expressions never short-circuit … Read more
Why not vec3 for OpenGL ES 2.0 gl_Position?
The w in vec4(x, y, z, w) is used for clipping, and plays its part while linear algebra transformations are applied to the position. By default, this should be set to 1.0. See here for some more info: http://web.archive.org/web/20160408103910/http://iphonedevelopment.blogspot.com/2010/11/opengl-es-20-for-iOS-chapter-4.html
Custom Texture Shader in Three.js
You are still using the old syntax for uniforms var uniforms = { texture1: { type: “t”, value: 0, texture: THREE.ImageUtils.loadTexture(“texture.jpg”) } }; This is the new syntax var uniforms = { texture1: { type: “t”, value: THREE.ImageUtils.loadTexture( “texture.jpg” ) } };
How do Shadertoy’s audio shaders work?
They are basically a function that given time returns 2 values for an audio single (left and right channel). The values go from -1 to 1. paste in this shader and maybe you’ll get it vec2 mainSound( float time ) { return vec2( sin(time * 1000.0), sin(time * 1000.0) ); } You can see a … Read more
Organizing GLSL shaders in OpenGL engine
Most modern engines I know have a “shader cache” and use the second option, because apparently it’s faster. Also you can take a look at the ARB_shader_subroutine which allows dynamic linkage. But I think it’s only available on DX11 class hardware.
How do I get the current color of a fragment?
The fragment shader receives gl_Color and gl_SecondaryColor as vertex attributes. It also gets four varying variables: gl_FrontColor, gl_FrontSecondaryColor, gl_BackColor, and gl_BackSecondaryColor that it can write values to. If you want to pass the original colors straight through, you’d do something like: gl_FrontColor = gl_Color; gl_FrontSecondaryColor = gl_SecondaryColor; gl_BackColor = gl_Color; gl_BackSecondaryColor = gl_SecondaryColor; Fixed functionality … Read more
Learning modern OpenGL
So… currently we have OpenGL 4.2 out, which as I read somewhere requires dx11 hardware (what does it mean?) and set of ‘side’ libraries, to for example create window. DX11 hardware is… hardware that has “supports DirectX 11” written on the side of the box. I’m not sure what it is you’re asking here; are … Read more
OpenGL 4.x learning resources [closed]
I cordially dislike negative answers, but I’m afraid I have to give one to this question. You are ultimately asking for beginner material that uses features unique to OpenGL version 4.0 and above. Well, let’s look at some of the unique features of 4.x. Perhaps the biggest feature is tessellation. What does that mean? It … Read more