summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-10-09 03:44:11 -0700
committeryum <yum.food.vr@gmail.com>2024-10-09 03:44:11 -0700
commit5b0b45f9e4892c8e66f36211ebcb1039dd012b1b (patch)
tree834e5881829273ec43bf36bee808202a9d5a268d
parenta396182815db14f5a6eed26799dd425506a70686 (diff)
Add emitter texture to fog
-rw-r--r--Editor/tooner.cs22
-rw-r--r--feature_macros.cginc1
-rw-r--r--fog.cginc39
-rw-r--r--globals.cginc8
-rw-r--r--pbr.cginc29
-rw-r--r--tooner.shader6
6 files changed, 85 insertions, 20 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 156e8c2..9f689aa 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -2038,6 +2038,28 @@ public class ToonerGUI : ShaderGUI {
bc = FindProperty("_Gimmick_Fog_00_Ray_Origin_Randomization");
RangeProperty(bc, "Ray origin randomization");
+ bc = FindProperty("_Gimmick_Fog_00_Emitter_Texture");
+ TexturePropertySingleLine(
+ MakeLabel(bc, "Emitter texture"),
+ bc);
+ SetKeyword("_GIMMICK_FOG_00_EMITTER_TEXTURE", bc.textureValue);
+ if (bc.textureValue) {
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_Fog_00_Emitter_Location");
+ VectorProperty(bc, "Location (world)");
+ bc = FindProperty("_Gimmick_Fog_00_Emitter_Normal");
+ VectorProperty(bc, "Normal (world)");
+ bc = FindProperty("_Gimmick_Fog_00_Emitter_Scale_X");
+ FloatProperty(bc, "Scale (x)");
+ bc = FindProperty("_Gimmick_Fog_00_Emitter_Scale_Y");
+ FloatProperty(bc, "Scale (y)");
+ bc = FindProperty("_Gimmick_Fog_00_Emitter_Brightness");
+ FloatProperty(bc, "Brightness");
+
+ EditorGUI.indentLevel -= 1;
+ }
+
EditorGUI.indentLevel -= 1;
}
diff --git a/feature_macros.cginc b/feature_macros.cginc
index 65220e8..2a68ff5 100644
--- a/feature_macros.cginc
+++ b/feature_macros.cginc
@@ -167,6 +167,7 @@
#pragma shader_feature_local _ SSR_ENABLED
#pragma shader_feature_local _ SSR_MASK
#pragma shader_feature_local _ _GIMMICK_FOG_00
+#pragma shader_feature_local _ _GIMMICK_FOG_00_EMITTER_TEXTURE
#endif // __FEATURE_MACROS_INC
diff --git a/fog.cginc b/fog.cginc
index a8f456c..6635ab7 100644
--- a/fog.cginc
+++ b/fog.cginc
@@ -43,9 +43,9 @@ float map(float3 p) {
return saturate(density);
}
-float3 get_normal(float3 p) {
+float3 get_normal(float3 p, float map_p) {
float3 e = float3(0.001, 0, 0);
- float center = map(p);
+ float center = map_p;
// Prevent NaN
float e2 = 1E-9;
@@ -111,9 +111,38 @@ Fog00PBR getFog00(v2f i) {
for (uint ii = 0; ii < step_count; ii++) {
float3 p = ro + (rd * _Gimmick_Fog_00_Step_Size) * ii;
- float4 c = float4(1, 1, 1, map(p));
+ float col_gray = 0.3;
+ const float map_p = map(p);
+ float4 c = float4(col_gray, col_gray, col_gray, map_p);
c.a = saturate(c.a * _Gimmick_Fog_00_Density * _Gimmick_Fog_00_Step_Size);
+#if defined(_GIMMICK_FOG_00_EMITTER_TEXTURE)
+ // Project onto plane
+ float3 p_to_emitter = p - _Gimmick_Fog_00_Emitter_Location;
+ float3 emitter_normal = normalize(_Gimmick_Fog_00_Emitter_Normal);
+ float2 emitter_scale = float2(_Gimmick_Fog_00_Emitter_Scale_X, _Gimmick_Fog_00_Emitter_Scale_Y);
+
+ float t = dot(p_to_emitter, emitter_normal);
+ float3 p_projected = p - t * emitter_normal;
+
+ p_projected -= _Gimmick_Fog_00_Emitter_Location;
+ bool in_range = (abs(p_projected.x) < emitter_scale.x) * (abs(p_projected.y) < emitter_scale.y) * (t > 0);
+
+ float2 emitter_uv = clamp(p_projected.xy, -emitter_scale, emitter_scale) / emitter_scale;
+ emitter_uv /= 2.0;
+ emitter_uv += 0.5;
+ float3 emitter_color = _Gimmick_Fog_00_Emitter_Texture.SampleLevel(linear_repeat_s, emitter_uv, 0);
+ emitter_color *= _Gimmick_Fog_00_Emitter_Brightness;
+ float emitter_dist = in_range ? abs(t) : 1000;
+ // Inverse square is physically accurate, but this looks better.
+ float emitter_falloff = min(1, rcp(pow(emitter_dist, 1.0)));
+#if 1
+ c.rgb = lerp(c.rgb, emitter_color, in_range * emitter_falloff);
+#else
+ c.rgb = emitter_color;
+#endif
+#endif
+
acc += c * (1.0 - acc.a);
const float ao_str = 0.3;
@@ -122,7 +151,7 @@ Fog00PBR getFog00(v2f i) {
// Performance hack: stop blending normals after enough accumulation.
if (acc.a < _Gimmick_Fog_00_Normal_Cutoff) {
- float3 n = get_normal(p);
+ float3 n = get_normal(p, map_p);
float n_interp = saturate(c.a * (1.0 - acc.a) * rcp(_Gimmick_Fog_00_Normal_Cutoff));
normal = MY_BLEND_NORMALS(normal, n, n_interp);
}
@@ -137,7 +166,7 @@ Fog00PBR getFog00(v2f i) {
}
Fog00PBR pbr;
- pbr.albedo.rgb = 1;
+ pbr.albedo.rgb = acc.rgb;
pbr.albedo.a = saturate(acc.a);
pbr.ao = ao;
diff --git a/globals.cginc b/globals.cginc
index 523e254..5271e64 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -716,6 +716,14 @@ float _Gimmick_Fog_00_Density;
float _Gimmick_Fog_00_Normal_Cutoff;
float _Gimmick_Fog_00_Albedo_Cutoff;
float _Gimmick_Fog_00_Ray_Origin_Randomization;
+#if defined(_GIMMICK_FOG_00_EMITTER_TEXTURE)
+texture2D _Gimmick_Fog_00_Emitter_Texture;
+float3 _Gimmick_Fog_00_Emitter_Location;
+float3 _Gimmick_Fog_00_Emitter_Normal;
+float _Gimmick_Fog_00_Emitter_Scale_X;
+float _Gimmick_Fog_00_Emitter_Scale_Y;
+float _Gimmick_Fog_00_Emitter_Brightness;
+#endif
#endif
#endif
diff --git a/pbr.cginc b/pbr.cginc
index 886ee66..38b2f35 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -254,21 +254,6 @@ float4 getLitColor(
direct_light.color *= (1 - e);
}
-#if defined(_LTCGI)
- ltcgi_acc acc = (ltcgi_acc) 0;
- if ((bool) round(_LTCGI_Enabled)) {
- LTCGI_Contribution(
- acc,
- i.worldPos,
- normal,
- view_dir,
- GetRoughness(smoothness),
- 0);
- indirect_light.diffuse += acc.diffuse;
- indirect_light.specular += acc.specular;
- }
-#endif
-
direct_light.color = RGBtoHSV(direct_light.color);
indirect_light.specular = RGBtoHSV(indirect_light.specular);
indirect_light.diffuse = RGBtoHSV(indirect_light.diffuse);
@@ -460,6 +445,20 @@ float4 getLitColor(
#endif
#endif
+#if defined(_LTCGI)
+ ltcgi_acc acc = (ltcgi_acc) 0;
+ if ((bool) round(_LTCGI_Enabled)) {
+ LTCGI_Contribution(
+ acc,
+ i.worldPos,
+ normal,
+ view_dir,
+ GetRoughness(smoothness),
+ 0);
+ pbr.rgb += acc.diffuse + acc.specular;
+ }
+#endif
+
UNITY_APPLY_FOG(i.fogCoord, pbr.rgb);
return float4(pbr.rgb, albedo.a);
diff --git a/tooner.shader b/tooner.shader
index 7c56a48..820d466 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -628,6 +628,12 @@ Shader "yum_food/tooner"
_Gimmick_Fog_00_Normal_Cutoff("Normal cutoff (alpha)", Range(0,1)) = 0.5
_Gimmick_Fog_00_Albedo_Cutoff("Albedo cutoff (alpha)", Range(0,1)) = 0.9
_Gimmick_Fog_00_Ray_Origin_Randomization("Enable ray origin randomization", Range(0,1)) = 1
+ _Gimmick_Fog_00_Emitter_Texture("Emitter texture", 2D) = "black" {}
+ _Gimmick_Fog_00_Emitter_Location("fog", Vector) = (0, 0, 0, 0)
+ _Gimmick_Fog_00_Emitter_Normal("fog", Vector) = (-1, 0, 0, 0)
+ _Gimmick_Fog_00_Emitter_Scale_X("fog", Float) = 1
+ _Gimmick_Fog_00_Emitter_Scale_Y("fog", Float) = 1
+ _Gimmick_Fog_00_Emitter_Brightness("fog", Float) = 1
}
SubShader
{