精华内容
下载资源
问答
  • water shader

    2017-12-12 18:05:03
    shader

    水 shader
    _WaveMap(“Normal”)
    _Tiling

    _WaveBumpScale
    _WavaBumpSpeed() 水流动的方向

    _DeepTex 获取深度 r通道(深度因素) g透明度因素(用深度图计算软边的时候需要) 用实时软边的话,透明度用_Color0.a

    1. _Color0 反射颜色 a通道控制透明度
      _Color1 折射颜色 a 通道控制折射的强度

      // 最基本的颜色通过Fresnel来混合两个基本颜色
      //fixed fresnel = pow(saturate(dot(viewDir, bump)), 0.3);
      fixed fresnel = saturate(dot(viewDir, bump));
      fixed3 finalColor = lerp(_Color0,_Color1,fresnel);

      出自
      fixed fresnel = _FresnelScale + (1 - _FresnelScale) * pow(1 - dot(worldView, worldNormal), 5);
      lerp(diffuse, reflection, saturate(fresnel))

      也有版本color0和color1分别为深色、浅色,根据深度混合

    2. 折射:
      vs里,计算坐标:
      o.pos = UnityObjectToClipPos(v.vertex);

      // 屏幕位置
      o.scrPos = ComputeScreenPos(o.pos);
      函数具体分析可见:https://chengkehan.github.io/ComputeScreenPos.html

      unity注释:Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position.
      COMPUTE_EYEDEPTH(o.scrPos.z);

      // grabUV
      o.uvgrab =ComputeGrabScreenPos(o.pos);
      unity注释:Computes texture coordinate for sampling a GrabPass texure. Input is clip space position.
      冯乐乐书说:我们通过内置的ComputeGrabScreenPos函数来得到对应被抓取的屏幕图像的采样坐标。可以在UnityCG.cginc文件中看到其定义:他的主要代码和ComputeScreenPos基本类似,最大的不同是针对平台差异造成的采样坐标问题

      inline float4 ComputeGrabScreenPos (float4 pos) {
      #if UNITY_UV_STARTS_AT_TOP
      float scale = -1.0;
      #else
      float scale = 1.0;
      #endif
      float4 o = pos * 0.5f;
      o.xy = float2(o.x, o.y*scale) + o.w;
      o.zw = pos.zw;
      return o;
      }
      inline float4 ComputeNonStereoScreenPos(float4 pos) {
      float4 o = pos * 0.5f;
      #if defined(UNITY_HALF_TEXEL_OFFSET)
      o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w * _ScreenParams.zw;
      #else
      o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w;
      #endif
      o.zw = pos.zw;
      return o;
      }

      inline float4 ComputeScreenPos (float4 pos) {
      float4 o = ComputeNonStereoScreenPos(pos);
      #ifdef UNITY_SINGLE_PASS_STEREO
      o.xy = TransformStereoScreenSpaceTex(o.xy, pos.w);
      #endif
      return o;
      }

      fs中,bump是法线空间,在法线空间下计算折射偏移
      i.uvgrab.xy += bump.xy * _DistortionFactor * i.uvgrab.w * _GrabTexture_TexelSize.xy;
      fixed3 grapColor = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
      水折射偏移 grapColor即为折射光颜色。

      然后将2种颜色混合后的结构与折射颜色混合

    3. 软边 获取深度(实时软边还是用深度图)
      遇到bug,有的地方sceneZ小于objectZ,发现是由于没有深度贴图的原因。

    half4 projTC = UNITY_PROJ_COORD(i.scrPos);    
        #ifdef USE_SOFTEDGE
        // 边缘查找             
        //float sceneZ      = LinearEyeDepth (tex2Dproj(_LastCameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r);
        //srcPosRe.x *=_ScreenParams.x/_ScreenParams.y;
    
        float sceneZ        = LinearEyeDepth (tex2Dproj(_LastCameraDepthTexture, projTC).r);
        float objectZ       = i.scrPos.z;
    
        // 通过深度混合扭曲后的GrapTexture
        depthFactor   = saturate((sceneZ - objectZ) / _DepthFactor);//saturate(objectZ / _DepthFactor);
        #else
            fixed3 waterMap =tex2D(_MainTex, TRANSFORM_TEX(i.uv.xy, _MainTex)).rgb;
            depthFactor = saturate(waterMap.r+_InvRanges.y);
            _Color0.a *=saturate(waterMap.g*_InvRanges.z +_InvRanges.x);
        #endif
    1. 高光相关
      _SpecColor
      _Shininess 高光相关

    2. 反射
      _Cubemap
      _CubemapInstensity

    实时反射 _ReflectionTex

    fixed3 reflDir      = reflect(-viewDir, bump);
                    fixed3 reflCol;
        fixed3 reflection1 =texCUBE(_Cubemap, reflDir).rgb *_CubemapInstensity;
        half refDis = _RefDisFactor  * projTC.w * _ReflectionTex_TexelSize.xy;
    
                    projTC.x += bump.x *refDis;
                    //projTC.y += 0.5*bump.y *refDis;       
                    fixed4 reflection2 = tex2Dproj(_ReflectionTex, projTC);
    
                    reflCol =lerp(reflection1.rgb,reflection2.rgb,reflection2.a*depthFactor);
    

    //天空盒和实时反射贴图 通过深度和反射贴图的a通道混合

    非实时反射
    reflCol =texCUBE(_Cubemap, reflDir).rgb *_CubemapInstensity;

    然后计算 反射的比例
    finalColor +=reflCol*_ReflectVal*depthFactor;

    1. finalCol += spec;
      然后 finalCol *= _InvRanges.w.
      加雾效 透明度是_Color0.a.
      输出

    几部分混合:
    1. color0和color1用viewDotN混合;
    2. 将GrabCol和得到的通过depthFactor混合;
    3. 反射和已有相加,反射的强度用depthFactor和_ReflectVal控制;cubemap和实时反射用depthFactor和实时反射贴图的a通道控制。
    4. 最后加上高光反射。

    原来的水的版本:
    (1)深度计算:

    // Calculate the depth difference at the current pixel
    float depth = tex2Dproj(_CameraDepthTexture, IN.proj0).r;
    depth = LinearEyeDepth(depth);
    depth -= IN.proj0.z;

    深度和几个参数都有关系(ranges的x控制透明度、高光强度,折射偏移、折射和反射混合的菲涅尔,y控制两个颜色混合的参数,z控制折射的混合,折射也被y控制)

            // Calculate the color tint
            half4 col;
            col.rgb = lerp(_Color1.rgb, _Color0.rgb, ranges.y);
            col.a = ranges.x;
    

    // Initial material properties
    o.Alpha = col.a;
    o.Specular = col.a;
    o.Gloss = _Shininess;
    IN.proj0.xy += o.Normal.xy * 0.5;
    half3 reflection = tex2Dproj(_ReflectionTex, IN.proj0).rgb;
    reflection = lerp(reflection * col.rgb, reflection, fresnel * _ReflectionTint);
    //反射还用到ReflectionTint控制。

    //折射用ranges.z 和ranges。控制
    // High-quality refraction uses the grab pass texture
    IN.proj1.xy += o.Normal.xy * _GrabTexture_TexelSize.xy * (20.0 * IN.proj1.z * col.a);
    half3 refraction = tex2Dproj(_GrabTexture, IN.proj1).rgb;
    refraction = lerp(refraction, refraction * col.rgb, ranges.z);
    // Color the refraction based on depth
    refraction = lerp(lerp(col.rgb, col.rgb * refraction, ranges.y), refraction, ranges.y);

    //折射和反射的混合也和深度有关
    // Always assume 20% reflection right off the bat, and make the fresnel fade out slower so there is more refraction overall
    fresnel = fresnel fresnel;
    fresnel = (0.8 * fresnel + 0.2) * col.a;

            // Calculate the initial material color
            o.Albedo = lerp(refraction, reflection, fresnel) + foam;
    
    展开全文
  • Water shader

    2020-11-27 22:35:20
    <div><p>I'd like to admire the Sun being reflected by animated waves. <p>This can be either vertex+fragment or fragment only. Rivers could use the same logic without waves.</p><p>该提问来源于...
  • Water Shader Improvements

    2020-11-29 02:14:03
    -Cleaned up a bunch of things in the water shader. -Tiny cleanup in the dof shader <h1>Housekeeping stuff <p>-Adjusted gitignore to account for visual studio. -Added wxwidgets to gitignore. <p>-Added ...
  • shader关于water的文本

    2011-07-29 10:46:46
    一个watershader文本.好好利用
  • Minor water shader fixes

    2021-01-09 02:35:18
    2. Use the Incremental Compile Operation for water shader and RTT (now we seems to use it only for water geometry) , can you take a look?</p><p>该提问来源于开源项目:OpenMW/openmw</p></div>
  • Godot water shader

    2020-05-24 22:56:37
    list=PLtcDUwlxDv2K8KQ8WdFi6KUwizc-x_ZG9&index=3 使用Godot产生低模水面: ...波浪效果所使用的shader: shader_type spatial; uniform vec4 out_color :hint_color =vec4(0.0,0.2,1.0,1.0); uniform flo.

    原链接(贴在这里方便查找):
    https://www.youtube.com/watch?v=5MfcliFqjnE&list=PLtcDUwlxDv2K8KQ8WdFi6KUwizc-x_ZG9&index=3

    使用Godot产生低模水面:

    波浪效果所使用的shader:

     

    shader_type spatial;
    
    uniform vec4 out_color :hint_color =vec4(0.0,0.2,1.0,1.0);
    uniform float amount:hint_range(0.2,1.5)=0.8;
    uniform float beer_factor=0.2;
    
    float generateOffset(float x,float z,float val1,float val2,float time){
    	float speed=1.0;
    	float radiansX=((mod(x+z*x*val1,amount)/amount)+(time*speed)*mod(x*0.8+z,1.5))*2.0*3.14;
    	float radiansZ=((mod(val2*(x*z+x*z),amount)/amount)+(time*speed)*2.0*mod(x,2.0))*2.0*3.14;
    	return amount*0.5*(sin(radiansZ)+cos(radiansX));
    }
    
    vec3 applyDistoration(vec3 vertex,float time){
    	float xd=generateOffset(vertex.x,vertex.z,0.2,0.1,time);
    	float yd=generateOffset(vertex.x,vertex.z,0.2,0.1,time);
    	float zd=generateOffset(vertex.x,vertex.z,0.2,0.1,time);
    	return vertex+vec3(xd,yd,zd);
    }
    void vertex(){
    	VERTEX=applyDistoration(VERTEX,TIME*0.1);
    }
    
    void fragment(){
    	NORMAL=normalize(cross(dFdx(VERTEX),dFdy(VERTEX)));
    	METALLIC=0.6;
    	SPECULAR=0.5;
    	ROUGHNESS=0.2;
    	ALBEDO=out_color.xyz;
    	
    	float depth=texture(DEPTH_TEXTURE,SCREEN_UV).r;
    	depth=depth*2.0-1.0;
    	depth=PROJECTION_MATRIX[3][2]/(depth+PROJECTION_MATRIX[2][2]);
    	depth=depth+VERTEX.z;
    	depth=exp(-depth*beer_factor);
    	ALPHA=clamp(1.0-depth,0.0,1.0);
    	
    }

     

    展开全文
  • Unity Water Shader

    2019-09-26 14:11:31
    上图是一个物体浸入水中的效果 原理  我们使用相机渲染的整个场景的深度图减去需要忽略的模型的深度...//在shader中声明,需要设置相机开启渲染深度图;深度图中记录的深度值:深度纹理中每个像素所记录的深度值...

    上图是一个物体浸入水中的效果

    原理

      我们使用相机渲染的整个场景的深度图减去需要忽略的模型的深度,这里忽略的是图中蓝色部分,就保留了其他的深度值。

     

     

      用到Main Camera渲染的深度贴图: sampler2D _CameraDepthTexture; //在shader中声明,需要设置相机开启渲染深度图;深度图中记录的深度值:深度纹理中每个像素所记录的深度值是从0 到1 非线性分布的。精度通常是 24 位或16 位,这主要取决于所使用的深度缓冲区。当读取深度纹理时,我们可以得到一个0-1范围内的高精度值。如果你需要获取到达相机的距离或者其他线性关系的值,那么你需要手动计算它。

      在顶点着色器中获取顶点在屏幕空间的位置,用做采样深度图的uv坐标:

                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.scrPos = ComputeScreenPos(o.pos);//将返回片段着色器的屏幕位置
                    COMPUTE_EYEDEPTH(o.scrPos.z);//计算顶点摄像机空间的深度:距离裁剪平面的距离,线性变化;

     

      在像素着色器中采样Main Camera渲染的深度贴图(摄像机能看到的整个场景的深度图):

      

              //计算当前像素深度
                    float  depth= tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r;//深度值 [0,1]
                    depth = LinearEyeDepth(depth);//深度根据相机的裁剪范围的值[0.3,1000],是将经过透视投影变换的深度值还原了

     

      将此图的值构建出灰度图,输出查看深度图效果: return float4(depth-999,depth-999,depth-999,1); 可以看出深度图中,没有被遮挡的部分并没有表现出线性渐变,说明区域的值被默认填充为最大的深度,我并没有找到相关的文件说明,有朋友找到,麻烦私信下。

     

      现在我们测试下顶点在屏幕空间的深度值(仅仅是计算需要计算的模型顶点的深度,与摄像机的深度图有区别),该值被顶点着色器记录在o.srcPos.z中,将值在像素着色器中输出,查看效果: return float4(i.scrPos.z,i.scrPos.z,i.scrPos.z,1); 

      (上图)想象沿着摄像机的方向,该值呈现出线性分布,说明是该点到近裁减面(以近裁剪面)的距离,假如摄像机裁剪空间是[0.3,10],那么该值在大于等于1的时候呈现出白色,在[0,1]区间内是灰度图。

       我们将顶点的深度值作为通道输出: return float4(i.scrPos.z,i.scrPos.z,i.scrPos.z,i.scrPos.z); 

    Tags {"Queue" = "Transparent"}
    Blend SrcAlpha OneMinusSrcAlpha 

    这个样子,我们就实现根据摄像机与顶点之间的深度值变化,实现与视角有关的透明效果,深度值在[0,1]范围内,则会透明,大于1则会呈现出材质颜色;

     

    现在我们将我们转化过的深度图深度值(线性分布)与顶点深度相减: depth -= i.scrPos.z; 

     

    为什么其他地方白色相减不等于黑色? 

      个人认为:在深度图中,没有被遮挡的地方被默认填充为最大深度1,转化为距离相机的线性距离时,也被转化为最大距离,例1000。这个值再减去模型的深度时,结果远大于模型深度,用颜色显示出来,即为白色。

     

    现在将深度值输出到像素着色器的rgba通道:查看效果: return float4(depth,depth,depth, depth); 与模型相交部分变成了透明。

     

    接下来,我们使用变量ColorDepth控制深度值,并增加2个颜色,来表现深度的范围:

        Properties
        {    _Color0("Water Color",Color) = (1,1,1,1)//水的颜色
            _Color1("Water Depth",Color) = (0,0,0,0)//水的深度的颜色
            _Alpha("Alpha",Range( 0,1))= 1//水面的正题透明度
            _ColorDepth("ColorDepth",Range( 0,1))= 0//水的深度
        }
                    //计算水的透明度: 使用深度值
                    float alpha = saturate( _Alpha*depth);
    
                    //计算颜色深度:
                    float colDepth = saturate(_ColorDepth*depth);
                    colDepth = 1-colDepth;
                    colDepth = lerp(colDepth, colDepth*colDepth*colDepth, 0.5);//调整深度,看个人喜好
    
                    half3 col;
                    col.rgb = lerp(_Color0.rgb, _Color1.rgb, colDepth);
    
                    return float4(col.rgb, alpha );

     

    在物体遮挡处,蓝色越深,表示越深,天蓝色,是海水颜色。现在除了物体遮挡处的深度表现正确,其他地方审定其实不正确。我们在水下加一块地皮:

    是不是有感觉了,我们再调节下颜色等参数:

    源代码:

    Shader "JQM/DepthTest_1"
    {
        Properties
        {    _Color0("Water Color",Color) = (1,1,1,1)//水的颜色
            _Color1("Water Depth",Color) = (0,0,0,0)//水的深度的颜色
            _Alpha("Alpha",Range( 0,1))= 1//水面的正题透明度
            _ColorDepth("ColorDepth",Range( 0,1))= 0//水的深度
        }
        SubShader
        {
            Tags {"Queue" = "Transparent"}
    
            Pass
            {
                Blend SrcAlpha OneMinusSrcAlpha 
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                
                #include "UnityCG.cginc"
    
                struct appdata
                {
                    float4 vertex : POSITION;
                    float2 uv : TEXCOORD0;
                };
    
                struct VertexOutput
                {
                    float2 uv : TEXCOORD0;
                    float4 pos : SV_POSITION;
                    float4 scrPos : TEXCOORD1;
                };
    
    
                float4 _Color0;
                float4 _Color1;
                float _Alpha;//水的透明度
                float _ColorDepth;
    
                sampler2D _CameraDepthTexture;
                
                VertexOutput vert (appdata v)
                {
                    VertexOutput o;
    
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.scrPos = ComputeScreenPos(o.pos);//将返回片段着色器的屏幕位置
                    COMPUTE_EYEDEPTH(o.scrPos.z);//计算顶点摄像机空间的深度:距离裁剪平面的距离
                    return o;
                }
                
                fixed4 frag (VertexOutput i) : COLOR
                {
                    //计算当前像素深度
                    float  depth= tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r;//UNITY_PROJ_COORD:深度值 [0,1]
                    depth = LinearEyeDepth(depth);//深度根据相机的裁剪范围的值[0.3,1000],是将经过透视投影变换的深度值还原了
                    depth -= i.scrPos.z;
                    //计算水的透明度: 使用深度值
                    float alpha = saturate( _Alpha*depth);
    
                    //计算颜色深度:
                    float colDepth = saturate(_ColorDepth*depth);
                    colDepth = 1-colDepth;
                    colDepth = lerp(colDepth, colDepth*colDepth*colDepth, 0.5);//调整深度,看个人喜好
    
                    half3 col;
                    col.rgb = lerp(_Color0.rgb, _Color1.rgb, colDepth);
    
                    return float4(col.rgb, alpha );  
                }
                ENDCG
            }
        }
    }

     

    现在基本完成了物体浸入水中的效果:

    接下来,我还需要什么效果呢?

    1. UV偏移的动态水面;

    2. 反射;

    3. 折射;

     

     

    关于相机透明度问题

    深度增加,透明度降低。

     

    转载于:https://www.cnblogs.com/jqm304775992/p/4939977.html

    展开全文
  • Godot water shader 2

    2020-06-02 23:21:14
    ????:更加真实的水面 ...Realistic Water Shader for GODOT 3.1.1 Copyright (c) 2019 UnionBytes, Achim Menzel (alias AiYori) Permission is hereby granted, free of charge, to any person obtain

    😮:更加真实的水面

    源项目地址: https://github.com/sunkper/Project-Summer-Island
    在这里插入图片描述

    🔞复杂water shader

    /*
    Realistic Water Shader for GODOT 3.1.1
    Copyright (c) 2019 UnionBytes, Achim Menzel (alias AiYori)
    Permission is hereby granted, free of charge, to any person obtaining a copy of this 
    software and associated documentation files (the "Software"), to deal in the Software
    without restriction, including without limitation the rights to use, copy, modify,
    merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to the following
    conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
    PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
    OR OTHER DEALINGS IN THE SOFTWARE.
    -- UnionBytes <https://www.unionbytes.de/>
    -- YouTube: <https://www.youtube.com/user/UnionBytes>
    */
    
    
    // For this shader min. GODOT 3.1.1 is required, because 3.1 has a depth buffer bug!
    shader_type 	spatial;
    render_mode 	cull_back,diffuse_burley,specular_schlick_ggx, blend_mix;
    
    
    // Wave settings:
    uniform float	wave_speed		 = 0.5; // Speed scale for the waves
    uniform vec4	wave_a			 = vec4(1.0, 1.0, 0.35, 3.0); 	// xy = Direction, z = Steepness, w = Length
    uniform	vec4	wave_b			 = vec4(1.0, 0.6, 0.30, 1.55);	// xy = Direction, z = Steepness, w = Length
    uniform	vec4	wave_c			 = vec4(1.0, 1.3, 0.25, 0.9); 	// xy = Direction, z = Steepness, w = Length
    
    // Surface settings:
    uniform vec2 	sampler_scale 	 = vec2(0.25, 0.25); 			// Scale for the sampler
    uniform vec2	sampler_direction= vec2(0.05, 0.04); 			// Direction and speed for the sampler offset
    
    uniform sampler2D uv_sampler : hint_aniso; 						// UV motion sampler for shifting the normalmap
    uniform vec2 	uv_sampler_scale = vec2(0.25, 0.25); 			// UV sampler scale
    uniform float 	uv_sampler_strength = 0.04; 					// UV shifting strength
    
    uniform sampler2D normalmap_a_sampler : hint_normal;			// Normalmap sampler A
    uniform sampler2D normalmap_b_sampler : hint_normal;			// Normalmap sampler B
    
    uniform sampler2D foam_sampler : hint_black;					// Foam sampler
    uniform float 	foam_level 		 = 0.5;							// Foam level -> distance from the object (0.0 - 0.5)
    
    // Volume settings:
    uniform float 	refraction 		 = 0.075;						// Refraction of the water
    
    uniform vec4 	color_deep : hint_color;						// Color for deep places in the water, medium to dark blue
    uniform vec4 	color_shallow : hint_color;						// Color for lower places in the water, bright blue - green
    uniform float 	beers_law		 = 2.0;							// Beers law value, regulates the blending size to the deep water level
    uniform float 	depth_offset	 = -0.75;						// Offset for the blending
    
    // Projector for the water caustics:
    uniform mat4	projector;										// Projector matrix, mostly the matric of the sun / directlight
    uniform sampler2DArray caustic_sampler : hint_black;			// Caustic sampler, (Texture array with 16 Textures for the animation)
    
    
    // Vertex -> Fragment:
    varying float 	vertex_height;									// Height of the water surface
    varying vec3 	vertex_normal;									// Vertex normal -> Needed for refraction calculation
    varying vec3 	vertex_binormal;								// Vertex binormal -> Needed for refraction calculation
    varying vec3 	vertex_tangent;									// Vertex tangent -> Needed for refraction calculation
    
    varying mat4 	inv_mvp; 										// Inverse ModelViewProjection matrix -> Needed for caustic projection
    
    
    // Wave function:
    vec4 wave(vec4 parameter, vec2 position, float time, inout vec3 tangent, inout vec3 binormal)
    {
    	float	wave_steepness	 = parameter.z;
    	float	wave_length		 = parameter.w;
    
    	float	k				 = 2.0 * 3.14159265359 / wave_length;
    	float 	c 				 = sqrt(9.8 / k);
    	vec2	d				 = normalize(parameter.xy);
    	float 	f 				 = k * (dot(d, position) - c * time);
    	float 	a				 = wave_steepness / k;
    	
    			tangent			+= normalize(vec3(1.0-d.x * d.x * (wave_steepness * sin(f)), d.x * (wave_steepness * cos(f)), -d.x * d.y * (wave_steepness * sin(f))));
    			binormal		+= normalize(vec3(-d.x * d.y * (wave_steepness * sin(f)), d.y * (wave_steepness * cos(f)), 1.0-d.y * d.y * (wave_steepness * sin(f))));
    
    	return vec4(d.x * (a * cos(f)), a * sin(f) * 0.25, d.y * (a * cos(f)), 0.0);
    }
    
    
    // Vertex shader:
    void vertex()
    {
    	float	time			 = TIME * wave_speed;
    	
    	vec4	vertex			 = vec4(VERTEX, 1.0);
    	vec3	vertex_position  = (WORLD_MATRIX * vertex).xyz;
    	
    			vertex_tangent 	 = vec3(0.0, 0.0, 0.0);
    		 	vertex_binormal  = vec3(0.0, 0.0, 0.0);
    	
    			vertex 			+= wave(wave_a, vertex_position.xz, time, vertex_tangent, vertex_binormal);
    			vertex 			+= wave(wave_b, vertex_position.xz, time, vertex_tangent, vertex_binormal);
    			vertex 			+= wave(wave_c, vertex_position.xz, time, vertex_tangent, vertex_binormal);
    	
    			vertex_position  = vertex.xyz;
    	
    			vertex_height	 = (PROJECTION_MATRIX * MODELVIEW_MATRIX * vertex).z;
    	
    			TANGENT			 = vertex_tangent;
    			BINORMAL		 = vertex_binormal;
    			vertex_normal	 = normalize(cross(vertex_binormal, vertex_tangent));
    			NORMAL			 = vertex_normal;
    		
    			UV				 = vertex.xz * sampler_scale;
    	
    			VERTEX			 = vertex.xyz;
    			
    			inv_mvp = inverse(PROJECTION_MATRIX * MODELVIEW_MATRIX);
    }
    
    
    // Fragment shader:
    void fragment()
    {
    	// Calculation of the UV with the UV motion sampler
    	vec2	uv_offset 					 = sampler_direction * TIME;
    	vec2 	uv_sampler_uv 				 = UV * uv_sampler_scale + uv_offset;
    	vec2	uv_sampler_uv_offset 		 = uv_sampler_strength * texture(uv_sampler, uv_sampler_uv).rg * 2.0 - 1.0;
    	vec2 	uv 							 = UV + uv_sampler_uv_offset;
    	
    	// Normalmap:
    	vec3 	normalmap					 = texture(normalmap_a_sampler, uv - uv_offset*2.0).rgb * 0.75;		// 75 % sampler A
    			normalmap 					+= texture(normalmap_b_sampler, uv + uv_offset).rgb * 0.25;			// 25 % sampler B
    	
    	// Refraction UV:
    	vec3	ref_normalmap				 = normalmap * 2.0 - 1.0;
    			ref_normalmap				 = normalize(vertex_tangent*ref_normalmap.x + vertex_binormal*ref_normalmap.y + vertex_normal*ref_normalmap.z);
    	vec2 	ref_uv						 = SCREEN_UV + (ref_normalmap.xy * refraction) / vertex_height;
    	
    	// Ground depth:
    	float 	depth_raw					 = texture(DEPTH_TEXTURE, ref_uv).r * 2.0 - 1.0;
    	float	depth						 = PROJECTION_MATRIX[3][2] / (depth_raw + PROJECTION_MATRIX[2][2]);
    			
    	float 	depth_blend 				 = exp((depth+VERTEX.z + depth_offset) * -beers_law);
    			depth_blend 				 = clamp(1.0-depth_blend, 0.0, 1.0);	
    	float	depth_blend_pow				 = clamp(pow(depth_blend, 2.5), 0.0, 1.0);
    
    	// Ground color:
    	vec3 	screen_color 				 = textureLod(SCREEN_TEXTURE, ref_uv, depth_blend_pow * 2.5).rgb;
    	
    	vec3 	dye_color 					 = mix(color_shallow.rgb, color_deep.rgb, depth_blend_pow);
    	vec3	color 						 = mix(screen_color*dye_color, dye_color*0.25, depth_blend_pow*0.5);
    	
    	// Caustic screen projection
    	vec4 	caustic_screenPos 			 = vec4(ref_uv*2.0-1.0, depth_raw, 1.0);
    	vec4 	caustic_localPos 			 = inv_mvp * caustic_screenPos;
    			caustic_localPos			 = vec4(caustic_localPos.xyz/caustic_localPos.w, caustic_localPos.w);
    	
    	vec2 	caustic_Uv 					 = caustic_localPos.xz / vec2(1024.0) + 0.5;
    	vec4	caustic_color				 = texture(caustic_sampler, vec3(caustic_Uv*300.0, mod(TIME*14.0, 16.0)));
    
    			color 						*= 1.0 + pow(caustic_color.r, 1.50) * (1.0-depth_blend) * 6.0;
    
    	// Foam:
    			if(depth + VERTEX.z < foam_level && depth > vertex_height-0.1)
    			{
    				float foam_noise = clamp(pow(texture(foam_sampler, (uv*4.0) - uv_offset).r, 10.0)*40.0, 0.0, 0.2);
    				float foam_mix = clamp(pow((1.0-(depth + VERTEX.z) + foam_noise), 8.0) * foam_noise * 0.4, 0.0, 1.0);
    				color = mix(color, vec3(1.0), foam_mix);
    			}
    	
    	// Set all values:
    	ALBEDO = color;
    	METALLIC = 0.1;
    	ROUGHNESS = 0.15;
    	SPECULAR = depth_blend_pow * 1.0;
    	NORMALMAP = normalmap;
    	NORMALMAP_DEPTH = 2.5;
    }
    
    展开全文
  • DCG Water Shader 2.0.7z

    2020-06-23 10:40:37
    u3d 2018 版测试通过 DCG Water Shader 2.0.7z 积分不足了,赚点积分~
  • unity shader graph Water

    2020-10-18 22:30:41
    连线图 会有的
  • unity-shader-水water实现

    千次阅读 2019-05-25 01:33:39
    title: unity-shader-水water实现 categories: Unity3d-Shader tags: [unity, shader, water, 水] date: 2019-05-21 06:49:01 comments: false unity-shader-水water实现 前篇 Chapter 1. Effective Water ...
  • Water Shader is an animated water material. This package includes: - Shader/Material and texture - customizable material - landscape material with foam movement - demo scene - tesselated wave Made ...
  • water ripple shader

    2018-01-24 17:34:21
    https://www.shadertoy.com/view/MsBSz1 http://blog.csdn.net/chenxizhibi/article/details/51291930 const float timeFactor = 10.0; float ripple(float dist, float rippleIntensity, float rippleScale)
  • Water Shader Water Shader用来创建海洋 1. 主要属性   1).没有必要为Water Shaders设置Diffuse和Specular Maps,但需要一张BumpMap来创建水边的涟漪和波浪,用来做折射。 2).Soft intersection factor...
  • water_shader.gif 参数设置 不进行背面剔除,这样从水下也能看到。 投射阴影和接受阴影都勾掉,因为水面不需要。 参数设置.png 输出节点 _color和_normalMap后面都有流程计算。 Glossiness是水面...
  • <div><p>it would be convenient to be able to apply the water shader on different object , so as to be able to manage more water with different parameters such as water direction, color, etc etc</p><p>...
  • Water Shader is an animated water material. This package includes: - Shader/Material and texture - customizable material - landscape material with foam movement - demo scene - tesselated wave ...
  • Unity3D 水面效果插件 Tasharen Water Shader U3D插件
  • DCG Water Shader 2.0.unitypackage, 牛逼shader,水表现真实震撼
  • Water水流shader+Forge烟雾流shader(管路)(unitypackage).zip ---管道水流、气体烟雾流shader
  • <div><p>该提问来源于开源项目:MovingBlocks/Terasology</p></div>
  • Natural.Water.Shader

    2013-03-22 22:54:01
    关于3D中water制作的不可多得好书,值得一读
  • 风格化水特效插件,适用于Unity3D,可以通过简单调整参数实现你想要的水面效果。有非常丰富的水面效果,包含island、pond、lake3个demo场景。
  • Highly customizable to suit your art direction through various parameters. This package focuses on providing artistic freedom, rather than a realistic water simulation
  • Unity风格化海水,最低支持到Unity2017,支持移动端,如果想在Unity手游上开发一个卡通渲染风格化的海水,是很好的参考,相对比较完整
  • <div><p>Forum thread: <a href="https://forum.unity.com/threads/water-shader.995380/">Water Shader</a></p> <p>This water shader is based on the following implementation: ;MHdDUqJHJxM">...
  • 超棒的风格化水特效插件,适用于Unity3D,可以通过简单调整参数实现你想要的水面效果。有非常丰富的水面效果,包含island、pond、lake3个demo场景。up主的毕设中也用到了,主要是调整了水面的噪波、颜色等。
  • } } 水shader Shader "" { Properties { // 浅颜色 _DepthGradientShallow("Depth Gradient Shallow", Color) = (0.325, 0.807, 0.971, 0.725) // 深颜色 _DepthGradientDeep("Depth Gradient Deep", Color...

空空如也

空空如也

1 2 3 4 5 ... 15
收藏数 286
精华内容 114
关键字:

shaderwater