shader

Shader optimization: Is a ternary operator equivalent to branching?

你说的曾经没有我的故事 提交于 2019-12-03 04:28:53
I'm working on a vertex shader in which I want to conditionally drop some vertices: float visible = texture(VisibleTexture, index).x; if (visible > threshold) gl_Vertex.z = 9999; // send out of frustum I know that branches kill performance when there's little commonality between neighboring data. In this case, every other vertex may get a different 'visible' value, which would be bad for the performance of the local shader core cluster (from my understanding). To my question: Is a ternary operator better (irrespective of readability issues)? float visible = texture(VisibleTexture, index).x; gl

Creating blur filter with a shader - access adjacent pixels from fragment shader?

孤人 提交于 2019-12-03 03:43:13
I want to create a blur effect using a fragment shader in OpenGL ES 2.0. The algorithm I am interested in is simply an averaging blur - add all adjacent pixels to myself and divide by 9 to normalize. However I have 2 issues: 1) does this require me to first render to a framebuffer, then switch rendering targets? Or is there an easier way 2) assume I bind my "source" image to blur as texture 0, and I'm outputting my blurred texture. How do I access the pixels that aren't the one I'm current dealing with. The vert shader has invoked me for pixel i, but I need to access the pixels around me. How?

三维数据处理软件架构

喜夏-厌秋 提交于 2019-12-03 03:37:17
原文链接 三维数据处理软件都包含哪些模块 三维数据处理软件,一般包含三个模块:数据管理和处理,三维渲染,UI。 这与图形学的三个经典问题是相对应的:建模,渲染和交互。与一般常见的数据处理软件,比如图像视频处理,不同的是,这里的数据展示模块需要三维渲染。与之对应的UI操作,也变成了一些三维空间的变换,比如模型的旋转缩放等。 如何搭建一个简单的三维数据处理软件 那么如何快速的搭建一个三维数据处理软件呢?采用搭积木的方式,每个模块都有很多现成的开发包可以选择。比如UI模块处,一般常见的有MFC,QT,MyGUI(Magic3D使用的UI)等。数据处理算法方面,常见的有BGL,Geometry++,CGAL,OpenMesh,PCL等。渲染模块,可以使用OpenGL或者Direct3D,也可以使用渲染引擎,如OGRE,OSG等。 如何选择几何算法开发包 几何算法开发包的生命周期,一般分为三个阶段:算法原型验证,开发和维护升级。其中绝大部分时间都在维护和升级。 几何算法开发包的选择,一般有三种:自主开发,外包,使用第三方库。而第三方库又分为开源库和商业库。开发包的选择,考虑的主要是成本开销。算法原型和开发阶段主要是时间成本,如何快速的实现目标功能是最关键的问题。维护升级阶段需要尽量低的成本开销。 算法的维护升级,一般只有代码作者来做,其他人来做的话,一般只能重写。重写的代价是很大的

Compute sum of array values in parallel with metal swift

柔情痞子 提交于 2019-12-03 03:35:35
I am trying to compute sum of large array in parallel with metal swift. Is there a god way to do it? My plane was that I divide my array to sub arrays, compute sum of one sub arrays in parallel and then when parallel computation is finished compute sum of sub sums. for example if I have array = [a0,....an] I divide array in sub arrays : array_1 = [a_0,...a_i], array_2 = [a_i+1,...a_2i], .... array_n/i = [a_n-1, ... a_n] sums for this arrays is computed in parallel and I get sum_1, sum_2, sum_3, ... sum_n/1 at the end just compute sum of sub sums. I create application which run my metal shader,

Passing an array of vectors to a uniform

浪子不回头ぞ 提交于 2019-12-03 03:34:43
I am trying to implement multiple lights in my shader but I have trouble to fill the uniform with my light data. My vertex shader: attribute vec3 aVertex; attribute vec3 aNormal; attribute vec2 aTexture; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; uniform mat4 uNMatrix; uniform vec3 uAmbientColor; uniform vec3 uPointLightingLocation[16]; uniform vec3 uPointLightingColor[16]; varying vec2 vTexture; varying vec3 vLightWeighting; void main(void) { vec4 mvPosition = uMVMatrix * vec4(aVertex, 1.0); gl_Position = uPMatrix * mvPosition; vTexture = aTexture; int i; for (i = 0; i < 16; i++) { vec3

OpenGL Compute Shader SSBO

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want a compute shader that writes 1's in the output buffer. I compile the shader and attach it to the program without problem, then I call glDispatchCompute() function and I wait until compute shader ends. But when I see the array, there are only 0's. Can anyone tell me where is the mistake? This is my compute shader code: #version 430 core layout (local_size_x = 2) in; layout(std430, binding=0) writeonly buffer Pos{ float Position[]; }; void main(){ Position[gl_GlobalInvocationID.x] = 1.0f; } And this is some of my main: GLuint program

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

OpenGL ES 2.0 Multiple Programs or Multiple Shaders or what? How does it work?

自古美人都是妖i 提交于 2019-12-03 03:01:38
问题 The Problem (TL;DR) My problem, fundamentally, is that I do not know how OpenGL ES 2.0 expects me to write and use multiple shaders; or if it is even advisable/expected that a person will do so. The fundamental question here is: if I have an apple, a glowing rock and a fuzzy mesh, all in the same 3D world, all best drawn with different shader programs but using the same mvpMatrix then how would I go about using all of them in the same OpenGL render such that they all use their most

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

Shader as a drawable (Android)

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I use obtain a drawable from a Shader (such as LinearGradient ) so that I can use it as a background in my UI? 回答1: Since the background will probably need to resize, we will use a ShaderFactory to produce the Shader : ShapeDrawable.ShaderFactory sf=new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(0, 0, width, height, new int[]{Color.WHITE, Color.GRAY, Color.BLACK}, new float[]{0,0.5f,1}, Shader.TileMode.MIRROR); } }; We use this to create a PaintDrawable which we