shader

Gaussian filter with OpenGL Shaders

空扰寡人 提交于 2019-12-17 10:42:34
问题 I am trying to learn Shaders to implement something in my iPhone app. So far I have understood easy examples like making a color image to gray scale, thresholding, etc. Most of the examples involve simple operations in where processing input image pixel I(x,y) results in a simple modification of the colors of the same pixel But, how about Convolutions?. For example, the easiest example would the Gaussian filter, in where output image pixel O(x,y) depends not only on I(x,y) but also on

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

Getting the true z value from the depth buffer

怎甘沉沦 提交于 2019-12-17 05:37:30
问题 Sampling from a depth buffer in a shader returns values between 0 and 1, as expected. Given the near- and far- clip planes of the camera, how do I calculate the true z value at this point, i.e. the distance from the camera? 回答1: From http://web.archive.org/web/20130416194336/http://olivers.posterous.com/linear-depth-in-glsl-for-real // == Post-process frag shader =========================================== uniform sampler2D depthBuffTex; uniform float zNear; uniform float zFar; varying vec2

Do conditional statements slow down shaders?

烈酒焚心 提交于 2019-12-17 04:42:18
问题 I want to know if "if-statements" inside shaders (vertex / fragment / pixel...) are really slowing down the shader performance. For example: Is it better to use this: vec3 output; output = input*enable + input2*(1-enable); instead of using this: vec3 output; if(enable == 1) { output = input; } else { output = input2; } in another forum there was a talk about that (2013): http://answers.unity3d.com/questions/442688/shader-if-else-performance.html Here the guys are saying, that the If

opengl保存并加载二进制program

≯℡__Kan透↙ 提交于 2019-12-16 09:29:55
通常情况下,opengl 的shader会被编译成program,然后再将program送到GPU里面去执行。 如果我们的应用程序,每次都用源码编译shader,这样效率肯定是不高的,特别是在嵌入式平台上, 性能比较弱的场景下。 其实我们可以稍微修改一下我们的程序结构,将编译完的program保存下来,下一次再用的时候,直接加载保存好的二进制program就好了,不必每次都编译,浪费时间。 这主要是通过如下两个API来实现的。 glGetProgramBinary 保存program glProgramBinary 加载program 首先确认是否支持 GLint formats = 0; glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &formats); if( formats < 1 ) { std::cerr << "Driver does not support any binary formats." << std::endl; exit(EXIT_FAILURE); } 保存二进制program // Get the binary length GLint length = 0; glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &length); // Retrieve

Unity Shader屏幕后处理高斯模糊

匆匆过客 提交于 2019-12-16 07:22:33
原理 利用卷积计算,使用的卷积核叫高斯核 使用一个N x N的高斯核对图像进行卷积滤波,就需要N x N x W x H次纹理采样,当N的大小不断增加时,采样次数会变得非常巨大,不过我们可以把这个二维高斯函数拆分成两个一维函数. 得到的结果是一样的。 实现 我们会先后调用两个Pass,第一个Pass使用竖直方向的一维高斯核进行滤波,第二个Pass使用水平方向的一维高斯核,得到最终的目标图像. 首先,创建一个脚本: public class GaussianBlur : PostEffectsBase 声明需要的Shader,并创建相应的材质: public Shader gaussianBlurShader ; private Material gaussianBlurMaterial = null ; public Material material { get { gaussianBlurMaterial = CheckShaderAndCreateMaterial ( gaussianBlurShader , gaussianBlurMaterial ) ; return gaussianBlurMaterial ; } } 然后提供调整高斯模糊迭代次数、模糊范围、缩放系数的参数: [ Range ( 0 , 4 ) ] public int iterations = 3 ;

程序猿 - 超实用的工具、素材、学习网站分享

不想你离开。 提交于 2019-12-16 01:41:14
文章目录 ------------------------------学习教程篇------------------------------- bilibili哔哩哔哩 网易云课堂 siki学院: 泰课在线: 可汗学院: 线性代数的本质 - bilibili 计算机科学速成课 - bilibili LearnOpenGL: The Book of Shaders Shadertoy Sandbox Gallery - Shader Three.js WebGL中文网 ------------------------------工具篇------------------------------- Shader建模工具 2D图形函数绘制工具 3D图形函数绘制工具 CODELF 变量命名 果汁排行榜 : 各类榜单排名大全 在线自动抠图 图形计算器 - GeoGebra 在线编辑图片 在线视频剪辑 PDF、World、Excel各类工具 一键生成所有尺寸的应用图标/启动图 在线编辑音频文件 图说,在线制作图表 Bigjpg :AI人工智能图片无损放大 tinypng :无损压缩图片 GitMind: 在线脑图制作 石墨文档: ------------------------------美术资源篇------------------------------- Softonic

【Unity Shader】效果公式总结

会有一股神秘感。 提交于 2019-12-14 19:01:47
a.漫反射公式: diff=C*max(0,cos<L,N>);//C是颜色和强度_LightColor0.rgb 代码: diff=max(0,dot(i.normal,i.lightDir))//i的单位向量and单位法向量 c=tex2D(tex,i.uv) _LightColor0 diff//_LightColor0表示的是场景中平行光的颜色和强度 b.高光反射公式: Spec=pow(max(0,cos(R,V),gloss))//R 单位反射向量reflect(ray,normal)函数获取,V视线单位方向向量 ,gloss光色度 代码: Spec=pow(max(0),dot(reflect(-i.lightDir,i.normal),32)) c=c**_LightColor0*(diff+Spec) 纹理 uv坐标是顶点存储了图片上的坐标 _MainTex (“Main Tex”, 2D) = “white” {} sampler2D _MainTex; float4 _MainTex_ST;//Unity中 纹理_ST来默认声明该纹理的属性_MainTex_ST.xy表示Scale, Till缩放,_MainTex_ST.zw表示Transform 偏移 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);/

Why is there the need for the index argument in glEnableVertexAttribArray? [duplicate]

断了今生、忘了曾经 提交于 2019-12-14 03:27:43
问题 This question already has answers here : What is the purpose of `glEnableVertexAttribArray(GLuint index)` in OpenGL? (2 answers) Closed 3 years ago . Using glVertexAttribPointer the opengl implementation already knows to which attribute location/index in vertex shader Vertex Attribute Object is bound, so why is there the need to provide attribute index in glEnableVertexAttribArray again? I think after using glBindVertexArray(VAO); it could have been enough to use just