97 lines
2.9 KiB
Plaintext
97 lines
2.9 KiB
Plaintext
Shader "Skybox/Cubemap Blend"
|
|
{
|
|
Properties
|
|
{
|
|
[NoScaleOffset] _Cubemap1 ("Cubemap 1", CUBE) = "" {}
|
|
[NoScaleOffset] _Cubemap2 ("Cubemap 2", CUBE) = "" {}
|
|
[NoScaleOffset] _Cubemap3 ("Cubemap 3", CUBE) = "" {}
|
|
_Blend ("Blend", Range(0, 1)) = 0
|
|
_Tint ("Tint Color", Color) = (1, 1, 1, 1)
|
|
_Exposure ("Exposure", Range(0, 8)) = 1.0
|
|
_Rotation ("Rotation", Range(0, 360)) = 0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
|
|
Cull Off
|
|
ZWrite Off
|
|
|
|
Pass
|
|
{
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
TEXTURECUBE(_Cubemap1);
|
|
SAMPLER(sampler_Cubemap1);
|
|
TEXTURECUBE(_Cubemap2);
|
|
SAMPLER(sampler_Cubemap2);
|
|
TEXTURECUBE(_Cubemap3);
|
|
SAMPLER(sampler_Cubemap3);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half _Blend;
|
|
half4 _Tint;
|
|
half _Exposure;
|
|
float _Rotation;
|
|
CBUFFER_END
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float3 texcoord : TEXCOORD0;
|
|
};
|
|
|
|
float3 RotateAroundYInDegrees(float3 dir, float degrees)
|
|
{
|
|
float rad = degrees * PI / 180.0;
|
|
float s, c;
|
|
sincos(rad, s, c);
|
|
return float3(
|
|
dir.x * c - dir.z * s,
|
|
dir.y,
|
|
dir.x * s + dir.z * c
|
|
);
|
|
}
|
|
|
|
Varyings vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
float3 rotated = RotateAroundYInDegrees(input.positionOS.xyz, _Rotation);
|
|
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
|
output.texcoord = rotated;
|
|
return output;
|
|
}
|
|
|
|
half4 frag(Varyings input) : SV_Target
|
|
{
|
|
half4 col1 = SAMPLE_TEXTURECUBE(_Cubemap1, sampler_Cubemap1, input.texcoord);
|
|
half4 col2 = SAMPLE_TEXTURECUBE(_Cubemap2, sampler_Cubemap2, input.texcoord);
|
|
half4 col3 = SAMPLE_TEXTURECUBE(_Cubemap3, sampler_Cubemap3, input.texcoord);
|
|
|
|
// Blend 0~0.5: Cubemap1 → Cubemap2
|
|
// Blend 0.5~1: Cubemap2 → Cubemap3
|
|
half4 col;
|
|
if (_Blend < 0.5)
|
|
col = lerp(col1, col2, _Blend * 2.0);
|
|
else
|
|
col = lerp(col2, col3, (_Blend - 0.5) * 2.0);
|
|
|
|
col.rgb *= _Tint.rgb * _Exposure;
|
|
return col;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
Fallback Off
|
|
}
|