Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Flickering water material in VR mode

Discussion in 'Shaders' started by BCyclik, Jun 3, 2022.

  1. BCyclik

    BCyclik

    Joined:
    Feb 12, 2020
    Posts:
    2
    Hi!

    Please tell me why, the water starts to flicker when entering VR mode. A shader is used for water
    Code (CSharp):
    1.  
    2. Shader "WaterVR/Surface Light Clear"
    3. {
    4.     Properties
    5.     {
    6.         [Header(Color Settings)] _Color("Color", Color) = (1,1,1,0)
    7.         _Tint("Tint", Color) = (0,0,0,0)
    8.         [Header(Normal Settings)]_Normal("Normal", 2D) = "bump" {}
    9.         _Normal2nd("Normal 2nd", 2D) = "bump" {}
    10.         _Smoothness("Smoothness", Range(0 , 1)) = 0.8
    11.         _NormalPower("Normal Power", Range(0 , 1)) = 1
    12.         _NormalPower2nd("Normal Power 2nd", Range(0 , 1)) = 0.5
    13.         [Header(Animation Settings)]_RipplesSpeed("Ripples Speed", Float) = 1
    14.         _RipplesSpeed2nd("Ripples Speed 2nd", Float) = 1
    15.         _SpeedX("Speed X", Float) = 0
    16.         _SpeedY("Speed Y", Float) = 0
    17.         [Toggle][Header(Visual Fixes)]_ZWrite1("ZWrite", Float) = 1
    18.         [HideInInspector] _texcoord("", 2D) = "white" {}
    19.         [HideInInspector] __dirty("", Int) = 1
    20.         [Header(Forward Rendering Options)]
    21.         [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
    22.         [ToggleOff] _GlossyReflections("Reflections", Float) = 1.0
    23.     }
    24.  
    25.         SubShader
    26.         {
    27.             Tags{ "RenderType" = "Opaque"  "Queue" = "Transparent-1" "IgnoreProjector" = "True" "IsEmissive" = "true"  }
    28.             Cull Back
    29.             ZWrite[_ZWrite1]
    30.             GrabPass{ "_GrabWater" }
    31.             CGPROGRAM
    32.             #include "UnityStandardUtils.cginc"
    33.             #include "UnityShaderVariables.cginc"
    34.             #pragma target 5.0
    35.             #pragma shader_feature _SPECULARHIGHLIGHTS_OFF
    36.             #pragma shader_feature _GLOSSYREFLECTIONS_OFF
    37.             #if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
    38.             #define ASE_DECLARE_SCREENSPACE_TEXTURE(tex) UNITY_DECLARE_SCREENSPACE_TEXTURE(tex);
    39.             #else
    40.             #define ASE_DECLARE_SCREENSPACE_TEXTURE(tex) UNITY_DECLARE_SCREENSPACE_TEXTURE(tex)
    41.             #endif
    42.             #pragma surface surf Standard keepalpha noshadow exclude_path:deferred
    43.             struct Input
    44.             {
    45.                 float2 uv_texcoord;
    46.                 float4 screenPos;
    47.             };
    48.  
    49.             uniform sampler2D _Normal;
    50.             uniform float _NormalPower;
    51.             uniform float _RipplesSpeed;
    52.             uniform float4 _Normal_ST;
    53.             uniform sampler2D _Sampler0409;
    54.             uniform float _SpeedX;
    55.             uniform float _SpeedY;
    56.             uniform sampler2D _Normal2nd;
    57.             uniform float _NormalPower2nd;
    58.             uniform float _RipplesSpeed2nd;
    59.             uniform float4 _Normal2nd_ST;
    60.             uniform sampler2D _Sampler0410;
    61.             uniform float4 _Tint;
    62.             ASE_DECLARE_SCREENSPACE_TEXTURE(_GrabWater)
    63.             uniform float4 _Color;
    64.             uniform float _Smoothness;
    65.             uniform float _ZWrite1;
    66.  
    67.  
    68.             inline float4 ASE_ComputeGrabScreenPos(float4 pos)
    69.             {
    70.                 #if UNITY_UV_STARTS_AT_TOP
    71.                 float scale = -1.0;
    72.                 #else
    73.                 float scale = 1.0;
    74.                 #endif
    75.                 float4 o = pos;
    76.                 o.y = pos.w * 0.5f;
    77.                 o.y = (pos.y - o.y) * _ProjectionParams.x * scale + o.y;
    78.                 return o;
    79.             }
    80.  
    81.  
    82.             void surf(Input i , inout SurfaceOutputStandard o)
    83.             {
    84.                 float mulTime187 = _Time.y * _RipplesSpeed;
    85.                 float2 uv0_Normal = i.uv_texcoord * _Normal_ST.xy + _Normal_ST.zw;
    86.                 float2 panner22 = (mulTime187 * float2(-0.04,0) + uv0_Normal);
    87.                 float mulTime395 = _Time.y * (_SpeedX / (_Normal_ST.xy).x);
    88.                 float mulTime403 = _Time.y * (_SpeedY / (_Normal_ST.xy).y);
    89.                 float2 appendResult402 = (float2(mulTime395 , mulTime403));
    90.                 float2 temp_output_422_0 = (_Normal_ST.xy * appendResult402);
    91.                 float2 panner19 = (mulTime187 * float2(0.03,0.03) + uv0_Normal);
    92.                 float mulTime323 = _Time.y * _RipplesSpeed2nd;
    93.                 float2 uv0_Normal2nd = i.uv_texcoord * _Normal2nd_ST.xy + _Normal2nd_ST.zw;
    94.                 float2 temp_output_397_0 = (uv0_Normal2nd + float2(0,0));
    95.                 float2 panner320 = (mulTime323 * float2(0.03,0.03) + temp_output_397_0);
    96.                 float2 temp_output_423_0 = (appendResult402 * _Normal2nd_ST.xy);
    97.                 float2 panner321 = (mulTime323 * float2(-0.04,0) + temp_output_397_0);
    98.                 float3 NormalWater315 = BlendNormals(BlendNormals(UnpackScaleNormal(tex2D(_Normal, (panner22 + temp_output_422_0)), _NormalPower) , UnpackScaleNormal(tex2D(_Normal, (panner19 + temp_output_422_0)), _NormalPower)) , BlendNormals(UnpackScaleNormal(tex2D(_Normal2nd, (panner320 + temp_output_423_0)), _NormalPower2nd) , UnpackScaleNormal(tex2D(_Normal2nd, (panner321 + temp_output_423_0)), _NormalPower2nd)));
    99.                 o.Normal = NormalWater315;
    100.                 o.Albedo = _Tint.rgb;
    101.                 float4 ase_screenPos = float4(i.screenPos.xyz , i.screenPos.w + 0.00000000001);
    102.                 float4 ase_grabScreenPos = ASE_ComputeGrabScreenPos(ase_screenPos);
    103.                 float4 screenColor223 = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_GrabWater,ase_grabScreenPos.xy / ase_grabScreenPos.w);
    104.                 o.Emission = (screenColor223 * _Color).rgb;
    105.                 o.Smoothness = (_Smoothness + (_ZWrite1 * 0.0));
    106.                 o.Alpha = 1;
    107.             }
    108.  
    109.             ENDCG
    110.         }
    111.             CustomEditor "ASEMaterialInspector"
    112. }
     
  2. BCyclik

    BCyclik

    Joined:
    Feb 12, 2020
    Posts:
    2