Синтаксис:
Используется glsl
Shader "Custom/SkyDome"
{
Properties
{
_CurrentTex ("Current (RGB)", 2D) = "white" {}
_BlendTex ("BlendT (RGB)", 2D) = "white" {}
_BlendPos ("Blend pos", float) = 0
_Dir("Dir", float) = 1
}
SubShader
{
Tags { "RenderType"="Background" "IgnoreProjector"="True" }
pass
{
CGPROGRAM
#pragma only_renderers d3d9 opengl
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _CurrentTex;
uniform sampler2D _BlendTex;
uniform fixed _BlendPos;
uniform fixed _Dir;
struct vertexInput
{
float4 vertex : POSITION;
half4 texcoord : TEXCOORD0;
};
struct vertexOutput
{
float4 pos : SV_POSITION;
half4 tex : TEXCOORD0;
fixed texMulDir : TEXCOORD1;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.tex = input.texcoord;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
fixed2 texcoordFlipped = input.texcoord.xy;
if (_Dir<0)
{
texcoordFlipped = half2(1.0h, 1.0h) - texcoordFlipped;
}
output.texMulDir = (texcoordFlipped.x*texcoordFlipped.y*texcoordFlipped.y);
return output;
}
float4 frag(vertexOutput input) : COLOR
{
fixed4 cur = tex2D(_CurrentTex, input.tex.xy);
fixed4 blend = tex2D(_BlendTex, input.tex.xy);
return
lerp
(
cur, blend, saturate(_BlendPos * (input.texMulDir*5.0h+1.0h) )
);
}
ENDCG
}
}
}
{
Properties
{
_CurrentTex ("Current (RGB)", 2D) = "white" {}
_BlendTex ("BlendT (RGB)", 2D) = "white" {}
_BlendPos ("Blend pos", float) = 0
_Dir("Dir", float) = 1
}
SubShader
{
Tags { "RenderType"="Background" "IgnoreProjector"="True" }
pass
{
CGPROGRAM
#pragma only_renderers d3d9 opengl
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _CurrentTex;
uniform sampler2D _BlendTex;
uniform fixed _BlendPos;
uniform fixed _Dir;
struct vertexInput
{
float4 vertex : POSITION;
half4 texcoord : TEXCOORD0;
};
struct vertexOutput
{
float4 pos : SV_POSITION;
half4 tex : TEXCOORD0;
fixed texMulDir : TEXCOORD1;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.tex = input.texcoord;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
fixed2 texcoordFlipped = input.texcoord.xy;
if (_Dir<0)
{
texcoordFlipped = half2(1.0h, 1.0h) - texcoordFlipped;
}
output.texMulDir = (texcoordFlipped.x*texcoordFlipped.y*texcoordFlipped.y);
return output;
}
float4 frag(vertexOutput input) : COLOR
{
fixed4 cur = tex2D(_CurrentTex, input.tex.xy);
fixed4 blend = tex2D(_BlendTex, input.tex.xy);
return
lerp
(
cur, blend, saturate(_BlendPos * (input.texMulDir*5.0h+1.0h) )
);
}
ENDCG
}
}
}
Синтаксис:
Используется csharp
using UnityEngine;
public class SkyController : MonoBehaviour
{
public Texture2D[] skyTextures;
private float t;
public float speed = 0.5f;
private int blendTexIndex;
private Material mat;
private int dir = 1;
void Start()
{
blendTexIndex = 1;
mat = renderer.sharedMaterial;
mat.SetTexture("_CurrentTex", skyTextures[0]);
mat.SetTexture("_BlendTex", skyTextures[1]);
mat.SetFloat("_Dir", dir);
}
void Update ()
{
t += Time.deltaTime*speed;
if (t >= 1f)
{
t = 0f;
int newTexIndex = blendTexIndex == skyTextures.Length - 1 ? 0 : blendTexIndex + 1;
mat.SetTexture("_CurrentTex", skyTextures[blendTexIndex]);
mat.SetTexture("_BlendTex", skyTextures[newTexIndex]);
dir = -dir;
mat.SetFloat("_Dir", dir);
blendTexIndex = newTexIndex;
}
mat.SetFloat("_BlendPos", t);
}
}
public class SkyController : MonoBehaviour
{
public Texture2D[] skyTextures;
private float t;
public float speed = 0.5f;
private int blendTexIndex;
private Material mat;
private int dir = 1;
void Start()
{
blendTexIndex = 1;
mat = renderer.sharedMaterial;
mat.SetTexture("_CurrentTex", skyTextures[0]);
mat.SetTexture("_BlendTex", skyTextures[1]);
mat.SetFloat("_Dir", dir);
}
void Update ()
{
t += Time.deltaTime*speed;
if (t >= 1f)
{
t = 0f;
int newTexIndex = blendTexIndex == skyTextures.Length - 1 ? 0 : blendTexIndex + 1;
mat.SetTexture("_CurrentTex", skyTextures[blendTexIndex]);
mat.SetTexture("_BlendTex", skyTextures[newTexIndex]);
dir = -dir;
mat.SetFloat("_Dir", dir);
blendTexIndex = newTexIndex;
}
mat.SetFloat("_BlendPos", t);
}
}