Search Unity

Bubble Shader Help

Discussion in 'Shaders' started by tom-AGS, Mar 18, 2020.

  1. tom-AGS

    tom-AGS

    Joined:
    Mar 16, 2020
    Posts:
    1
    Hey Guys,

    I've been using this bubble shader which was courteously provided here.

    https://github.com/JPBotelho/Soap-Bubble

    I have no clue about shader code, but when i apply it, the transparency alpha ( the fresnel effect) seems locked to one direction?

    So i only get the bubble effect if i look from the X axis? Then when i spin the camera to z axis, it looks weird.

    Rotating the mesh has no effect, im thinking it has something to do with the "refl2Refr" property in the code but i have no idea about shaders. Any help would be greatly appreaciated. Thanks so much.

    I'll paste the shader code below. and attach some images.


    Code (CSharp):
    1. Shader "Bubble"
    2.   {
    3.     Properties
    4.     {
    5.       _MainTex ("Texture", 2D) = "white" {}
    6.       _Cube ("Cubemap", CUBE) = "" {}
    7.       _AlphaCubemap ("Alpha Cubemap", CUBE) = "" {}
    8.  
    9.       _Scale ("Scale", Range(0.1, 15.0)) = 3.0
    10.       _Bias ("Bias", Range(-5, 5.0)) = 3.0
    11.       _Power ("Power", Range(0.1, 15.0)) = 3.0
    12.  
    13.       _Mult ("Mult", Range(0,1)) = 1.0
    14.     }
    15.     SubShader
    16.     {  
    17.       Tags
    18.       {
    19.         "Queue"="Transparent"
    20.         "RenderType"="Transparent"
    21.       }
    22.  
    23.       CGPROGRAM
    24.       #pragma surface surf Standard fullforwardshadows alpha:fade
    25.  
    26.       struct Input
    27.       {
    28.           float2 uv_MainTex;
    29.           float3 worldRefl;
    30.           float3 viewDir;
    31.       };
    32.            
    33.       sampler2D _MainTex;
    34.       samplerCUBE _Cube;
    35.       samplerCUBE _AlphaCubemap;
    36.  
    37.       float _Bias;
    38.       float _Power;
    39.       float _Scale;
    40.       float _Mult;
    41.  
    42.       float randomNum(in float2 uv)
    43.           {
    44.              float2 noise = (frac(sin(dot(uv, float2(12.9898,78.233)*2.0)) * 43758.5453));
    45.              return abs(noise.x + noise.y) * 0.1;
    46.       }
    47.  
    48.  
    49.       void surf (Input IN, inout SurfaceOutputStandard o)
    50.       {
    51.         float3 cubeSample = texCUBE (_Cube, IN.worldRefl);
    52.         float3 alphaSample = texCUBE (_AlphaCubemap, IN.worldRefl);
    53.         float3 textureSample = tex2D(_MainTex, IN.uv_MainTex);
    54.        
    55.         float fresnelTerm = _Scale * o.Normal + _Bias; //- _Bias;
    56.         float refl2Refr = 1 - fresnelTerm - .3;
    57.         //o.Alpha = 1 - (pow(alphaSample, _Power) + refl2Refr);
    58.  
    59.         alphaSample = pow (alphaSample, _Power);
    60.  
    61.         o.Albedo = lerp (cubeSample, cubeSample * textureSample, 1 - alphaSample); //Makes it brighter
    62.         o.Emission = lerp (cubeSample, cubeSample * textureSample, 1 - alphaSample);
    63.         o.Alpha = lerp(_Mult, 1.0, refl2Refr + alphaSample);
    64.       }
    65.       ENDCG
    66.     }
    67.     Fallback "Diffuse"
    68.   }
     

    Attached Files:

    rul2024 likes this.