fragment-shader

Metal shader in SceneKit to outline an object

对着背影说爱祢 提交于 2019-12-22 10:55:30
问题 I'm playing around and trying to implement Metal shader in SceneKit that will outline an object. The idea is to draw an outline (or silhouette) similar to this image found in this blogpost (the blogpost doesn't contain any code): I'm new to SceneKit and Metal shaders so I'm able just to draw some geometry and write simple vertex or fragment shader. I'm curious how can I achieve this kind of effect? Is it done in multiple passes? Cheers! 回答1: The basic idea here is to clone the "selected" node

Creating a Gradient Color in Fragment Shader

[亡魂溺海] 提交于 2019-12-21 19:47:02
问题 I'm trying to achieve making a gradient color as the design apps (Photoshop for example) does, but can't get the exact result i want. My shader creates very nice 'gradients' but also contains other colors that are different from the colors I want to switch in. It looks nice but, my aim is adding blending functions later and make a kind of color correction shader. but first of all I have to get the right colors. Here is my fragment shader http://player.thebookofshaders.com/?log=171119111216

understanding the basics of dFdX and dFdY

人走茶凉 提交于 2019-12-21 05:22:27
问题 I've read numerous descriptions of the behavior of dFdX(n) and dFdY(n) and do believe I still have a handle on partial derivatives from school. What I don't follow is where does 'n' come from in the simplest possible example? Reading the glsl built-in functions dFdx(n) and dFdy(n) without any context other than mathematics I would interpret them as "I have some function of x and y: f(x,y) , I take the partial derivative of that function w.r.t. x d/dx(x,y) , and I evaluate the partial

What does the 1/w coordinate stand for in gl_FragCoord?

北慕城南 提交于 2019-12-21 02:21:05
问题 The gl_FragCoord variable stores four components: (x, y, z, 1/w ) What is the w coordinate and why is it stored as 1/w ? 回答1: The GLSL and OpenGL specifications are needlessly confusing in this regard. The OpenGL spec is easier to understand: gl_FragCoord stores the X, Y, and Z components of the window-space vertex position. The X, Y, and Z values are calculated as described for computing the window-space position (though the pixel-center and upper-left origin can modify the X and Y values).

Fragment shader inexplicable bahaviour

℡╲_俬逩灬. 提交于 2019-12-20 07:16:59
问题 I have written a C++ program where I draw a teapot and apply lighting. It is itself simple, but I also use shaders. Simple I'm new with GLSL I just tried a simple fragment shader, but the screen output is inexplicable. In this file I initialize glew in the init method, where I also compile the vertex and fragment shader. They're in the "vertex_shader" and "fragment_shader" files. The thing you may not recognize is what's Light and Material. They're just some structs containing all info about

GLSL: How to get pixel x,y,z world position?

守給你的承諾、 提交于 2019-12-18 10:34:12
问题 I want to adjust the colors depending on which xyz position they are in the world. I tried this in my fragment shader: varying vec4 verpos; void main(){ vec4 c; c.x = verpos.x; c.y = verpos.y; c.z = verpos.z; c.w = 1.0; gl_FragColor = c; } but it seems that the colors change depending on my camera angle/position, how do i make the coords independent from my camera position/angle? Heres my vertex shader: varying vec4 verpos; void main(){ gl_Position = ftransform(); verpos = gl_ModelViewMatrix

OpenGL - How to access depth buffer values? - Or: gl_FragCoord.z vs. Rendering depth to texture

筅森魡賤 提交于 2019-12-17 17:58:11
问题 I want to access the depth buffer value at the currently processed pixel in a pixel shader. How can we achieve this goal? Basically, there seems to be two options: Render depth to texture. How can we do this and what is the tradeoff? Use the value provided by gl_FragCoord.z - But: Is this the correct value? 回答1: On question 1: You can't directly read from the depth buffer in the fragment shader (unless there are recent extensions I'm not familiar with). You need to render to a Frame Buffer

What does `precision mediump float` mean?

大城市里の小女人 提交于 2019-12-17 17:34:02
问题 In the learningwebgl tutorial1 I've found an interesting line in the fragment shader. precision mediump float; I've found an article about it here, but I still can't understand what does it mean? And if I remove this line, nothing changes. Everything is the same. So what does precision mediump float mean? 回答1: This determines how much precision the GPU uses when calculating floats. highp is high precision, and of course more intensive than mediump (medium precision) and lowp (low precision).

YUV to RGB conversion by fragment shader

怎甘沉沦 提交于 2019-12-17 07:15:27
问题 I've a problem with convertion of camera preview in Android from YUV format to RGB. The purpose of conversion is to apply some effects. I try to convert by fragment shader because convertion by native code is slow (about 14fps). The reference which I've used is http://jyrom.tistory.com/m/post/view/id/187. I try to port this code to Android platform, but the result is black-green rectangles. But, I can watch some form through the output which I get. Could you please try to help me to resolve

YUV to RGB conversion by fragment shader

♀尐吖头ヾ 提交于 2019-12-17 07:15:00
问题 I've a problem with convertion of camera preview in Android from YUV format to RGB. The purpose of conversion is to apply some effects. I try to convert by fragment shader because convertion by native code is slow (about 14fps). The reference which I've used is http://jyrom.tistory.com/m/post/view/id/187. I try to port this code to Android platform, but the result is black-green rectangles. But, I can watch some form through the output which I get. Could you please try to help me to resolve