110 lines
4.5 KiB
Plaintext
110 lines
4.5 KiB
Plaintext
Shader "Custom/AtmosphereLayerTexture"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex("Cloud Texture", 2D) = "white" {}
|
|
_RimColor("Rim Color", Color) = (1.0, 0.8, 0.2, 1.0)
|
|
_CoreColor("Core Color", Color) = (0.9, 0.5, 0.0, 0.3)
|
|
_RimPower("Rim Power", Range(0.5, 8.0)) = 1.5
|
|
_RimIntensity("Rim Intensity", Range(0.0, 5.0)) = 2.5
|
|
_CoreIntensity("Core Intensity", Range(0.0, 2.0)) = 0.4
|
|
_ScrollSpeedX("Scroll Speed X", Range(-2.0, 2.0)) = 0.05
|
|
_ScrollSpeedY("Scroll Speed Y", Range(-2.0, 2.0)) = 0.01
|
|
_TextureStrength("Texture Strength", Range(0.0, 1.0)) = 0.6
|
|
_PulseSpeed("Pulse Speed", Range(0.0, 3.0)) = 0.8
|
|
_PulseStrength("Pulse Strength", Range(0.0, 1.0)) = 0.15
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
ZWrite Off
|
|
Cull Back
|
|
|
|
Pass
|
|
{
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionHCS : SV_POSITION;
|
|
float3 normalWS : TEXCOORD0;
|
|
float3 viewDirWS : TEXCOORD1;
|
|
float2 uv : TEXCOORD2;
|
|
};
|
|
|
|
TEXTURE2D(_MainTex);
|
|
SAMPLER(sampler_MainTex);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _MainTex_ST;
|
|
half4 _RimColor;
|
|
half4 _CoreColor;
|
|
float _RimPower;
|
|
float _RimIntensity;
|
|
float _CoreIntensity;
|
|
float _ScrollSpeedX;
|
|
float _ScrollSpeedY;
|
|
float _TextureStrength;
|
|
float _PulseSpeed;
|
|
float _PulseStrength;
|
|
CBUFFER_END
|
|
|
|
Varyings vert(Attributes IN)
|
|
{
|
|
Varyings OUT;
|
|
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
|
|
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
|
|
float3 posWS = TransformObjectToWorld(IN.positionOS.xyz);
|
|
OUT.viewDirWS = normalize(_WorldSpaceCameraPos - posWS);
|
|
OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
|
|
return OUT;
|
|
}
|
|
|
|
half4 frag(Varyings IN) : SV_Target
|
|
{
|
|
float2 scrolledUV = IN.uv + float2(_ScrollSpeedX, _ScrollSpeedY) * _Time.y;
|
|
float2 uv2 = IN.uv + float2(_ScrollSpeedX * 0.4, _ScrollSpeedY * 1.7) * _Time.y;
|
|
|
|
half4 tex1 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, scrolledUV);
|
|
half4 tex2 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv2);
|
|
half lum1 = dot(tex1.rgb, half3(0.299, 0.587, 0.114));
|
|
half lum2 = dot(tex2.rgb, half3(0.299, 0.587, 0.114));
|
|
half raw = (lum1 + lum2) * 0.5;
|
|
half texVal = saturate((raw - 0.4) * 3.0);
|
|
half texMod = 0.5 + texVal * 1.0;
|
|
|
|
float3 normal = normalize(IN.normalWS);
|
|
float3 viewDir = normalize(IN.viewDirWS);
|
|
float fresnel = 1.0 - saturate(dot(normal, viewDir));
|
|
|
|
float pulse = 1.0 + sin(_Time.y * _PulseSpeed) * _PulseStrength;
|
|
|
|
float rim = pow(fresnel, _RimPower) * _RimIntensity * pulse;
|
|
rim = lerp(rim, rim * texMod, _TextureStrength);
|
|
|
|
float core = (1.0 - fresnel) * _CoreIntensity;
|
|
core = lerp(core, core * texMod, _TextureStrength * 0.5);
|
|
|
|
half3 cloudColor = lerp(_RimColor.rgb, _CoreColor.rgb + half3(0.1, 0.05, 0.0), texVal);
|
|
half3 col = lerp(_CoreColor.rgb * core, cloudColor * rim, fresnel);
|
|
|
|
float alpha = saturate(rim * 0.8 + core * _CoreColor.a);
|
|
|
|
return half4(col, alpha);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
} |