Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created March 31, 2015 13:11
Show Gist options
  • Save keijiro/01dc44ad440623a5d30c to your computer and use it in GitHub Desktop.
Save keijiro/01dc44ad440623a5d30c to your computer and use it in GitHub Desktop.
Cubemapped Skybox Shader with LOD Level
Shader "Skybox/Cubemap LOD" {
Properties {
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
[Gamma] _Exposure ("Exposure", Range(0, 8)) = 1.0
_Rotation ("Rotation", Range(0, 360)) = 0
_LodLevel ("LOD Level", Range(0, 10)) = 0
[NoScaleOffset] _Tex ("Cubemap (HDR)", Cube) = "grey" {}
}
SubShader {
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
Cull Off ZWrite Off ZTest Always
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
samplerCUBE _Tex;
half4 _Tex_HDR;
half4 _Tint;
half _Exposure;
float _Rotation;
float _LodLevel;
float4 RotateAroundYInDegrees (float4 vertex, float degrees)
{
float alpha = degrees * UNITY_PI / 180.0;
float sina, cosa;
sincos(alpha, sina, cosa);
float2x2 m = float2x2(cosa, -sina, sina, cosa);
return float4(mul(m, vertex.xz), vertex.yw).xzyw;
}
struct appdata_t {
float4 vertex : POSITION;
};
struct v2f {
float4 vertex : SV_POSITION;
float3 texcoord : TEXCOORD0;
};
v2f vert (appdata_t v)
{
v2f o;
float4 vf = float4(v.vertex.xyz, 0);
vf = mul(UNITY_MATRIX_MVP, RotateAroundYInDegrees(vf, _Rotation));
o.vertex = vf.xyww;
o.texcoord = v.vertex;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
half4 tex = texCUBElod (_Tex, float4(i.texcoord, _LodLevel));
half3 c = DecodeHDR (tex, _Tex_HDR);
c = c * _Tint.rgb * unity_ColorSpaceDouble;
c *= _Exposure;
return half4(c, 1);
}
ENDCG
}
}
Fallback Off
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment