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

@ -58,7 +58,7 @@ Material:
m_Floats:
- _BumpScale: 1
- _Cutoff: 1
- _Depth: 15
- _Depth: 3
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _Frequency: 6.2832
@ -70,7 +70,7 @@ Material:
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Phase: 0
- _Power: 128
- _Power: 32
- _SinePower: 1.25
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1

View file

@ -508,7 +508,7 @@ Light:
m_Type: 2
m_Shape: 0
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 0.333
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208

View file

@ -1732,7 +1732,6 @@ GameObject:
- component: {fileID: 4028928668500718027}
- component: {fileID: 6423368230359933839}
- component: {fileID: 8693096897863455396}
- component: {fileID: 2748941174002375643}
m_Layer: 0
m_Name: Cube.043
m_TagString: Untagged
@ -1811,18 +1810,6 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &2748941174002375643
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8882633467169423962}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1cc21c48ee370cb42a042622dd21640d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &3244127278357174761
PrefabInstance:
m_ObjectHideFlags: 0

View file

@ -2439,7 +2439,7 @@ PrefabInstance:
- target: {fileID: 3664209305474245377, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 60.98
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3664209305474245377, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
@ -2464,7 +2464,7 @@ PrefabInstance:
- target: {fileID: 3664209306888449100, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 55.675
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3664209306888449100, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}

View file

@ -10,7 +10,8 @@ using UnityEngine.Rendering;
/// Generate halton sequence.
/// code from unity post-processing stack.
/// </summary>
public class HaltonSequence {
public class HaltonSequence
{
public int radix = 3;
private int storedIndex = 0;
public float Get() {
@ -28,7 +29,8 @@ public class HaltonSequence {
}
}
public enum Quality {
public enum Quality
{
Low,
Normal, //Low sample count
High, //High sample count and high shadow sample count.
@ -41,7 +43,8 @@ public enum Quality {
[ImageEffectAllowedInSceneView]
[ExecuteInEditMode,RequireComponent(typeof(Camera))]
[ImageEffectOpaque]
public class VolumeCloudRenderer : EffectBase {
public class VolumeCloudRenderer : EffectBase
{
[Header("Render Settings")]
[Range(0, 2)]
public int downSample = 1;
@ -56,7 +59,6 @@ public enum Quality {
private HaltonSequence sequence = new HaltonSequence() { radix = 3 };
// The index of 4x4 pixels.
private int frameIndex = 0;
private float bayerOffsetIndex = 0;
private bool firstFrame = true;
[SerializeField]

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);
}

BIN
GameData/PlayerSettings.msgpack (Stored with Git LFS)

Binary file not shown.

BIN
ProjectSettings/GraphicsSettings.asset (Stored with Git LFS)

Binary file not shown.