Search Unity

Aubergines Backgrounds (Free stuff)

Discussion in 'Shaders' started by aubergine, Jan 2, 2014.

  1. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    I recently converted some of the nice shadertoy shaders to Unity.
    These are pretty much useless stuff but very good for learning, so i decided to share here.

    HOW TO USE:
    1- Add THIS SCRIPT to your main camera.
    2- Make a material out of one of the shaders and adjust parameters on the material (if any)
    3- Run the game.

    Notes:
    I am writing the shaders to be used as a background(drawn first before anything like a skybox)
    So, if you please you can use them as animated backgrounds.

    If you want to add shaders of your own, you are very welcome.

    LICENCE:
    NON COMMERCIAL USE ONLY (atleast for the shaders i share).

    NOTE: Moved some of the shaders to my website and added webdemos.
     
    Last edited: Mar 15, 2014
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Infinite tunnel (Textured and straight motion):

    Code (csharp):
    1. Shader "Aubergine/PreProcessFx/Tunnel-Textured-Straight" {
    2.     Properties {
    3.         _MainTex("Base (RGB)", 2D) = "white" {}
    4.         _Speed("Speed", Float) = 1.86
    5.         _TunnelFog("Fog", Range(0.5, 6.0)) = 1.6
    6.         _Zoom("Zoom", Range(1.0, 16.0)) = 2.0
    7.         _Scale("Checker Scale", Range(0.1, 1.0)) = 0.1
    8.     }
    9.  
    10.     SubShader {
    11.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    12.         LOD 100
    13.  
    14.         Pass {
    15.             Name "BASE"
    16.             Tags { "LightMode" = "Always" }
    17.  
    18.             Fog { Mode off }
    19.             ZWrite Off
    20.             Cull Off
    21.  
    22.             CGPROGRAM
    23.             #pragma exclude_renderers xbox360 ps3 flash
    24.             #pragma vertex vert
    25.             #pragma fragment frag
    26.             #pragma fragmentoption ARB_precision_hint_fastest
    27.  
    28.             sampler2D _MainTex;
    29.             fixed4 _MainTex_ST;
    30.             fixed _Speed, _TunnelFog;
    31.             half _Zoom;
    32.  
    33.             struct a2v {
    34.                 float4 vertex : POSITION;
    35.                 float4 texcoord : TEXCOORD0;
    36.             };
    37.  
    38.             struct v2f {
    39.                 float4 pos : SV_POSITION;
    40.                 float2 uv : TEXCOORD0;
    41.             };
    42.  
    43.             v2f vert(a2v v) {
    44.                 v2f o;
    45.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    46.                 o.uv = v.texcoord.xy;
    47.                 return o;
    48.             }
    49.  
    50.             fixed4 frag(v2f i) : COLOR {
    51.                 half2 pos = i.uv - 0.5;
    52.                 half2 p = pos * _Zoom;
    53.                 float dist = length(p);
    54.                 float2 nuv = float2(p.x / dist, 1.0 / abs(dist) + _Time.y * _Speed);
    55.                 fixed3 col = tex2D(_MainTex, nuv * _MainTex_ST.xy).rgb * pow(abs(dist), _TunnelFog);
    56.                 return fixed4(col.rgb, 1.0);
    57.             }
    58.             ENDCG
    59.         }
    60.     }
    61.  
    62.     Fallback Off
    63. }
     

    Attached Files:

    • $1.jpg
      $1.jpg
      File size:
      74 KB
      Views:
      1,190
  3. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Tunnel (with procedural checker texture rotating CCW):

    Code (csharp):
    1. Shader "Aubergine/PreProcessFx/Tunnel-RotateCCW" {
    2.     Properties {
    3.         _Speed("Speed", Float) = 1.86
    4.         _TunnelFog("Fog", Range(0.5, 6.0)) = 1.6
    5.         _Zoom("Zoom", Range(1.0, 16.0)) = 2.0
    6.     }
    7.  
    8.     CGINCLUDE
    9.     fixed3 checkers(float2 p, float s) {
    10.         float c = clamp(ceil(sin(p.x / s) * sin(p.y / s)) * s * 10.0, 0.1, 1.0);
    11.         return fixed3(c, c, c);
    12.     }
    13.     ENDCG
    14.  
    15.     SubShader {
    16.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    17.         LOD 100
    18.  
    19.         Pass {
    20.             Name "BASE"
    21.             Tags { "LightMode" = "Always" }
    22.  
    23.             Fog { Mode off }
    24.             ZWrite Off
    25.             Cull Off
    26.  
    27.             CGPROGRAM
    28.             #pragma exclude_renderers xbox360 ps3 flash
    29.             #pragma vertex vert
    30.             #pragma fragment frag
    31.             #pragma fragmentoption ARB_precision_hint_fastest
    32.  
    33.             fixed _Speed, _TunnelFog;
    34.             half _Zoom;
    35.  
    36.             struct a2v {
    37.                 float4 vertex : POSITION;
    38.                 float4 texcoord : TEXCOORD0;
    39.             };
    40.  
    41.             struct v2f {
    42.                 float4 pos : SV_POSITION;
    43.                 float2 uv : TEXCOORD0;
    44.             };
    45.  
    46.             v2f vert(a2v v) {
    47.                 v2f o;
    48.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    49.                 o.uv = v.texcoord.xy;
    50.                 return o;
    51.             }
    52.  
    53.             fixed4 frag(v2f i) : COLOR {
    54.                 half2 pos = i.uv - 0.5;
    55.                 half2 p = pos * _Zoom;
    56.                 float cc = cos(_Time.y);
    57.                 float ss = sin(_Time.y);
    58.                 p = half2((cc * p.x + ss * p.y), (-ss * p.x + cc * p.y));
    59.                 float dist = length(p);
    60.                 float2 nuv = float2(p.x / dist, 1.0 / abs(dist) + _Time.y * _Speed);
    61.                 fixed3 col = checkers(nuv, 0.10) * pow(abs(dist), _TunnelFog);
    62.                 return fixed4(col.rgb, 1.0);
    63.             }
    64.             ENDCG
    65.         }
    66.     }
    67.  
    68.     Fallback Off
    69. }
    Tunnel Rotating CW:

    Code (csharp):
    1. Shader "Aubergine/PreProcessFx/Tunnel-RotateCW" {
    2.     Properties {
    3.         _Speed("Speed", Float) = 1.86
    4.         _TunnelFog("Fog", Range(0.5, 6.0)) = 1.6
    5.         _Zoom("Zoom", Range(1.0, 16.0)) = 2.0
    6.     }
    7.  
    8.     CGINCLUDE
    9.     fixed3 checkers(float2 p, float s) {
    10.         float c = clamp(ceil(sin(p.x / s) * sin(p.y / s)) * s * 10.0, 0.1, 1.0);
    11.         return fixed3(c, c, c);
    12.     }
    13.     ENDCG
    14.  
    15.     SubShader {
    16.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    17.         LOD 100
    18.  
    19.         Pass {
    20.             Name "BASE"
    21.             Tags { "LightMode" = "Always" }
    22.  
    23.             Fog { Mode off }
    24.             ZWrite Off
    25.             Cull Off
    26.  
    27.             CGPROGRAM
    28.             #pragma exclude_renderers xbox360 ps3 flash
    29.             #pragma vertex vert
    30.             #pragma fragment frag
    31.             #pragma fragmentoption ARB_precision_hint_fastest
    32.  
    33.             fixed _Speed, _TunnelFog;
    34.             half _Zoom;
    35.  
    36.             struct a2v {
    37.                 float4 vertex : POSITION;
    38.                 float4 texcoord : TEXCOORD0;
    39.             };
    40.  
    41.             struct v2f {
    42.                 float4 pos : SV_POSITION;
    43.                 float2 uv : TEXCOORD0;
    44.             };
    45.  
    46.             v2f vert(a2v v) {
    47.                 v2f o;
    48.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    49.                 o.uv = v.texcoord.xy;
    50.                 return o;
    51.             }
    52.  
    53.             fixed4 frag(v2f i) : COLOR {
    54.                 half2 pos = i.uv - 0.5;
    55.                 half2 p = pos * _Zoom;
    56.                 float cc = cos(_Time.y);
    57.                 float ss = sin(_Time.y);
    58.                 p = half2((-cc * p.x + ss * p.y), (ss * p.x + cc * p.y));
    59.                 float dist = length(p);
    60.                 float2 nuv = float2(p.x / dist, 1.0 / abs(dist) + _Time.y * _Speed);
    61.                 fixed3 col = checkers(nuv, 0.10) * pow(abs(dist), _TunnelFog);
    62.                 return fixed4(col.rgb, 1.0);
    63.             }
    64.             ENDCG
    65.         }
    66.     }
    67.  
    68.     Fallback Off
    69. }
    Tunnel Straight Motion:

    Code (csharp):
    1. Shader "Aubergine/PreProcessFx/Tunnel-Straight" {
    2.     Properties {
    3.         _Speed("Speed", Float) = 1.86
    4.         _TunnelFog("Fog", Range(0.5, 6.0)) = 1.6
    5.         _Zoom("Zoom", Range(1.0, 16.0)) = 2.0
    6.         _Scale("Checker Scale", Range(0.001, 0.2)) = 0.1
    7.     }
    8.  
    9.     CGINCLUDE
    10.     fixed3 checkers(float2 p, float s) {
    11.         float c = clamp(ceil(sin(p.x / s) * sin(p.y / s)) * s * 10.0, 0.1, 1.0);
    12.         return fixed3(c, c, c);
    13.     }
    14.     ENDCG
    15.  
    16.     SubShader {
    17.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    18.         LOD 100
    19.  
    20.         Pass {
    21.             Name "BASE"
    22.             Tags { "LightMode" = "Always" }
    23.  
    24.             Fog { Mode off }
    25.             ZWrite Off
    26.             Cull Off
    27.  
    28.             CGPROGRAM
    29.             #pragma exclude_renderers xbox360 ps3 flash
    30.             #pragma vertex vert
    31.             #pragma fragment frag
    32.             #pragma fragmentoption ARB_precision_hint_fastest
    33.  
    34.             fixed _Speed, _TunnelFog, _Scale;
    35.             half _Zoom;
    36.  
    37.             struct a2v {
    38.                 float4 vertex : POSITION;
    39.                 float4 texcoord : TEXCOORD0;
    40.             };
    41.  
    42.             struct v2f {
    43.                 float4 pos : SV_POSITION;
    44.                 float2 uv : TEXCOORD0;
    45.             };
    46.  
    47.             v2f vert(a2v v) {
    48.                 v2f o;
    49.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    50.                 o.uv = v.texcoord.xy;
    51.                 return o;
    52.             }
    53.  
    54.             fixed4 frag(v2f i) : COLOR {
    55.                 half2 pos = i.uv - 0.5;
    56.                 half2 p = pos * _Zoom;
    57.                 float dist = length(p);
    58.                 float2 nuv = float2(p.x / dist, 1.0 / abs(dist) + _Time.y * _Speed);
    59.                 fixed3 col = checkers(nuv, _Scale) * pow(abs(dist), _TunnelFog);
    60.                 return fixed4(col.rgb, 1.0);
    61.             }
    62.             ENDCG
    63.         }
    64.     }
    65.  
    66.     Fallback Off
    67. }
     

    Attached Files:

    • $1.jpg
      $1.jpg
      File size:
      61.2 KB
      Views:
      1,140
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Noise (Animated):

    Code (csharp):
    1. Shader "Aubergine/PreProcessFx/Noise" {
    2.     Properties {
    3.         _Color("Tint (RGB)", Color) = (1, 1, 1, 1)
    4.     }
    5.  
    6.     CGINCLUDE
    7.     inline float rand(float2 n) {
    8.         return frac(sin(dot(n.xy, float2(_Time.y * 12.9898, 78.233)))* 43758.5453);
    9.     }
    10.     ENDCG
    11.  
    12.     SubShader {
    13.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    14.         LOD 100
    15.  
    16.         Pass {
    17.             Name "BASE"
    18.             Tags { "LightMode" = "Always" }
    19.  
    20.             Fog { Mode off }
    21.             ZWrite Off
    22.             Cull Off
    23.  
    24.             CGPROGRAM
    25.             #pragma exclude_renderers xbox360 ps3 flash
    26.             #pragma vertex vert
    27.             #pragma fragment frag
    28.             #pragma fragmentoption ARB_precision_hint_fastest
    29.  
    30.             fixed4 _Color;
    31.  
    32.             struct a2v {
    33.                 float4 vertex : POSITION;
    34.                 float4 texcoord : TEXCOORD0;
    35.             };
    36.  
    37.             struct v2f {
    38.                 float4 pos : SV_POSITION;
    39.                 float2 uv : TEXCOORD0;
    40.             };
    41.  
    42.             v2f vert(a2v v) {
    43.                 v2f o;
    44.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    45.                 o.uv = v.texcoord.xy;
    46.                 return o;
    47.             }
    48.  
    49.             fixed4 frag(v2f i) : COLOR {
    50.                 fixed c = rand(i.uv);
    51.                 return fixed4(_Color.rgb * c, 1.0);
    52.             }
    53.             ENDCG
    54.         }
    55.     }
    56.  
    57.     Fallback Off
    58. }
     

    Attached Files:

    • $1.jpg
      $1.jpg
      File size:
      139.5 KB
      Views:
      1,138
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Screen space sun (2D):

    Code (csharp):
    1. Shader "Aubergine/PreProcessFx/Sun" {
    2.     Properties {
    3.         _Color("Tint (RGB)", Color) = (1, 1, 1, 1)
    4.         _CenterX("Center X", Range(0.0, 1.0)) = 0.5
    5.         _CenterY("Center Y", Range(0.0, 1.0)) = 0.5
    6.         _Scale("Scale", Float) = 10.0
    7.     }
    8.  
    9.     SubShader {
    10.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    11.         LOD 100
    12.  
    13.         Pass {
    14.             Name "BASE"
    15.             Tags { "LightMode" = "Always" }
    16.  
    17.             Fog { Mode off }
    18.             ZWrite Off
    19.             Cull Off
    20.  
    21.             CGPROGRAM
    22.             #pragma exclude_renderers xbox360 ps3 flash
    23.             #pragma vertex vert
    24.             #pragma fragment frag
    25.             #pragma fragmentoption ARB_precision_hint_fastest
    26.  
    27.             fixed4 _Color;
    28.             fixed _CenterX, _CenterY;
    29.             half _Scale;
    30.  
    31.             struct a2v {
    32.                 float4 vertex : POSITION;
    33.                 float4 texcoord : TEXCOORD0;
    34.             };
    35.  
    36.             struct v2f {
    37.                 float4 pos : SV_POSITION;
    38.                 float2 uv : TEXCOORD0;
    39.             };
    40.  
    41.             v2f vert(a2v v) {
    42.                 v2f o;
    43.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    44.                 o.uv = v.texcoord.xy;
    45.                 return o;
    46.             }
    47.  
    48.             fixed4 frag(v2f i) : COLOR {
    49.                 half2 center = float2(_CenterX, _CenterY);
    50.                 half2 pos = i.uv - center;
    51.                 float dist = length(i.uv - pos * _ScreenParams.xy);
    52.                 fixed c = _Scale / dist;
    53.                 return fixed4(c * _Color.rgb, 1.0);
    54.             }
    55.             ENDCG
    56.         }
    57.     }
    58.  
    59.     Fallback Off
    60. }
     

    Attached Files:

    • $1.jpg
      $1.jpg
      File size:
      25.7 KB
      Views:
      1,143
  6. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Nice! You really must love writing shaders :) How about a cubemap-like background, so that it rotates when you look in different directions?
    Also, why don't you draw the quad with GL? Or at least set the camera's clear flags to Depth only to save precious fillrate, since you're drawing over the whole background anyways?
     
  7. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    These are pretty much useless eyecandy stuff, maybe some can be used though.
    I didnt write these by the way, just converting some shadertoy shaders to unity for learning purposes, i love fractals.

    I dont know if GL is supported by unity free, is it? Anyways, there is enough control with shaders, you can move the quad back and forth between skybox and other stuff if necessary this way.

    You are welcome to add to the list, forexample i am having problems with noise calculations as it fills up the instruction limits of 3.0, you are not allowed to use textures though(except the tunnel, it was just an example), try to stick with procedural stuff.
    EDIT: Lets make a big library here.
     
  8. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Having fun with shaders :)
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,440
    Thanks, good stuff!


    here's also couple "effect" shaders sources, mostly from the old shadertoy site:

    wipe transition shader ( http://unitycoder.com/blog/2012/01/20/wipe-transition-shader/ )
    Code (csharp):
    1. // ORIGINAL GLSL SHADER "Postpro" BY iq (2009)
    2. Shader "UnityForums/WipeShader"
    3. {
    4. Properties
    5. {
    6. _tex0 ("Texture1", 2D) = "white" {}
    7. _tex1 ("Texture2", 2D) = "white" {}
    8. }
    9.  
    10. SubShader
    11. {
    12. Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    13. LOD 100
    14. Pass
    15. {
    16. CGPROGRAM
    17. #pragma target 3.0
    18. #pragma vertex vert
    19. #pragma fragment frag
    20. #include "UnityCG.cginc"
    21.  
    22. sampler2D _tex0;
    23. sampler2D _tex1;
    24.  
    25. struct v2f {
    26. float4 pos : POSITION;
    27. float4 color : COLOR0;
    28. float4 fragPos : COLOR1;
    29. float2  uv : TEXCOORD0;
    30. };
    31.  
    32. float4 _tex0_ST;
    33.  
    34. v2f vert (appdata_base v)
    35. {
    36. v2f o;
    37. o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    38. o.fragPos = o.pos;
    39. o.uv = TRANSFORM_TEX (v.texcoord, _tex0);
    40. o.color = float4 (1.0, 1.0, 1.0, 1);
    41. return o;
    42. }
    43.  
    44. half4 frag (v2f i) : COLOR
    45. {
    46. float animtime = _Time*10.0;
    47. float2 q = i.uv.xy / float2(1,1);
    48. float3 oricol = tex2D (_tex0,float2(q.x,q.y)).xyz;
    49. float3 col = tex2D (_tex1,float2(i.uv.x,i.uv.y)).xyz;
    50. float comp = smoothstep( 0.2, 0.7, sin(animtime) );
    51. col = lerp(col,oricol,  clamp(-2.0+2.0*q.x+3.0*comp,0.0,1.0)); // ??
    52. return float4(col,1);
    53. }
    54. ENDCG
    55. }
    56. }
    57. FallBack "VertexLit"
    58. }


    plasma shader ( http://unitycoder.com/blog/2011/12/14/plasma-shader-testing/ )
    Code (csharp):
    1. // main code, *original shader by: ‘Plasma’ by Viktor Korsun (2011)
    2. Shader "UnityForums/Plasma1"
    3. {
    4. Properties
    5. {
    6. _Anim("Time", Float) = 0
    7. _ResX("_ResX", Float) = 128
    8. _ResY("_ResY", Float) = 128
    9. }
    10. SubShader
    11. {
    12. Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    13. LOD 100
    14. Pass
    15. {
    16. CGPROGRAM
    17. #pragma target 3.0
    18. #pragma vertex vert
    19. #pragma fragment frag
    20. #include "UnityCG.cginc"
    21.  
    22. uniform float _ResX;
    23. uniform float _ResY;
    24. uniform float _Anim;
    25.  
    26. struct v2f {
    27. float4 pos : POSITION;
    28. float4 color : COLOR0;
    29. float4 fragPos : COLOR1;
    30. };
    31.  
    32. v2f vert (appdata_base v)
    33. {
    34. v2f o;
    35. o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    36. o.fragPos = o.pos;
    37. o.color = float4 (1.0, 1.0, 1.0, 1);
    38. return o;
    39. }
    40.  
    41. half4 frag (v2f i) : COLOR {
    42. float4 outColor = i.color;
    43. float x = i.fragPos.x;
    44. float y = i.fragPos.z;
    45. float mov0 = x+y+cos(sin(_Time[1]/10)*2.)*100.+sin(x/100.)*1000.;
    46. float mov1 = y / _ResY / 0.2 + _Time[1];
    47. float mov2 = x / _ResX / 0.2;
    48. float c1 = abs(sin(mov1+_Time[1])/2.+mov2/2.-mov1-mov2+_Time[1]);
    49. float c2 = abs(sin(c1+sin(mov0/1000.+_Time[1])+sin(y/40.+_Time[1])+sin((x+y)/100.)*3.));
    50. float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
    51. outColor.rgba = float4(c1,c2,c3,0.5);
    52. return outColor;
    53. }
    54. ENDCG
    55. }
    56. }
    57. FallBack "VertexLit"
    58. }

    radar shader
    http://unitycoder.com/blog/2012/10/25/radar-shader/

    360 panorama reflection shader
    http://unitycoder.com/blog/2012/10/06/360-panorama-reflection-shader/

    .
     
    Last edited: Jan 6, 2014
  10. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,440
    Added 2 sources above^, cannot edit the post anymore, it goes empty..><

    here's the missing ones:

    radar effect ( http://unitycoder.com/blog/2012/10/25/radar-shader/ )
    Code (csharp):
    1. // original shader: http://glsl.heroku.com/e#4190.1
    2. Shader "UnityForums/Radar1"
    3. {
    4. Properties {
    5. tex ("Texture (RGB)", 2D) = "white" {}
    6. resolution("resolution", Vector) = (1,1,0,0)
    7. }
    8. SubShader {
    9. Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    10. LOD 100
    11. CGPROGRAM
    12. #pragma target 3.0
    13. #pragma surface surf Lambert
    14. #define GRID_SIZE 32
    15. #define PI 3.1416
    16. uniform float2 resolution;
    17. struct Input {
    18. float2 uvtex;
    19. };
    20. float3 color(float d) {
    21. return d * float3(0, 1, 0);
    22. }
    23. int mod(int a, int b) {
    24. return a - ((a / b) * b);
    25. }
    26. void surf (Input IN, inout SurfaceOutput o)
    27. {
    28. float time = _Time.x*10;
    29. float2 p = (-1.0 + 2.0 * ((IN.uvtex.xy) / resolution.xy));
    30. p.x *= (resolution.x / resolution.y);
    31. float2 uv;
    32. float a = (atan2(p.y,p.x) + time);
    33. float r = sqrt(dot(p,p));
    34. uv.x = 0.1/r;
    35. uv.y = a/(PI);
    36. float len = dot(p,p);
    37. float3 col = color(pow(frac(uv.y / -2.0), 15.0));
    38. if (len > 0.7) col = float3(0.8,0.8,0.8);
    39. if (len > 0.73) col = float3(0,0,0);
    40.  
    41. bool grid_x = mod(int(IN.uvtex.x) - int(resolution.x / 2.0), GRID_SIZE) == 0;
    42. bool grid_y = mod(int(IN.uvtex.y) - int(resolution.y / 2.0), GRID_SIZE) == 0;
    43.  
    44. if (len < 0.7)
    45. {
    46. if (grid_x || grid_y)
    47. col += color(0.1);
    48.  
    49. if (grid_x  grid_y)
    50. col += color(1.0);
    51. }
    52. half4 c = float4(col, 1.0);
    53. o.Albedo = c.rgb;
    54. o.Alpha = c.a;
    55. }
    56. ENDCG
    57. }
    58. FallBack "Diffuse"
    59. }
    360 panorama reflection shader *not really suitable when used in plane ( http://unitycoder.com/blog/2012/10/0...ection-shader/ )
    Code (csharp):
    1. // original source: http://www.clicktorelease.com/code/streetViewReflectionMapping
    2. Shader "UnityForums/360reflection" {
    3. Properties {
    4. _texture ("texture (RGB)", 2D) = "white" {}
    5. _scaledTexture ("scaledTexture (RGB)", 2D) = "white" {}
    6. }
    7. SubShader {
    8. Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    9. LOD 100
    10.  
    11. CGPROGRAM
    12. #pragma target 3.0
    13. #pragma surface surf Lambert vertex:vert
    14.  
    15. float3 vReflect;
    16. float3 vRefract;
    17.  
    18. struct Input {
    19. float2 uv_MainTex;
    20. float4 pos : SV_POSITION;
    21. float3 vReflect;
    22. float3 vRefract;
    23. };
    24.  
    25. void vert (inout appdata_full v, out Input o)
    26. {
    27. float4 mPosition = mul(_Object2World,float4(v.vertex.xyz, 1.0 ));
    28. float3 nWorld = normalize( mul(  float3x3(_Object2World[0].xyz, _Object2World[1].xyz, _Object2World[2].xyz) ,v.normal ));
    29. o.vReflect = normalize( reflect( normalize( mPosition.xyz - _WorldSpaceCameraPos ), nWorld ) );
    30. o.vRefract = normalize( refract( normalize( mPosition.xyz - _WorldSpaceCameraPos ), nWorld, 0.9 ) );
    31. o.pos = mul(UNITY_MATRIX_P * UNITY_MATRIX_MV,float4(v.vertex.xyz, 1.0));
    32. }
    33.  
    34. uniform float rAmount;
    35. uniform sampler2D _texture;
    36. uniform sampler2D _scaledTexture;
    37.  
    38. void surf (Input IN, inout SurfaceOutput o)
    39. {
    40. float PI = 3.14159265358979323846264;
    41. float yaw = .5 - atan2(IN.vReflect.z, - IN.vReflect.x ) / ( 2.0 * PI );
    42. float pitch = .5 - asin( -IN.vReflect.y ) / PI;
    43. float3 color = tex2D(_scaledTexture, float2( yaw, pitch ) ).rgb * ( 1.0 - rAmount );
    44. yaw = .5 - atan2(IN.vRefract.z, - IN.vRefract.x ) / ( 2.0 * PI );
    45. pitch = .5 - asin(IN.vRefract.y ) / PI;
    46. color += tex2D(_texture, float2( yaw, pitch ) ).rgb * rAmount;
    47. half4 c = float4( color, 1.0 );
    48. o.Albedo = c.rgb;
    49. o.Alpha = c.a;
    50. }
    51.  
    52. ENDCG
    53. }
    54. FallBack "Diffuse"
    55. }
    56. }
     
    Last edited: Jan 6, 2014
  11. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Thank you mgear, hopefully more people will contribute :)
     
  12. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Here is one very sick and beautiful effect.

    HellHole:
    Code (csharp):
    1.  
    2. Shader "Aubergine/PreProcessFx/HellHole" {
    3.     Properties {
    4.     }
    5.  
    6.     CGINCLUDE
    7.     inline half4 makePoint(half2 p) {
    8.         half2 m = half2(2.0 - 1.0, 2.0 + 1.0);
    9.         half u = abs(sin((atan2(p.y, p.x) - length(p) + _Time.y) * 10.0) * 0.1) + 0.1;
    10.         half r = 0.03 / abs(u - length(p) * 0.3);
    11.         half g = 0.04 / abs(u - length(p) * 0.5);
    12.         half b = 0.05 / abs(u - length(p) * 0.7);
    13.         return min(half4(1), half4(r, g, b, 1.0));
    14.     }
    15.  
    16.     half map(half3 p) {
    17.         return 1.2-dot(abs(p), half3(0, 1, 0)) + (-0.5 * length(makePoint(p.xz).xyz) * sin(_Time.y * 2.0) + (sin(p.z * 5.0 + _Time.y * 5.0) + sin(p.x * 5.0 + _Time.y * 5.0)) * 0.1);
    18.     }
    19.     ENDCG
    20.  
    21.     SubShader {
    22.         Tags { "RenderType" = "Background" "Queue" = "Background" "IgnoreProjector" = "True" }
    23.         LOD 100
    24.  
    25.         Pass {
    26.             Name "BASE"
    27.             Tags { "LightMode" = "Always" }
    28.  
    29.             Fog { Mode off }
    30.             ZWrite Off
    31.             Cull Off
    32.  
    33.             CGPROGRAM
    34.             #pragma exclude_renderers xbox360 ps3 flash
    35.             #pragma vertex vert
    36.             #pragma fragment frag
    37.             #pragma fragmentoption ARB_precision_hint_fastest
    38.             #pragma target 3.0
    39.  
    40.             struct a2v {
    41.                 float4 vertex : POSITION;
    42.                 float4 texcoord : TEXCOORD0;
    43.             };
    44.  
    45.             struct v2f {
    46.                 float4 pos : SV_POSITION;
    47.                 float2 uv : TEXCOORD0;
    48.             };
    49.  
    50.             v2f vert(a2v v) {
    51.                 v2f o;
    52.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    53.                 o.uv = v.texcoord.xy;
    54.                 return o;
    55.             }
    56.  
    57.             fixed4 frag(v2f i) : COLOR {
    58.                 half2 p = -1.0 + 2.0 * i.uv;
    59.                 if(abs(p.y) > 0.75) {
    60.                     return fixed4(0);
    61.                 }
    62.  
    63.                 p.y = -p.y;
    64.                 half3 d = normalize(half3(p, 1.0));
    65.                 float a = -0.1;
    66.                 d.y = cos(a) * d.y - sin(a) * d.z;
    67.                 d.z = sin(a) * d.y + cos(a) * d.z;
    68.  
    69.                 half3 e = half3(0,0.0,-2.0);
    70.                 float t = 0.0;
    71.                 for(int i = 0 ; i < 5; i++) {
    72.                     float k = map(e + d * t);
    73.                     if(k < 0.05)
    74.                         break;
    75.                     t += k * 0.7;
    76.                 }
    77.  
    78.                 fixed4 res = half4(t * .5) * makePoint((t * d + e).xz) + t * 0.1 * half4(1,2,3,4) * 0.5 * map( (t * d + e) + 0.1 ) ;   
    79.                 return res;
    80.             }
    81.             ENDCG
    82.         }
    83.     }
    84.  
    85.     Fallback Off
    86. }
    87.  
     

    Attached Files:

  13. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    This is a Starfield Procedural shader, you can use it as a skybox. This is modified version from noise shader.

    Code (CSharp):
    1. Shader "Skybox/Starfield Procedural" {
    2.  
    3. SubShader {
    4.     Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
    5.     Cull Off ZWrite Off
    6. Pass {
    7.  
    8. CGPROGRAM
    9. #pragma vertex vert
    10. #pragma fragment frag
    11.  
    12. #include "UnityCG.cginc"
    13.  
    14. struct v2f {
    15.     float4  pos :    SV_POSITION;
    16.     half3  uv  :    TEXCOORD0;
    17. };
    18.  
    19. half random3(half3 n){
    20.     return frac(sin(dot(n.xyz, half3(12.9898,78.233,1)))*43758.5453);
    21. }
    22.  
    23. v2f vert (appdata_base v)
    24. {
    25.     v2f o;
    26.     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    27.     float scale = 256 ;
    28.     o.uv = v.texcoord.xyz * scale;
    29.  
    30.     return o;
    31. }
    32.  
    33. half4 frag (v2f i) : COLOR
    34. {
    35.     half rnd = random3(round(i.uv));
    36.  
    37.     half2 col = saturate( half2( rnd - 0.997, rnd - 0.99)) ;
    38.     half stars = col.x * 100 + col.y * 5 ;
    39.  
    40.     return  half4(stars.rrr,1);
    41. }
    42. ENDCG
    43.  
    44.     }
    45. }
    46. }
     

    Attached Files:

    mgear likes this.