summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--3ner.shader16
-rw-r--r--LUTS/dfg_cloth.exr.meta2
-rw-r--r--features.cginc8
-rw-r--r--globals.cginc11
-rw-r--r--pbr.cginc67
5 files changed, 100 insertions, 4 deletions
diff --git a/3ner.shader b/3ner.shader
index d940f1d..e7865e2 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -399,6 +399,22 @@ Shader "yum_food/3ner"
[ThryToggle(_UNLIT)] _Unlit("Unlit", Float) = 0
//endex
+ //ifex _Parallax_Heightmap_Enabled==0
+ [HideInInspector] m_start_Parallax_Heightmap("Parallax Heightmap", Float) = 0
+ [ThryToggle(_PARALLAX_HEIGHTMAP)] _Parallax_Heightmap_Enabled("Enable", Float) = 0
+ _Parallax_Heightmap("Heightmap", 2D) = "gray" {}
+ _Parallax_Heightmap_Scale("Scale", Float) = 1
+ _Parallax_Heightmap_Bias("Neutral point", Float) = 0.5
+
+ //ifex _Parallax_Heightmap_Ray_Marching_Enabled==0
+ [HideInInspector] m_start_Parallax_Heightmap_Ray_Marching("Parallax Heightmap Ray Marching", Float) = 0
+ [ThryToggle(_PARALLAX_HEIGHTMAP_RAY_MARCHING)] _Parallax_Heightmap_Ray_Marching_Enabled("Enable", Float) = 0
+ [IntRange] _Parallax_Heightmap_Ray_Marching_Steps("Steps", Range(1, 10)) = 5
+ [HideInInspector] m_end_Parallax_Heightmap_Ray_Marching("Parallax Heightmap Ray Marching", Float) = 0
+ //endex
+ [HideInInspector] m_end_Parallax_Heightmap("Parallax Heightmap", Float) = 0
+ //endex
+
//ifex _Shadow_Caster_Enabled==0
[HideInInspector] m_start_Shadow_Caster("Shadow caster pass", Float) = 0
[ThryToggle(_SHADOW_CASTER)] _Shadow_Caster_Enabled("Enable", Float) = 1
diff --git a/LUTS/dfg_cloth.exr.meta b/LUTS/dfg_cloth.exr.meta
index 450e377..a3630b0 100644
--- a/LUTS/dfg_cloth.exr.meta
+++ b/LUTS/dfg_cloth.exr.meta
@@ -5,7 +5,7 @@ TextureImporter:
externalObjects: {}
serializedVersion: 12
mipmaps:
- mipMapMode: 0
+ mipMapMode: 1
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
diff --git a/features.cginc b/features.cginc
index f693049..814d80d 100644
--- a/features.cginc
+++ b/features.cginc
@@ -41,6 +41,14 @@
#pragma shader_feature_local _UNLIT
//endex
+//ifex _Parallax_Heightmap_Enabled==0
+#pragma shader_feature_local _PARALLAX_HEIGHTMAP
+//endex
+
+//ifex _Parallax_Heightmap_Ray_Marching_Enabled==0
+#pragma shader_feature_local _PARALLAX_HEIGHTMAP_RAY_MARCHING
+//endex
+
//ifex _UV_Scroll_Enabled==0
#pragma shader_feature_local _UV_SCROLL
//endex
diff --git a/globals.cginc b/globals.cginc
index 911aceb..ad7f6d4 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -166,6 +166,17 @@ float _Ray_Marching_Hexagon_Radius;
float _Ray_Marching_Hexagon_Height;
#endif // _RAY_MARCHING_HEXAGON
+#if defined(_PARALLAX_HEIGHTMAP)
+texture2D _Parallax_Heightmap;
+float4 _Parallax_Heightmap_ST;
+float _Parallax_Heightmap_Scale;
+float _Parallax_Heightmap_Bias;
+#endif // _PARALLAX_HEIGHTMAP
+
+#if defined(_PARALLAX_HEIGHTMAP_RAY_MARCHING)
+float _Parallax_Heightmap_Ray_Marching_Steps;
+#endif // _PARALLAX_HEIGHTMAP_RAY_MARCHING
+
#if defined(_VERTEX_DEFORMATION)
float _Vertex_Deformation_Slot_0_Enabled;
int _Vertex_Deformation_Slot_0_Opcode;
diff --git a/pbr.cginc b/pbr.cginc
index 73ff970..8501edc 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -27,6 +27,63 @@ struct Pbr {
#define MIN_PERCEPTUAL_ROUGHNESS 5e-2f
#define MIN_ROUGHNESS 5e-3f
+#if defined(_PARALLAX_HEIGHTMAP)
+float2 parallax_offset(float2 uv, float3 view_dir_world, float3x3 tbn) {
+ float3 view_dir_tangent = mul(tbn, view_dir_world);
+ float2 uv_step = view_dir_tangent.xy / max(view_dir_tangent.z, 1e-3f) * _Parallax_Heightmap_Scale;
+
+#if defined(_PARALLAX_HEIGHTMAP_RAY_MARCHING)
+ float step_count = _Parallax_Heightmap_Ray_Marching_Steps;
+ float2 delta_uv = uv_step / step_count;
+ float delta_depth = 1.0 / step_count;
+
+ float2 cur_uv = uv;
+ float cur_depth = 0.0;
+ float cur_height = 1.0 - _Parallax_Heightmap.Sample(linear_repeat_s,
+ cur_uv * _Parallax_Heightmap_ST.xy + _Parallax_Heightmap_ST.zw).r;
+ cur_height = (cur_height - (1.0 - _Parallax_Heightmap_Bias));
+
+ // If starting inside geometry, march backwards
+ bool inside = cur_depth < cur_height;
+ if (!inside) {
+ delta_uv = -delta_uv;
+ delta_depth = -delta_depth;
+ }
+
+ float prev_depth = cur_depth;
+ float prev_height = cur_height;
+
+ [loop]
+ for (int i = 0; i < (int)step_count; i++) {
+ bool was_inside = cur_depth < cur_height;
+ if (was_inside != inside) break;
+
+ prev_depth = cur_depth;
+ prev_height = cur_height;
+
+ cur_uv += delta_uv;
+ cur_depth += delta_depth;
+ cur_height = 1.0 - _Parallax_Heightmap.Sample(linear_repeat_s,
+ cur_uv * _Parallax_Heightmap_ST.xy + _Parallax_Heightmap_ST.zw).r;
+ cur_height = (cur_height - (1.0 - _Parallax_Heightmap_Bias));
+ }
+
+ // Linear interpolation between last two samples
+ float after = cur_height - cur_depth;
+ float before = prev_height - prev_depth;
+ float t = after / (after - before);
+
+ return cur_uv - uv - delta_uv * t;
+#else
+ float2 heightmap_uv = uv * _Parallax_Heightmap_ST.xy + _Parallax_Heightmap_ST.zw;
+ float height = _Parallax_Heightmap.Sample(linear_repeat_s, heightmap_uv).r;
+ height = height - _Parallax_Heightmap_Bias;
+
+ return uv_step * height;
+#endif
+}
+#endif // _PARALLAX_HEIGHTMAP
+
// TODO consider normal filtering like filamented
void propagateSmoothness(inout Pbr pbr) {
pbr.roughness_perceptual = max(MIN_PERCEPTUAL_ROUGHNESS, 1.0f - pbr.smoothness);
@@ -54,10 +111,17 @@ void apply_marble(float3 world_pos, inout float3 albedo) {
Pbr getPbr(v2f i) {
Pbr pbr = (Pbr) 0;
+ float3 bitangent = cross(i.normal, i.tangent.xyz) * i.tangent.w;
+ pbr.tbn = float3x3(i.tangent.xyz, bitangent, i.normal);
+
#if defined(_UV_SCROLL)
i.uv01.xy += getTime() * _UV_Scroll_Speed;
#endif // _UV_SCROLL
+#if defined(_PARALLAX_HEIGHTMAP)
+ i.uv01.xy += parallax_offset(i.uv01.xy, normalize(i.eyeVec.xyz), pbr.tbn);
+#endif // _PARALLAX_HEIGHTMAP
+
pbr.albedo = _MainTex.Sample(aniso16_trilinear_repeat_s, i.uv01.xy * _MainTex_ST.xy + _MainTex_ST.zw);
pbr.albedo *= _Color;
apply_marble(i.worldPos, pbr.albedo.xyz);
@@ -74,9 +138,6 @@ Pbr getPbr(v2f i) {
normal_tangent = blendNormalsHill12(normal_tangent, detail_normal);
#endif
- // Map from tangent space to world space.
- float3 bitangent = cross(i.normal, i.tangent.xyz) * i.tangent.w;
- pbr.tbn = float3x3(i.tangent.xyz, bitangent, i.normal);
pbr.normal = normalize(mul(normal_tangent, pbr.tbn));
float4 metallic_gloss = _MetallicGlossMap.Sample(aniso16_trilinear_repeat_s, i.uv01.xy * _MetallicGlossMap_ST.xy);