summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--3ner.shader14
-rw-r--r--brdf.cginc9
-rw-r--r--features.cginc62
-rw-r--r--globals.cginc9
-rw-r--r--math.cginc15
-rw-r--r--pbr.cginc16
6 files changed, 62 insertions, 63 deletions
diff --git a/3ner.shader b/3ner.shader
index 727d733..6321a9d 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -32,6 +32,20 @@ Shader "yum_food/3ner"
_Metallic("Metallic", Range(0, 1)) = 0
_Smoothness("Smoothness", Range(0, 1)) = 0
+ [HideInInspector] m_start_Gimmicks("Gimmicks", Float) = 0
+ //ifex _Marble_Enabled==0
+ [HideInInspector] m_start_Marble("Marble", Float) = 0
+ [ThryToggle(_MARBLE)] _Marble_Enabled("Enable", Float) = 0
+ [Gradient] _Marble_U_Ramp("U Ramp", 2D) = "white" {}
+ [Gradient] _Marble_V_Ramp("V Ramp", 2D) = "white" {}
+ [Gradient] _Marble_W_Ramp("W Ramp", 2D) = "white" {}
+ _Marble_Scale("Scale", Vector) = (1, 1, 1, 0)
+ _Marble_Strength("Strength", Float) = 1
+ _Marble_Octaves("Octaves", Range(1, 10)) = 3
+ [HideInInspector] m_end_Marble("Marble", Float) = 0
+ //endex
+ [HideInInspector] m_end_Gimmicks("Gimmicks", Float) = 0
+
//ifex _Tessellation_Enabled==0
[HideInInspector] m_start_Tessellation("Tessellation", Float) = 0
[ThryToggle(_TESSELLATION)] _Tessellation_Enabled("Enable", Float) = 0
diff --git a/brdf.cginc b/brdf.cginc
index 1504ef0..6ca8c8d 100644
--- a/brdf.cginc
+++ b/brdf.cginc
@@ -72,7 +72,6 @@ float4 brdf(Pbr pbr, LightData data) {
data.direct.NoL = 1;
data.direct.NoH = 1;
data.direct.LoH = 1;
- data.direct.LoV = 1;
#endif
// Direct
@@ -82,18 +81,22 @@ float4 brdf(Pbr pbr, LightData data) {
float G = V_GGXSmith(pbr.roughness, data.direct.NoL, data.common.NoV);
float FDG = F * D * G;
+
float3 direct_specular = FDG * data.direct.color * data.direct.NoL * lerp(1.0f, pbr.albedo.xyz, pbr.metallic);
+ direct_specular = max(0, direct_specular);
specular += direct_specular;
float3 remainder = (1.0f - direct_specular);
float Fd = Fd_OrenNayar(pbr.roughness, data.common.NoV, data.direct.NoL, data.direct.LoV) / PI;
float3 direct_diffuse = Fd * remainder * (1.0f - pbr.metallic) * pbr.albedo.xyz * data.direct.color;
- diffuse += direct_diffuse;
+ direct_diffuse = max(0, direct_diffuse);
+ diffuse += direct_diffuse;
}
// Indirect
- if (false) {
+ if (true) {
float F = F_Schlick(data.indirect.LoH, f0, f90);
+ float G = V_GGXSmith(pbr.roughness, data.indirect.NoL, data.common.NoV);
float3 indirect_specular = F * data.indirect.specular;
specular += indirect_specular;
diff --git a/features.cginc b/features.cginc
index cffb33e..4958d77 100644
--- a/features.cginc
+++ b/features.cginc
@@ -5,66 +5,8 @@
#pragma shader_feature_local _GRADIENT_NORMALS
//endex
-//ifex _Sea_FX_Enabled==0
-#pragma shader_feature_local _SEA_FX
-//endex
-
-//ifex _Sea_FX_Heightmaps_Y_0_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_Y_0
-//endex
-//ifex _Sea_FX_Heightmaps_Y_1_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_Y_1
-//endex
-//ifex _Sea_FX_Heightmaps_Y_2_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_Y_2
-//endex
-//ifex _Sea_FX_Heightmaps_Y_3_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_Y_3
-//endex
-//ifex _Sea_FX_Heightmaps_XZ_0_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_XZ_0
-//endex
-//ifex _Sea_FX_Heightmaps_XZ_1_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_XZ_1
-//endex
-//ifex _Sea_FX_Heightmaps_XZ_2_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_XZ_2
-//endex
-//ifex _Sea_FX_Heightmaps_XZ_3_Enabled==0
-#pragma shader_feature_local _SEA_FX_HEIGHTMAPS_XZ_3
-//endex
-
-//ifex _Sea_FX_Vertical_Derivatives_0_Enabled==0
-#pragma shader_feature_local _SEA_FX_VERTICAL_DERIVATIVES_0
-//endex
-//ifex _Sea_FX_Horizontal_Derivatives_0_Enabled==0
-#pragma shader_feature_local _SEA_FX_HORIZONTAL_DERIVATIVES_0
-//endex
-//ifex _Sea_FX_Vertical_Derivatives_1_Enabled==0
-#pragma shader_feature_local _SEA_FX_VERTICAL_DERIVATIVES_1
-//endex
-//ifex _Sea_FX_Horizontal_Derivatives_1_Enabled==0
-#pragma shader_feature_local _SEA_FX_HORIZONTAL_DERIVATIVES_1
-//endex
-//ifex _Sea_FX_Vertical_Derivatives_2_Enabled==0
-#pragma shader_feature_local _SEA_FX_VERTICAL_DERIVATIVES_2
-//endex
-//ifex _Sea_FX_Horizontal_Derivatives_2_Enabled==0
-#pragma shader_feature_local _SEA_FX_HORIZONTAL_DERIVATIVES_2
-//endex
-//ifex _Sea_FX_Vertical_Derivatives_3_Enabled==0
-#pragma shader_feature_local _SEA_FX_VERTICAL_DERIVATIVES_3
-//endex
-//ifex _Sea_FX_Horizontal_Derivatives_3_Enabled==0
-#pragma shader_feature_local _SEA_FX_HORIZONTAL_DERIVATIVES_3
-//endex
-
-//ifex _Sea_Foam_Enabled==0
-#pragma shader_feature_local _SEA_FOAM
-//endex
-
-//ifex _Sea_SSS_Enabled==0
-#pragma shader_feature_local _SEA_SSS
+//ifex _Marble_Enabled==0
+#pragma shader_feature_local _MARBLE
//endex
//ifex _Tessellation_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index fefeb46..897e077 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -19,6 +19,15 @@ float _Specular_AA_Variance;
float _Specular_AA_Threshold;
float _BRDF_Specular_Min_Denom;
+#if defined(_MARBLE)
+texture2D _Marble_U_Ramp;
+texture2D _Marble_V_Ramp;
+texture2D _Marble_W_Ramp;
+float3 _Marble_Scale;
+float _Marble_Octaves;
+float _Marble_Strength;
+#endif // _MARBLE
+
#if defined(_TESSELLATION)
float _Tessellation_Factor;
float _Tessellation_Frustum_Culling_Bias;
diff --git a/math.cginc b/math.cginc
index 4b91209..0d59121 100644
--- a/math.cginc
+++ b/math.cginc
@@ -4,6 +4,21 @@
#define PI 3.14159265358979f
#define RCP_PI (1.0f / PI)
+float sin_noise_3d(float3 uvw) {
+ return sin(uvw[0]) * sin(uvw[1]) * sin(uvw[2]);
+}
+
+float sin_noise_3d_fbm(float3 uvw, uint octaves, float k, float strength) {
+ float result = 0;
+ float factor = 1.0f;
+ for (uint i = 0; i < octaves; i++) {
+ result += sin_noise_3d(uvw) * factor * strength;
+ uvw *= k;
+ factor /= k;
+ }
+ return result;
+}
+
// Wrap a dot product. Assume it's already clamped.
// At k=0, you get standard lambertian shading.
// At k=0.5, you get half-lambertian shading.
diff --git a/pbr.cginc b/pbr.cginc
index 7167929..156fba2 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -23,12 +23,28 @@ void propagateSmoothness(inout Pbr pbr) {
pbr.roughness = max(MIN_ROUGHNESS, pbr.roughness_perceptual * pbr.roughness_perceptual);
}
+void apply_marble(float3 world_pos, inout float3 albedo) {
+#if defined(_MARBLE)
+ float3 uvw = world_pos * _Marble_Scale;
+ float noise_r = sin_noise_3d_fbm(uvw + _Time[0], _Marble_Octaves, 2.0f, _Marble_Strength);
+ float noise_g = sin_noise_3d_fbm(uvw+3.1 + _Time[0], _Marble_Octaves, 2.0f, _Marble_Strength);
+ float noise_b = sin_noise_3d_fbm(uvw+3.7 + _Time[0], _Marble_Octaves, 2.0f, _Marble_Strength);
+
+ float3 r = _Marble_U_Ramp.Sample(linear_repeat_s, float2(noise_r, 0));
+ float3 g = _Marble_V_Ramp.Sample(linear_repeat_s, float2(noise_g, 0));
+ float3 b = _Marble_W_Ramp.Sample(linear_repeat_s, float2(noise_b, 0));
+
+ albedo = r + g + b;
+#endif
+}
+
Pbr getPbr(v2f i) {
Pbr pbr = (Pbr) 0;
pbr.normal = normalize(i.normal);
pbr.albedo = _Color;
pbr.smoothness = _Smoothness;
propagateSmoothness(pbr);
+ apply_marble(i.worldPos, pbr.albedo.xyz);
pbr.metallic = _Metallic;
return pbr;