Синтаксис:
Используется glsl
/// Портировано с http://www.iquilezles.org/apps/shadertoy/
Shader "ReliefTunnel" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_TimeT ("Time", Float) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;
float _TimeT;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half2 resolution = half2(1.0,1.0);
float2 p = -1.0 + 2.0 * IN.uv_MainTex.xy / resolution.xy;
float2 uv;
float r = sqrt( dot(p,p) );
float a = atan2(p.y,p.x) + 0.5*sin(0.5*r-0.5*_TimeT);
float s = 0.5 + 0.5*cos(7.0*a);
s = smoothstep(0.0,1.0,s);
s = smoothstep(0.0,1.0,s);
s = smoothstep(0.0,1.0,s);
s = smoothstep(0.0,1.0,s);
uv.x = _TimeT + 1.0/( r + .2*s);
uv.y = 3.0*a/3.1416;
float w = (0.5 + 0.5*s)*r*r;
float3 col = tex2D(_MainTex,uv).xyz;
float ao = 0.5 + 0.5*cos(7.0*a);
ao = smoothstep(0.0,0.4,ao)-smoothstep(0.4,0.7,ao);
ao = 1.0-0.5*ao*r;
half4 color = half4(col*w*ao,1.0);
o.Albedo = color.rgb;
o.Alpha = color.a;
}
ENDCG
}
FallBack "Diffuse"
}
Shader "ReliefTunnel" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_TimeT ("Time", Float) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;
float _TimeT;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half2 resolution = half2(1.0,1.0);
float2 p = -1.0 + 2.0 * IN.uv_MainTex.xy / resolution.xy;
float2 uv;
float r = sqrt( dot(p,p) );
float a = atan2(p.y,p.x) + 0.5*sin(0.5*r-0.5*_TimeT);
float s = 0.5 + 0.5*cos(7.0*a);
s = smoothstep(0.0,1.0,s);
s = smoothstep(0.0,1.0,s);
s = smoothstep(0.0,1.0,s);
s = smoothstep(0.0,1.0,s);
uv.x = _TimeT + 1.0/( r + .2*s);
uv.y = 3.0*a/3.1416;
float w = (0.5 + 0.5*s)*r*r;
float3 col = tex2D(_MainTex,uv).xyz;
float ao = 0.5 + 0.5*cos(7.0*a);
ao = smoothstep(0.0,0.4,ao)-smoothstep(0.4,0.7,ao);
ao = 1.0-0.5*ao*r;
half4 color = half4(col*w*ao,1.0);
o.Albedo = color.rgb;
o.Alpha = color.a;
}
ENDCG
}
FallBack "Diffuse"
}
Скрипт времени.
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class TimeToShader : MonoBehaviour {
public float timeScale = 1f;
void Update ()
{
Time.timeScale = timeScale;
renderer.material.SetFloat("_TimeT", Time.time);
}
}
using System.Collections;
public class TimeToShader : MonoBehaviour {
public float timeScale = 1f;
void Update ()
{
Time.timeScale = timeScale;
renderer.material.SetFloat("_TimeT", Time.time);
}
}