shader

Is there a way to cache slow WebGL shader compilation if the shader never changes?

你离开我真会死。 提交于 2020-01-25 00:19:06
问题 I have a WebGL shader which compiles perceptually immediately (Chrome on Windows 7) when I have this: void main(void) { if (antialias_level == 1) gl_FragColor = NewtonIteration((gl_FragCoord.xy + offset) / zoom); else if (antialias_level == 2) gl_FragColor = (NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.25, -0.25)) / zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.25, 0.25)) / zoom)) * 0.5; } But it takes a very long time (~10 sec) to compile this: void main(void) { if

Shader(7)_溶解

左心房为你撑大大i 提交于 2020-01-25 00:10:33
效果图: 原理: 现在状态不佳,等状态好再详细写 代码: Shader "Hidden/NewImageEffectShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _Noise ("Noise", 2D) = "white"{} _Crl ("Crl",Range(0,1)) = 0.5 } SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float2 uv1 : TEXCOORD1; float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; o.uv1 = v.uv; return o; } sampler2D _MainTex; sampler2D _Noise; float

How to bind texture just to one object in OpenGLES?

白昼怎懂夜的黑 提交于 2020-01-24 19:49:29
问题 I am activating the texture just before the object to draw. But the texture is showing on both objects. Why is that so? Should I unbind the texture before the first object to draw? - I tried with glDisable and glBindTexture but it did not help. Here my code: @Override public void onDrawFrame(GL10 gl) { GLES20.glClear(GL10.GL_COLOR_BUFFER_BIT); synchronized (camerObject) { surfaceTextureCamera.updateTexImage(); cameraUpdate = false; } vertexBuffer.position(0); GLES20.glVertexAttribPointer

SceneKit shader modifier for geometry entry points works in iOS but not OS X

*爱你&永不变心* 提交于 2020-01-23 13:30:13
问题 I'm in the early stages of making a SceneKit shader modifier (for the geometry entry point) that displaces a plane's geometry according to a height-map texture. The plan is to use it for creating terrain. In iOS (edit: the iOS Simulator) the shader works as it should, but does print this warning to the console: SceneKit: error, modifier without code is invalid When building for OS X however, the shader gets a fatal error, and the terrain geometry just displays as a pink rectangle. This is the

[Stage3D]初窥Stage3D(2)

穿精又带淫゛_ 提交于 2020-01-23 12:57:37
Vertex and Fragment Shader (顶点着色器 和 像素着色器) 1.什么是shader   Shader(着色器)是图形渲染管道中的可编程代码块,它是跑在GPU上面的程序,专门用于处理图像显示,分为 vertex shader(顶点着色器) 和 fragment shader (像素着色器)。顾名思义,这两个shader的功能,分别是负责顶点的处理,和像素的处理。 而在Stage3D中,提供了一个API叫Program3D,这个类实现了Shader 。也就是说,如果要在Actionscript中使用shader编程,则必须使用stage3D中的Program3D类。这个类会根据渲染需求生成一个shader实例并把它传递给GPU,此后GPU再执行这个shader实例从而执行渲染效果。    简而言之,shader是运行在GPU上面的程序,负责图形顶点计算和像素颜色渲染。 2.Shader的工作流程    (图片来自:http://www.adobe.com/devnet/flashplayer/articles/vertex-fragment-shaders.html)   如图所示为可编程图形管道的各个工作模块,模块之间是瀑布式的(即下一个模块的工作依赖于上一个模块的输出)。首先,假定我们有一组定义了一组三角形的顶点数据流。在图形管道中

Render camera preview on a Texture with target GL_TEXTURE_2D

梦想的初衷 提交于 2020-01-23 08:04:50
问题 I'm trying to render the camera preview on an OpenGL Texture with target GL_TEXTURE_2D . I'm very well aware of SurfaceTexture but I cannot use it because it only works with GL_TEXTURE_EXTERNAL_OES . In the documentation of SurfaceTexture, it's written : Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than the GL_TEXTURE_2D target I cannot use GL_TEXTURE_EXTERNAL_OES because, I'll have to make a lot of changes in my existing code. Is there a way to

Unity项目中world space状态下的UGUI始终渲染在最上层

为君一笑 提交于 2020-01-23 03:36:50
Unity项目中world space状态下的UGUI始终渲染在最上层 简介 shader 简介 使用shader创建材质球,赋值到UGUI的对象上,使该UGUI对象始终渲染在最上层。 原文章中是在制作VR项目时,但其实在除Screen Space-Overlay状态下,都可使用。只要符合实际需求即可。 因为拥有该shader的UGUI不会被一般的3D物体所遮挡,故要根据具体需求使用。 shader shader出自: https://blog.csdn.net/u013032852/article/details/77642262 Shader "UI/Overlay" { Properties { [ PerRendererData ] _MainTex ( "Font Texture" , 2 D ) = "white" { } _Color ( "Tint" , Color ) = ( 1 , 1 , 1 , 1 ) _StencilComp ( "Stencil Comparison" , Float ) = 8 _Stencil ( "Stencil ID" , Float ) = 0 _StencilOp ( "Stencil Operation" , Float ) = 0 _StencilWriteMask ( "Stencil Write Mask" ,

【译】Unity3D Shader 新手教程(6/6) —— 更好的卡通Shader

浪尽此生 提交于 2020-01-22 19:09:03
本文为翻译,附上 原文链接 。 转载请注明出处—— polobymulberry-博客园 。 动机 如果你想了解以下几件事,我建议你阅读以下这篇教程: 想知道如何写一个multipass的toon shader。 在shader中学习更多不同参考坐标系(空间space)以及其作用。 深入学习一个实用的fragment shader。 学习矩阵相乘和Unity内建矩阵的使用。 该教程比 第五篇教程 更实用。 准备工作 为了实现一个描边的toon shader,我们需要做的是: 为模型描边。 将 第四篇文章 中的介绍的toon shader(使用的是surface shader)移植到vertex&fragment shader中。 描边 有很多方法进行描边,在 第四篇文章 中,我们使用了rim lighting(边缘光照)来给我们人物加上描边效果。现在我们采用另一种方法,额外使用一个Pass改善已有的描边效果。 不同于之前描边效果的实现,在这篇教程中,你可以将你看不到的模型部分(比如背面)放大一些,再渲染成全黑,这样也是可以实现描边效果的。这种方法可以将原模型的正面完好无损呈现出来。 所以我们首先试着: 单独写一个仅仅用来绘制模型背面的Pass。 扩展模型背面的顶点,使其看起来变大了一些。 下面这个Pass就是用来仅仅绘制模型背面(Cull Front,剔除正面的多边形): Pass

关于Unity中Shader的使用

你离开我真会死。 提交于 2020-01-22 19:08:44
在游戏的开发过程中,程序员不太会自己去写shader,因为写起来很麻烦,而且只有Unity会报错,编译器也没有什么提示。 通常是拿别人的shader改一改,当然,程序员还是要能看懂和会一点shader Unity坐标系转换 1: transform.localToWorldMatrix 局部转世界的矩阵; 2: transfrom.worldToLocalMatrix 世界坐标转局部坐标矩阵;  MultiplyPoint, MultiplyPoint3x4 MultiplayVector 来进行坐标变换; 4: shader中 左乘_World2Object矩阵来实现世界坐标转局部坐标变换; 5: shader中左乘_Object2World矩阵来实现局部转世界的转换; 6: UNITY_MATRIX_MV 基本变换矩阵 x 摄像机矩阵; 7: UNITY_MATRIX_MVP 基本变换矩阵x摄像机矩阵x投影矩阵; 8: UNITY_MATRIX_V 摄像机矩阵; 9: UNITY_MATRIX_P 投影矩阵; 10: UNITY_MATRIX_VP摄像机矩阵x投影矩阵; 11: UNITY_MATRIX_T_MV (基本变换矩阵 x 摄像机矩阵) 转置矩阵; 12: UNITY_MATRIX_IT_MV(基本变换矩阵 x 摄像机矩阵) 的逆转置矩阵; 13: UNITY

unity中shader常用方法

自古美人都是妖i 提交于 2020-01-22 19:07:16
今天给大家列出来shader中常用的一些函数,函数后面有释义,大家可以打印出来,或者在写shader的时候来这篇文章查阅,看看你需要用到哪些。 Cg提供了一系列内建的标准函数。这些函数用于执行数学上的通用计算或通用算法(纹理映射等), 有些函数直接和 GPU 指令相对应,所以执行效率非常高。 这些函数来源于文档,我为大家筛选出了常用的,去掉了基本用不到的函数。 数学函数: abs(x) 返回输入参数的绝对值 acos(x) 反余切函数,输入参数范围为[-1,1],返回[0,π]区间的角度值 all(x) 如果输入参数均不为0,则返回 ture;否则返回 flase。&&运算 any(x) 输入参数只要有其中一个不为0,则返回 true。||运算 asin(x) 反正弦函数,输入参数取值区间为[−1,1],返回角度值范围为[−π/2 ,π/2 ] atan(x) 反正切函数,返回角度值范围为⎡−π/2 ,π/2⎤ atan2(y,x) 计算y/x 的反正切值。实际上和atan(x)函数功能完全一样,至少输入参数不同。atan(x) = atan2(x, float(1)) ceil(x) 对输入参数向上取整。例如:ceil(float(1.3)),其返回值为 2.0 clamp(x,a,b) 如果x 值小于 a,则返回a;如果 x 值大于 b,返回b;否则,返回 x cos(x)