diff options
| -rw-r--r-- | 2ner.cginc | 10 | ||||
| -rw-r--r-- | 2ner.shader | 4 | ||||
| -rw-r--r-- | decals.cginc | 10 | ||||
| -rw-r--r-- | features.cginc | 1 | ||||
| -rw-r--r-- | globals.cginc | 4 | ||||
| -rw-r--r-- | math.cginc | 6 | ||||
| -rw-r--r-- | shatter_wave.cginc | 4 | ||||
| -rw-r--r-- | tessellation.cginc | 11 |
8 files changed, 34 insertions, 16 deletions
@@ -13,6 +13,7 @@ #include "interpolators.cginc"
#include "letter_grid.cginc"
#include "matcaps.cginc"
+#include "math.cginc"
#include "poi.cginc"
#include "shatter_wave.cginc"
#include "ssfd.cginc"
@@ -174,11 +175,11 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace i.tangent = UnityObjectToWorldNormal(i.tangent);
i.binormal = UnityObjectToWorldNormal(i.binormal);
-#if defined(_SHATTER_WAVE)
- shatterWaveFrag(i.normal, i.objPos);
+#if defined(_SHATTER_WAVE) || defined(_TESSELLATION_HEIGHTMAP)
+ calcNormalInScreenSpace(i.normal, i.objPos);
#endif
-#if defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING)
+#if defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING) || defined(_TESSELLATION_HEIGHTMAP)
{
[branch]
if (
@@ -189,6 +190,9 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace #if defined(_VERTEX_DOMAIN_WARPING)
|| _Vertex_Domain_Warping_Octaves > 0.1
#endif
+#if defined(_TESSELLATION_HEIGHTMAP)
+ || _Tessellation_Heightmap_Scale > 1E-4
+#endif
) {
float4 clip_pos = UnityObjectToClipPos(i.objPos);
depth = clip_pos.z / clip_pos.w;
diff --git a/2ner.shader b/2ner.shader index 1dc1bdc..55d08a4 100644 --- a/2ner.shader +++ b/2ner.shader @@ -545,6 +545,10 @@ Shader "yum_food/2ner" _Tessellation_Heightmap("Heightmap", 2D) = "black" {} _Tessellation_Heightmap_Scale("Scale", Float) = 1 _Tessellation_Heightmap_Offset("Offset", Range(-1, 1)) = 0 + [HideInInspector] m_start_Tessellation_Heightmap_Direction_Control("Direction control", Float) = 0 + [ThryToggle(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)] _Tessellation_Heightmap_Direction_Control_Enabled("Enable", Float) = 0 + _Tessellation_Heightmap_Direction_Control_Vector("Direction (normal/tangent/binormal)", Vector) = (1, 0, 0) + [HideInInspector] m_end_Tessellation_Heightmap_Direction_Control("Direction control", Float) = 0 [HideInInspector] m_end_Tessellation_Heightmap("Heightmap", Float) = 0 [HideInInspector] m_start_Tessellation_Range_Factor("Range-based factor", Float) = 0 [ThryToggle(_TESSELLATION_RANGE_FACTOR)] _Tessellation_Range_Factor_Enabled("Enable", Float) = 0 diff --git a/decals.cginc b/decals.cginc index c120c79..59ab085 100644 --- a/decals.cginc +++ b/decals.cginc @@ -71,7 +71,6 @@ struct DecalParams { sd = params.sdf_invert ? 1 - sd : sd; \
sd = (sd > params.sdf_threshold ? 1 : 0); \
decal_albedo = params.color * sd; \
- decal_albedo.a *= params.opacity; \
}
#define APPLY_DECAL_SEC01_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, params) \
@@ -79,7 +78,6 @@ struct DecalParams { { \
decal_albedo = params.mainTex.Sample(linear_repeat_s, decal_uv); \
decal_albedo *= params.color; \
- decal_albedo.a *= params.opacity; \
}
#define APPLY_DECAL_SEC02_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
@@ -99,16 +97,18 @@ struct DecalParams { float decal_mask = 1;
#define APPLY_DECAL_SEC04_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, params) \
+ decal_albedo.a = lerp(0, decal_albedo.a, params.opacity); \
albedo = alphaBlend(albedo, decal_albedo);
#define APPLY_DECAL_SEC04_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, params) \
- albedo = lerp(albedo, decal_albedo, decal_mask);
+ albedo = lerp(albedo, decal_albedo, decal_mask * params.opacity);
#define APPLY_DECAL_SEC05_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
float3 decal_normal = UnpackScaleNormal( \
params.normalTex.Sample(linear_repeat_s, decal_uv), \
- params.normal_scale * decal_albedo.a); \
- normal_tangent = lerp(normal_tangent, decal_normal, decal_albedo.a);
+ params.normal_scale * decal_albedo.a * params.opacity); \
+ normal_tangent = blendNormalsHill12(normal_tangent, decal_normal);
+ //normal_tangent = lerp(normal_tangent, decal_normal, decal_albedo.a * params.opacity);
#define APPLY_DECAL_SEC05_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, params) {}
diff --git a/features.cginc b/features.cginc index 766d1cd..faffddd 100644 --- a/features.cginc +++ b/features.cginc @@ -223,6 +223,7 @@ //ifex _Tessellation_Enabled==0 #pragma shader_feature_local _TESSELLATION #pragma shader_feature_local _TESSELLATION_HEIGHTMAP +#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL #pragma shader_feature_local _TESSELLATION_RANGE_FACTOR //endex diff --git a/globals.cginc b/globals.cginc index 62bbdee..5530d41 100644 --- a/globals.cginc +++ b/globals.cginc @@ -457,6 +457,10 @@ float _Tessellation_Heightmap_Scale; float _Tessellation_Heightmap_Offset;
#endif // _TESSELLATION_HEIGHTMAP
+#if defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)
+float3 _Tessellation_Heightmap_Direction_Control_Vector;
+#endif // _TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL
+
#if defined(_TESSELLATION_RANGE_FACTOR)
float _Tessellation_Range_Factor_Distance_Near;
float _Tessellation_Range_Factor_Factor_Near;
@@ -16,7 +16,7 @@ float pow5(float x) }
float wrapNoL(float NoL, float k) {
-#if 1
+#if 0
// https://www.iro.umontreal.ca/~derek/files/jgt_wrap_final.pdf
return pow(max(1E-4, (NoL + k) / (1 + k)), 1 + k);
#else
@@ -242,4 +242,8 @@ float4 get_quaternion(float3 axis_normal, float theta) { return float4(axis_normal * sin(theta / 2), cos(theta / 2));
}
+void calcNormalInScreenSpace(inout float3 normal, float3 objPos) {
+ normal = normalize(cross(ddy(objPos), ddx(objPos)));
+}
+
#endif // __MATH_INC
diff --git a/shatter_wave.cginc b/shatter_wave.cginc index d65741f..24afb27 100644 --- a/shatter_wave.cginc +++ b/shatter_wave.cginc @@ -97,10 +97,6 @@ void shatterWaveVert(inout float3 objPos, float3 objNormal, float3 objTangent) { objPos += objNormal * (offset.x + offset.y + offset.z + offset.w);
}
-void shatterWaveFrag(inout float3 normal, float3 objPos) {
- normal = normalize(cross(ddy(objPos), ddx(objPos)));
-}
-
#endif // _SHATTER_WAVE
#endif // __SHATTER_WAVE_INC
diff --git a/tessellation.cginc b/tessellation.cginc index cc47057..fc79177 100644 --- a/tessellation.cginc +++ b/tessellation.cginc @@ -133,11 +133,16 @@ v2f domain( _Tessellation_Heightmap_Offset + _Tessellation_Heightmap_Scale * -0.5; #endif -#if defined(OUTLINE_PASS) - o.objPos.xyz += -o.normal * height; +#if defined(OUTLINE_PASS) && defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL) + float3 heightmap_direction = mul(transpose(-float3x3(o.normal, o.tangent, o.binormal)), _Tessellation_Heightmap_Direction_Control_Vector); +#elif defined(OUTLINE_PASS) && !defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL) + float3 heightmap_direction = -o.normal; +#elif !defined(OUTLINE_PASS) && defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL) + float3 heightmap_direction = mul(transpose(float3x3(o.normal, o.tangent, o.binormal)), _Tessellation_Heightmap_Direction_Control_Vector); #else - o.objPos.xyz += o.normal * height; + float3 heightmap_direction = o.normal; #endif + o.objPos.xyz += heightmap_direction * height; #endif o.pos = UnityObjectToClipPos(o.objPos); |
