diff options
| -rw-r--r-- | 2ner.cginc | 53 | ||||
| -rw-r--r-- | 2ner.shader | 36 | ||||
| -rw-r--r-- | custom30.cginc | 142 | ||||
| -rw-r--r-- | features.cginc | 10 | ||||
| -rw-r--r-- | fog.cginc | 59 | ||||
| -rw-r--r-- | globals.cginc | 11 | ||||
| -rw-r--r-- | vertex_domain_warping.cginc | 2 |
7 files changed, 279 insertions, 34 deletions
@@ -65,6 +65,9 @@ v2f vert(appdata v) { #if defined(EXTRA_STENCIL_COLOR_PASS) && !defined(_EXTRA_STENCIL_COLOR_PASS)
return (v2f) (0.0/0.0);
#endif
+#if defined(FORWARD_ADD_PASS) & defined(_UNLIT)
+ return (v2f) (0.0/0.0);
+#endif
v2f o;
@@ -178,12 +181,18 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace , out float depth : SV_DepthLessEqual
#endif
) : SV_Target {
+#if defined(_CUSTOM30) && defined(_DEPTH_PREPASS) && !defined(FORWARD_BASE_PASS)
+ return 0;
+#endif
+
UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy);
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
// Not necessarily normalized after interpolation
i.normal = normalize(i.normal);
+ i.tangent = normalize(i.tangent);
+ i.binormal = normalize(i.binormal);
i.normal *= facing ? 1 : -1;
i.normal = UnityObjectToWorldNormal(i.normal);
@@ -192,7 +201,12 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace #if defined(_RAYMARCHED_FOG) && defined(FORWARD_BASE_PASS)
{
+ // Many fields are overspecified as .rgb or .xyz. This is because thry's
+ // shader locker will inline those fields (incorrectly) as float4. Unity's
+ // shader compiler doesn't like that, demanding exact type correspondence.
+ // Overspecifying gets around the issue.
FogParams fog_params = {
+ _Raymarched_Fog_Color.rgb,
_Raymarched_Fog_Steps,
_Raymarched_Fog_Density,
_Raymarched_Fog_Y_Cutoff,
@@ -208,6 +222,19 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace _Raymarched_Fog_Height_Density_Start,
_Raymarched_Fog_Height_Density_Half_Life,
#endif
+ #if defined(_CUSTOM30_FOG_HEIGHT_DENSITY_MINIMUM)
+ _Custom30_Fog_Height_Density_Minimum,
+ #endif
+ #if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE)
+ _Raymarched_Fog_Emitter_Texture,
+ _Raymarched_Fog_Emitter_Texture_TexelSize,
+ _Raymarched_Fog_Emitter_Texture_World_Pos.xyz,
+ normalize(_Raymarched_Fog_Emitter_Texture_World_Normal).xyz,
+ normalize(_Raymarched_Fog_Emitter_Texture_World_Tangent).xyz,
+ normalize(cross(_Raymarched_Fog_Emitter_Texture_World_Normal, _Raymarched_Fog_Emitter_Texture_World_Tangent)).xyz,
+ _Raymarched_Fog_Emitter_Texture_World_Scale.xy,
+ 1.0f / _Raymarched_Fog_Emitter_Texture_World_Scale.xy,
+ #endif
};
FogResult fog_result = raymarched_fog(i, fog_params);
depth = fog_result.depth;
@@ -249,14 +276,22 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace i.uv01.xy = eye_effect_00.uv;
#endif
+ float4x4 tangentToWorld = float4x4(
+ float4(i.tangent.x, i.binormal.x, i.normal.x, 0),
+ float4(i.tangent.y, i.binormal.y, i.normal.y, 0),
+ float4(i.tangent.z, i.binormal.z, i.normal.z, 0),
+ float4(0, 0, 0, 1)
+ );
#if defined(_CUSTOM30)
#if defined(FORWARD_BASE_PASS) || (!defined(_DEPTH_PREPASS) && defined(SHADOW_CASTER_PASS))
#if defined(_CUSTOM30_BASICCUBE)
- Custom30Output c30_out = BasicCube(i);
+ Custom30Output c30_out = BasicCube(i, tangentToWorld);
#elif defined(_CUSTOM30_BASICWEDGE)
- Custom30Output c30_out = BasicWedge(i);
+ Custom30Output c30_out = BasicWedge(i, tangentToWorld);
#elif defined(_CUSTOM30_BASICPLATFORM)
- Custom30Output c30_out = BasicPlatform(i);
+ Custom30Output c30_out = BasicPlatform(i, tangentToWorld);
+#elif defined(_CUSTOM30_RAINBOW)
+ Custom30Output c30_out = Rainbow(i, tangentToWorld);
#else
Custom30Output c30_out = (Custom30Output) 0;
#endif
@@ -271,14 +306,18 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace #endif
#endif
- float3x3 tangentToWorld = float3x3(i.tangent, i.binormal, i.normal);
float ssao = 1;
#if defined(_SSAO)
float2 debug;
ssao = get_ssao(i, tangentToWorld, debug);
#endif
- tangentToWorld = float3x3(i.tangent, i.binormal, i.normal);
+ tangentToWorld = float4x4(
+ float4(i.tangent, 0),
+ float4(i.binormal, 0),
+ float4(i.normal, 0),
+ float4(0, 0, 0, 1)
+ );
YumPbr pbr = GetYumPbr(i, tangentToWorld);
pbr.ao *= ssao;
@@ -345,7 +384,11 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace pbr.albedo.rgb = visualizeInFalseColor(pbr.albedo.rgb);
+#if defined(_UNLIT)
+ float4 lit = pbr.albedo;
+#else
float4 lit = YumBRDF(i, l, pbr);
+#endif
lit.rgb += LightVolumeSpecular(pbr.albedo, pbr.smoothness, pbr.metallic,
pbr.normal, l.view_dir, l.L00, l.L01r, l.L01g, l.L01b);
diff --git a/2ner.shader b/2ner.shader index 1c6e826..3ef8f74 100644 --- a/2ner.shader +++ b/2ner.shader @@ -138,6 +138,12 @@ Shader "yum_food/2ner" [HideInInspector] m_end_Custom30_BasicPlatform("Basic platform", Float) = 0 //endex + //ifex _Custom30_Rainbow_Enabled==0 + [HideInInspector] m_start_Custom30_Rainbow("Rainbow", Float) = 0 + [ThryToggle(_CUSTOM30_RAINBOW)]_Custom30_Rainbow_Enabled("Enable", Float) = 0 + [HideInInspector] m_end_Custom30_Rainbow("Rainbow", Float) = 0 + //endex + [HideInInspector] m_end_Custom30("Custom 30", Float) = 0 //endex @@ -829,16 +835,40 @@ Shader "yum_food/2ner" _Raymarched_Fog_Y_Cutoff("Y cutoff", Float) = -1000 _Raymarched_Fog_Velocity("Velocity", Vector) = (1, -.2, 0, 0) + //ifex _Raymarched_Fog_Density_Exponent_Enabled==0 [HideInInspector] m_start_Raymarched_Fog_Density_Exponent("Density exponent", Float) = 0 [ThryToggle(_RAYMARCHED_FOG_DENSITY_EXPONENT)] _Raymarched_Fog_Density_Exponent_Enabled("Enable", Float) = 0 _Raymarched_Fog_Density_Exponent("Exponent", Float) = 1 [HideInInspector] m_end_Raymarched_Fog_Density_Exponent("Density exponent", Float) = 0 + //endex + //ifex _Raymarched_Fog_Height_Density_Enabled==0 [HideInInspector] m_start_Raymarched_Fog_Height_Density("Height density", Float) = 0 [ThryToggle(_RAYMARCHED_FOG_HEIGHT_DENSITY)] _Raymarched_Fog_Height_Density_Enabled("Enable", Float) = 0 _Raymarched_Fog_Height_Density_Start("Start elevation", Float) = 0 _Raymarched_Fog_Height_Density_Half_Life("Half life", Float) = 1 + + //ifex _Custom30_Fog_Height_Density_Minimum_Enabled==0 + [HideInInspector] m_start_Custom30_Fog_Height_Density_Minimum("Minimum", Float) = 0 + [ThryToggle(_CUSTOM30_FOG_HEIGHT_DENSITY_MINIMUM)] _Custom30_Fog_Height_Density_Minimum_Enabled("Enable", Float) = 0 + _Custom30_Fog_Height_Density_Minimum("Minimum factor", Float) = 0 + [HideInInspector] m_end_Custom30_Fog_Height_Density_Minimum("Minimum", Float) = 0 + //endex [HideInInspector] m_end_Raymarched_Fog_Height_Density("Height density", Float) = 0 + //endex + + //ifex _Raymarched_Fog_Emitter_Texture_Enabled==0 + [HideInInspector] m_start_Raymarched_Fog_Emitter_Texture("Emitter texture", Float) = 0 + [ThryToggle(_RAYMARCHED_FOG_EMITTER_TEXTURE)] _Raymarched_Fog_Emitter_Texture_Enabled("Enable", Float) = 0 + _Raymarched_Fog_Emitter_Texture("Texture", 2D) = "black" {} + _Raymarched_Fog_Emitter_Texture_World_Pos("World position", Vector) = (0, 0, 0, 0) + _Raymarched_Fog_Emitter_Texture_World_Normal("World normal", Vector) = (0, 0, 0, 0) + _Raymarched_Fog_Emitter_Texture_World_Tangent("World tangent", Vector) = (0, 0, 0, 0) + _Raymarched_Fog_Emitter_Texture_World_Scale("World scale", Vector) = (1, 1, 0, 0) + _Raymarched_Fog_Emitter_Texture_World_Scale_Rcp("World scale reciprocal", Vector) = (1, 1, 0, 0) + [HideInInspector] m_end_Raymarched_Fog_Emitter_Texture("Emitter texture", Float) = 0 + //endex + [HideInInspector] m_end_Raymarched_Fog("Raymarched fog", Float) = 0 //endex @@ -1875,6 +1905,12 @@ Shader "yum_food/2ner" [HideInInspector] m_end_Depth_Prepass("Depth Prepass", Float) = 0 //endex + //ifex _Unlit_Enabled==0 + [HideInInspector] m_start_Unlit("Unlit", Float) = 0 + [ThryToggle(_UNLIT)] _Unlit_Enabled("Enable", Float) = 0 + [HideInInspector] m_end_Unlit("Unlit", Float) = 0 + //endex + [HideInInspector] m_start_blending ("Blending--{button_help:{text:Tutorial,action:{type:URL,data:https://www.poiyomi.com/rendering/blending},hover:Documentation}}", Float) = 0 [DoNotAnimate][Enum(Thry.BlendOp)]_BlendOp ("RGB Blend Op", Int) = 0 [DoNotAnimate][Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("RGB Source Blend", Int) = 1 diff --git a/custom30.cginc b/custom30.cginc index 56392d6..75522f1 100644 --- a/custom30.cginc +++ b/custom30.cginc @@ -23,9 +23,12 @@ struct Custom30Output { float depth; }; -float3 GetFragToOrigin(v2f i) { - // Vector from fragment to origin - return float3(-1, 1, 1) * (i.color * 2.0f - 1.0f) / i.color.a; +float3 GetFragToOrigin(v2f i, float3x3 tangentToWorld) { + // Vector from fragment to origin (tangent space) + float3 vec_tan = (i.color * 2.0f - 1.0f) / i.color.a; + float3 vec_world = mul(tangentToWorld, vec_tan); + float3 vec_obj = mul((float3x3)unity_WorldToObject, vec_world); + return vec_obj; } float cut_with_box(float3 p, float d, float3 box_size) { @@ -168,13 +171,20 @@ float3 BasicCube_normal(float3 p) { return normalize(n); } -Custom30Output BasicCube(v2f i) { - float3 objSpaceCameraPos = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)); +Custom30Output BasicCube(v2f i, float4x4 tangentToWorld) { + float4x4 worldToTangent = transpose(tangentToWorld); + float4x4 objectToTangent = mul(worldToTangent, unity_ObjectToWorld); + float4x4 tangentToObject = transpose(objectToTangent); - float3 frag_to_origin = GetFragToOrigin(i); + // Vector from fragment to origin in tangent space. + float3 frag_to_origin = (i.color * 2.0f - 1.0f) / i.color.a; + + float3 tanSpaceCameraPos = mul(worldToTangent, + float4(_WorldSpaceCameraPos, 1.0)); float3 ro = -frag_to_origin; - float3 rd = normalize(i.objPos - objSpaceCameraPos); + float3 rd = normalize( + mul(worldToTangent, float4(i.worldPos, 1.0)).xyz - tanSpaceCameraPos); ro -= rd * _Custom30_ro_Offset; @@ -199,13 +209,14 @@ Custom30Output BasicCube(v2f i) { #endif float3 objPos = ro + rd * d_acc; // Transform from SDF space back to object space - float3 objSpacePos = objPos + (i.objPos + frag_to_origin); + float3 frag_to_origin_obj = mul(tangentToObject, float4(frag_to_origin, 1.0)); + float3 objSpacePos = objPos + (i.objPos + frag_to_origin_obj); o.objPos = objSpacePos; float4 clipPos = UnityObjectToClipPos(objSpacePos); o.depth = clipPos.z / clipPos.w; float3 sdfNormal = BasicCube_normal(objPos); - o.normal = UnityObjectToWorldNormal(sdfNormal); + o.normal = mul(tangentToWorld, sdfNormal); return o; } @@ -231,13 +242,22 @@ float3 BasicWedge_normal(float3 p) { return normalize(n); } -Custom30Output BasicWedge(v2f i) { - float3 objSpaceCameraPos = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)); +Custom30Output BasicWedge(v2f i, float4x4 tangentToWorld) { + float4x4 worldToTangent = transpose(tangentToWorld); + float4x4 objectToTangent = mul(worldToTangent, unity_ObjectToWorld); + float4x4 tangentToObject = transpose(objectToTangent); + + // Vector from fragment to origin in tangent space. + float3 frag_to_origin = (i.color * 2.0f - 1.0f) / i.color.a; - float3 frag_to_origin = GetFragToOrigin(i); + float3 tanSpaceCameraPos = mul(worldToTangent, + float4(_WorldSpaceCameraPos, 1.0)); float3 ro = -frag_to_origin; - float3 rd = normalize(i.objPos - objSpaceCameraPos); + float3 rd = normalize( + mul(worldToTangent, float4(i.worldPos, 1.0)).xyz - tanSpaceCameraPos); + + ro -= rd * _Custom30_ro_Offset; float d; float d_acc = 0; @@ -260,13 +280,14 @@ Custom30Output BasicWedge(v2f i) { #endif float3 objPos = ro + rd * d_acc; // Transform from SDF space back to object space - float3 objSpacePos = objPos + (i.objPos + frag_to_origin); + float3 frag_to_origin_obj = mul(tangentToObject, float4(frag_to_origin, 1.0)); + float3 objSpacePos = objPos + (i.objPos + frag_to_origin_obj); o.objPos = objSpacePos; float4 clipPos = UnityObjectToClipPos(objSpacePos); o.depth = clipPos.z / clipPos.w; - float3 sdfNormal = BasicWedge_normal(objPos) * float3(-1, 1, 1); - o.normal = UnityObjectToWorldNormal(sdfNormal); + float3 sdfNormal = BasicWedge_normal(objPos); + o.normal = mul(tangentToWorld, sdfNormal); return o; } @@ -320,13 +341,22 @@ float3 BasicPlatform_normal(float3 p) { return normalize(n); } -Custom30Output BasicPlatform(v2f i) { - float3 objSpaceCameraPos = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)); +Custom30Output BasicPlatform(v2f i, float4x4 tangentToWorld) { + float4x4 worldToTangent = transpose(tangentToWorld); + float4x4 objectToTangent = mul(worldToTangent, unity_ObjectToWorld); + float4x4 tangentToObject = transpose(objectToTangent); + + // Vector from fragment to origin in tangent space. + float3 frag_to_origin = (i.color * 2.0f - 1.0f) / i.color.a; - float3 frag_to_origin = GetFragToOrigin(i); + float3 tanSpaceCameraPos = mul(worldToTangent, + float4(_WorldSpaceCameraPos, 1.0)); float3 ro = -frag_to_origin; - float3 rd = normalize(i.objPos - objSpaceCameraPos); + float3 rd = normalize( + mul(worldToTangent, float4(i.worldPos, 1.0)).xyz - tanSpaceCameraPos); + + ro -= rd * _Custom30_ro_Offset; float d; float d_acc = 0; @@ -347,13 +377,79 @@ Custom30Output BasicPlatform(v2f i) { clip(epsilon - d); #endif float3 objPos = ro + rd * d_acc; - float3 objSpacePos = objPos + (i.objPos + frag_to_origin); + // Transform from SDF space back to object space + float3 frag_to_origin_obj = mul(tangentToObject, float4(frag_to_origin, 1.0)); + float3 objSpacePos = objPos + (i.objPos + frag_to_origin_obj); + o.objPos = objSpacePos; + float4 clipPos = UnityObjectToClipPos(objSpacePos); + o.depth = clipPos.z / clipPos.w; + + float3 sdfNormal = BasicPlatform_normal(objPos); + o.normal = mul(tangentToWorld, sdfNormal); + + return o; +} +#endif + +#if defined(_CUSTOM30_RAINBOW) +float Rainbow_map(float3 p) { + return length(p) - 2; +} + +float3 Rainbow_normal(float3 p) { + float epsilon = 1E-3; + float center_d = Rainbow_map(p); + float3 n = float3( + Rainbow_map(p + float3(epsilon, 0, 0)) - center_d, + Rainbow_map(p + float3(0, epsilon, 0)) - center_d, + Rainbow_map(p + float3(0, 0, epsilon)) - center_d); + return normalize(n); +} + +Custom30Output Rainbow(v2f i, float4x4 tangentToWorld) { + float4x4 worldToTangent = transpose(tangentToWorld); + float4x4 objectToTangent = mul(worldToTangent, unity_ObjectToWorld); + float4x4 tangentToObject = transpose(objectToTangent); + + // Vector from fragment to origin in tangent space. + float3 frag_to_origin = (i.color * 2.0f - 1.0f) / i.color.a; + + float3 tanSpaceCameraPos = mul(worldToTangent, + float4(_WorldSpaceCameraPos, 1.0)); + + float3 ro = -frag_to_origin; + float3 rd = normalize( + mul(worldToTangent, float4(i.worldPos, 1.0)).xyz - tanSpaceCameraPos); + + ro -= rd * _Custom30_ro_Offset; + + float d; + float d_acc = 0; + float epsilon = 1E-2; + float max_d = 1.73205081f * 2.0f; + [loop] + for (uint ii = 0; ii < CUSTOM30_MAX_STEPS; ++ii) { + float3 p = ro + rd * d_acc; + d = Rainbow_map(p); + d_acc += d; + if (d < epsilon) break; + if (d_acc > max_d) break; + } + + Custom30Output o; +#if !defined(_DEPTH_PREPASS) + clip(epsilon - d); +#endif + float3 objPos = ro + rd * d_acc; + // Transform from SDF space back to object space + float3 frag_to_origin_obj = mul(tangentToObject, float4(frag_to_origin, 1.0)); + float3 objSpacePos = objPos + (i.objPos + frag_to_origin_obj); o.objPos = objSpacePos; float4 clipPos = UnityObjectToClipPos(objSpacePos); o.depth = clipPos.z / clipPos.w; - float3 sdfNormal = BasicPlatform_normal(objPos) * float3(-1, 1, 1); - o.normal = UnityObjectToWorldNormal(sdfNormal); + float3 sdfNormal = Rainbow_normal(objPos); + o.normal = mul(tangentToWorld, sdfNormal); return o; } diff --git a/features.cginc b/features.cginc index 4dc350d..71ed9e2 100644 --- a/features.cginc +++ b/features.cginc @@ -306,6 +306,7 @@ #pragma shader_feature_local _CUSTOM30_BASICPLATFORM_CHAMFER #pragma shader_feature_local _CUSTOM30_BASICPLATFORM_Y_ALIGNED #pragma shader_feature_local _CUSTOM30_BASICPLATFORM_VERTICAL +#pragma shader_feature_local _CUSTOM30_RAINBOW //endex //ifex _Depth_Prepass_Enabled==0 @@ -318,11 +319,20 @@ //ifex _Raymarched_Fog_Height_Density_Enabled==0 #pragma shader_feature_local _RAYMARCHED_FOG_HEIGHT_DENSITY +#pragma shader_feature_local _CUSTOM30_FOG_HEIGHT_DENSITY_MINIMUM //endex //ifex _Raymarched_Fog_Density_Exponent_Enabled==0 #pragma shader_feature_local _RAYMARCHED_FOG_DENSITY_EXPONENT //endex +//ifex _Raymarched_Fog_Emitter_Texture_Enabled==0 +#pragma shader_feature_local _RAYMARCHED_FOG_EMITTER_TEXTURE +//endex + +//ifex _Unlit_Enabled==0 +#pragma shader_feature_local _UNLIT +//endex + #endif // __FEATURES_INC @@ -9,6 +9,7 @@ #if defined(_RAYMARCHED_FOG) struct FogParams { + float3 color; float steps; float density; float y_cutoff; @@ -24,8 +25,47 @@ struct FogParams { float height_density_start; float height_density_half_life; #endif +#if defined(_CUSTOM30_FOG_HEIGHT_DENSITY_MINIMUM) + float height_density_minimum; +#endif +#if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE) + texture2D emitter_texture; + float4 emitter_texture_texelsize; + float3 emitter_world_pos; + float3 emitter_normal; + float3 emitter_tangent; + float3 emitter_normal_x_tangent; + float2 emitter_scale; // [tangent scale in meters, bitangent scale in meters] + float2 emitter_scale_rcp; +#endif }; +#if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE) +// Returns weighted color +float3 getEmitterData(FogParams p, float3 pp) +{ + // Using identity a_parallel_to_b = (dot(a, b) / dot(b, b)) * b + // float3 along_tangent = dot(p - em_loc, em_tangent) * em_tangent; + // float3 along_normal_x_tangent = dot(p - em_loc, em_normal_x_tangent) * + // em_normal_x_tangent; + // Given that em_tangent and em_normal_x_tangent are normalized, and the fact + // that we really want uvs, we can simplify this: + float2 uv = float2(dot(pp - p.emitter_world_pos, p.emitter_normal_x_tangent), dot(pp - p.emitter_world_pos, p.emitter_tangent)); + uv *= p.emitter_scale_rcp; + uv *= 0.5; + uv += 0.5; + + bool in_range = uv.x < 1 && uv.y < 1 && uv.x > 0 && uv.y > 0; + [branch] + if (!in_range) { + return p.color; + } + + float4 c = p.emitter_texture.SampleLevel(linear_clamp_s, uv, 0); + return lerp(p.color, c.rgb, c.a); +} +#endif + struct FogResult { float4 color; float depth; @@ -45,7 +85,6 @@ FogResult raymarched_fog(v2f i, FogParams p) float linearZ = GetLinearZFromZDepth_WorksWithMirrors(zDepthFromMap, screen_uv); - linearZ = min(1E3, linearZ); // Get intersection with plane at elevation y. float plane_y = p.y_cutoff; @@ -57,6 +96,7 @@ FogResult raymarched_fog(v2f i, FogParams p) } } linearZ = min(linearZ, distance_to_y); + linearZ = min(linearZ, 1200); linearZ -= ro_epsilon; float dither = p.dithering_noise.SampleLevel(point_repeat_s, @@ -69,7 +109,7 @@ FogResult raymarched_fog(v2f i, FogParams p) float step_size = linearZ / p.steps; float3 pp = ro; - float d = 0; + float4 color = 0; [loop] for (uint ii = 0; ii < p.steps; ++ii) { pp += step_size * rd; @@ -97,18 +137,27 @@ FogResult raymarched_fog(v2f i, FogParams p) // y=9 -> density = 1/8 float exponent = height_clamped / p.height_density_half_life; float factor = pow(2, -exponent); +#if defined(_CUSTOM30_FOG_HEIGHT_DENSITY_MINIMUM) + factor = max(factor, p.height_density_minimum); +#endif cur_d *= factor; #endif cur_d = saturate(cur_d); - d = d + (1 - d) * cur_d; + +#if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE) + float4 cur_c = float4(getEmitterData(p, pp) * cur_d, cur_d); +#else + float4 cur_c = float4(p.color * cur_d, cur_d); +#endif + color += (1.0f - color.a) * cur_c; } FogResult r; - r.color.rgb = _Raymarched_Fog_Color; + r.color = color; //r.color.rgb = saturate(log(linearZ) / 5.0); //r.color.rgb = float3(screen_uv, 0); - r.color.a = d; + //r.color.a = d; r.depth = 0.0001; // Very small depth value to render in front return r; } diff --git a/globals.cginc b/globals.cginc index e1cc6f1..1bb881a 100644 --- a/globals.cginc +++ b/globals.cginc @@ -553,6 +553,17 @@ float _Raymarched_Fog_Density_Exponent; float _Raymarched_Fog_Height_Density_Start;
float _Raymarched_Fog_Height_Density_Half_Life;
#endif
+#if defined(_CUSTOM30_FOG_HEIGHT_DENSITY_MINIMUM)
+float _Custom30_Fog_Height_Density_Minimum;
+#endif
+#if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE)
+texture2D _Raymarched_Fog_Emitter_Texture;
+float4 _Raymarched_Fog_Emitter_Texture_TexelSize;
+float3 _Raymarched_Fog_Emitter_Texture_World_Pos;
+float3 _Raymarched_Fog_Emitter_Texture_World_Normal;
+float3 _Raymarched_Fog_Emitter_Texture_World_Tangent;
+float2 _Raymarched_Fog_Emitter_Texture_World_Scale;
+#endif
#endif // _RAYMARCHED_FOG
#endif // __GLOBALS_INC
diff --git a/vertex_domain_warping.cginc b/vertex_domain_warping.cginc index 29c500a..66053a6 100644 --- a/vertex_domain_warping.cginc +++ b/vertex_domain_warping.cginc @@ -24,7 +24,7 @@ float3 domainWarpVertexPosition(float3 objPos) { for (uint i = 0; i < octaves; i++) {
float3 uv = objPos * scale + speed * _Time[0];
- float3 noise = _Vertex_Domain_Warping_Noise.SampleLevel(trilinear_repeat_s, uv, 0);
+ float3 noise = _Vertex_Domain_Warping_Noise.SampleLevel(linear_repeat_s, uv, 0);
objPos += (noise * 2 - 1) * strength;
}
#endif // _VERTEX_DOMAIN_WARPING
|
