fragment-shader

SKShader to create parallax background

妖精的绣舞 提交于 2019-12-03 16:19:02
A parallax background with a fixed camera is easy to do, but since i'm making a topdown view 2D space exploration game, I figured that having a single SKSpriteNode filling the screen and being a child of my SKCameraNode and using a SKShader to draw a parallax starfield would be easier. I went on shadertoy and found this simple looking shader. I adapted it successfully on shadertoy to accept a vec2() for the velocity of the movement that I want to pass as an SKAttribute so it can follow the movement of my ship. Here is the original source: https://www.shadertoy.com/view/XtjSDh I managed to make

Gaussian Blur - standard deviation, radius and kernel size

折月煮酒 提交于 2019-12-03 12:32:31
问题 I've implemented a gaussian blur fragment shader in GLSL. I understand the main concepts behind all of it: convolution, separation of x and y using linearity, multiple passes to increase radius... I still have a few questions though: What's the relationship between sigma and radius? I've read that sigma is equivalent to radius, I don't see how sigma is expressed in pixels. Or is "radius" just a name for sigma, not related to pixels? How do I choose sigma? Considering I use multiple passes to

GLSL reusable/shared functions, shared constants (OpenGL ES 2.0)?

拥有回忆 提交于 2019-12-03 12:03:52
Short: Can I define a function that every shader can use? Or I have to define it per shader? The whole story: I want to create numerous shaders intended to colorize the input fragments with predefined gradient ramps (something like this - http://www.thinkboxsoftware.com/storage/krakatoa-support-images/krakatoa15_kcm_densitybyage_gradientrampmap.png ). I want to define a gradient ramp constant for each shader (an array of vec4 color samples, where the alpha value holds the gradient position, see Pos in the picture above) And I need a function that can return a color sample from the given

How do I get the current color of a fragment?

百般思念 提交于 2019-12-03 05:34:19
问题 I'm trying to wrap my head around shaders in GLSL, and I've found some useful resources and tutorials, but I keep running into a wall for something that ought to be fundamental and trivial: how does my fragment shader retrieve the color of the current fragment? You set the final color by saying gl_FragColor = whatever , but apparently that's an output-only value. How do you get the original color of the input so you can perform calculations on it? That's got to be in a variable somewhere, but

Three.js use framebuffer as texture

烈酒焚心 提交于 2019-12-03 03:56:50
问题 I'm using an image in a canvas element as a texture in Three.js, performing image manipulations on the canvas using JavaScript, and then calling needsUpdate() on the texture. This works, but it's quite slow. I'd like to perform the image calculations in a fragment shader instead. I've found many examples which almost do this: Shader materials : http://mrdoob.github.io/three.js/examples/webgl_shader2.html This example shows image manipulations performed in a fragment shader, but that shader is

Custom Texture Shader in Three.js

北慕城南 提交于 2019-12-03 03:06:49
问题 I'm just looking to create a very simple Fragment Shader that draws a specified texture to the mesh. I've looked at a handful of custom fragment shaders that accomplished the same and built my own shaders and supporting JS code around it. However, it's just not working. Here's a working abstraction of the code I'm trying to run: Vertex Shader <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4

Gaussian Blur - standard deviation, radius and kernel size

ⅰ亾dé卋堺 提交于 2019-12-03 03:01:27
I've implemented a gaussian blur fragment shader in GLSL. I understand the main concepts behind all of it: convolution, separation of x and y using linearity, multiple passes to increase radius... I still have a few questions though: What's the relationship between sigma and radius? I've read that sigma is equivalent to radius, I don't see how sigma is expressed in pixels. Or is "radius" just a name for sigma, not related to pixels? How do I choose sigma? Considering I use multiple passes to increase sigma, how do I choose a good sigma to obtain the sigma I want at any given pass? If the

Efficient Bicubic filtering code in GLSL?

风流意气都作罢 提交于 2019-12-03 01:13:54
问题 I'm wondering if anyone has complete, working, and efficient code to do bicubic texture filtering in glsl. There is this: http://www.codeproject.com/Articles/236394/Bi-Cubic-and-Bi-Linear-Interpolation-with-GLSL or https://github.com/visionworkbench/visionworkbench/blob/master/src/vw/GPU/Shaders/Interp/interpolation-bicubic.glsl but both do 16 texture reads where only 4 are necessary: https://groups.google.com/forum/#!topic/comp.graphics.api.opengl/kqrujgJfTxo However the method above uses a

Custom Texture Shader in Three.js

社会主义新天地 提交于 2019-12-02 17:40:52
I'm just looking to create a very simple Fragment Shader that draws a specified texture to the mesh. I've looked at a handful of custom fragment shaders that accomplished the same and built my own shaders and supporting JS code around it. However, it's just not working. Here's a working abstraction of the code I'm trying to run: Vertex Shader <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); } </script> Fragment Shader <script id="fragmentShader" type="x-shader/x-fragment">

WebGL Drawing Multiple Shapes of Different Colour

…衆ロ難τιáo~ 提交于 2019-12-02 16:48:30
问题 I am currently in the process of learning both WebGL and Javascript. An assignment is requiring me to create multiple shapes using WebGL and for them to all be different colours, however, I am unable to figure out how to set it so that each shape has it's own colour. // HelloTriangle.js (c) 2012 matsuda // Vertex shader program var VSHADER_SOURCE = 'attribute vec4 a_Position;\n' + 'void main() {\n' + ' gl_Position = a_Position;\n' + '}\n'; // Fragment shader program var FSHADER_SOURCE =