Nebula-based Lighting

Main shader used for dynamic objects like the ships now gets its ambient color from the fog lighting texture
This commit is contained in:
Reinier Vens 2022-07-14 05:21:16 +01:00
commit bba4f720ce
9 changed files with 50 additions and 44 deletions

View file

@ -29,8 +29,10 @@ Shader "Aetheria/GlowFade"
CGPROGRAM
#include "Dither Functions.cginc"
#include "Assets/Shaders/Volumetric.cginc"
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
#pragma surface surf Standard fullforwardshadows noambient vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
@ -41,14 +43,7 @@ Shader "Aetheria/GlowFade"
sampler2D _FadeTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
float2 uv_FadeTex;
float4 screenPos;
};
half _Fade;
//half _Fade;
half _FadeSharpness;
half _FadeEdge;
half _Glossiness;
@ -58,29 +53,55 @@ Shader "Aetheria/GlowFade"
fixed4 _Color;
half3 _EdgeColor;
struct Input
{
float2 uv_MainTex;
float2 uv_FadeTex;
float4 screenPos;
float3 ambientColor;
};
float4 VolumeSampleColorSimple(float3 pos, float3 normal)
{
float d = density(pos);
float2 uv = getUV(pos);
const float lodRange = 3;
float3 tint = tex2Dlod(_NebulaTint, float4(uv.x, uv.y, 0, 3 + lodRange + dot(normal, float3(0,1,0))*lodRange));
return float4(tint, d);
}
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex);
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
o.ambientColor = VolumeSampleColorSimple(worldPos, worldNormal).rgb;
}
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_DEFINE_INSTANCED_PROP(half, _Fade)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
half f = tex2D (_FadeTex, IN.uv_FadeTex).r + (1-_FadeEdge-_Fade);
half3 e = _EdgeColor * smoothstep(1 - _FadeEdge, 1, f);
o.Emission = e;
half f = tex2D (_FadeTex, IN.uv_FadeTex).r + (1-_FadeEdge - UNITY_ACCESS_INSTANCED_PROP(_Fade_arr, _Fade));
// Apply screen space dithering
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
ditherClip(screenUV, _FadeSharpness - f * _FadeSharpness);
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
fixed oc = tex2D (_OcclusionMap, IN.uv_MainTex).r;
o.Occlusion = oc * _OcclusionStrength;
o.Emission = _EdgeColor * smoothstep(1 - _FadeEdge, 1, f) + IN.ambientColor * c.rgb * 10;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)) * _BumpScale;
fixed4 m = tex2D (_MetallicGlossMap, IN.uv_MainTex);
o.Metallic = _Metallic * m.r;
o.Smoothness = _Glossiness * m.a;
fixed4 oc = tex2D (_OcclusionMap, IN.uv_MainTex);
o.Occlusion = oc.r * _OcclusionStrength;
}
ENDCG
}

View file

@ -155,10 +155,6 @@ float4 VolumeSampleColor(float3 pos)
float d = density(pos);
float2 uv = getUV(pos);
float3 tint = tex2Dlod(_NebulaTint, float4(uv.x, uv.y, 0, pow(max(.01,d), _TintLodExponent)));
//float2 tintGrad = tintGradient(pos, uv, 1 / pow(density, .25), tint);
//float3 tintNormal = normalize(float3(tintGrad.x, 0, tintGrad.y));
//tint *= abs(dot(normal, float3(0,-1,0)));
// pow(abs(1-density), _TintExponent)
const float albedo = smoothstep(0,-250,pos.y) * pow(max(.1,d), _TintExponent) * _NebulaLuminance;
return float4(albedo*tint, d);
}