summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--3ner.cginc2
-rw-r--r--3ner.shader11
-rw-r--r--globals.cginc14
-rw-r--r--pbr.cginc21
4 files changed, 39 insertions, 9 deletions
diff --git a/3ner.cginc b/3ner.cginc
index 00d98a0..d50f553 100644
--- a/3ner.cginc
+++ b/3ner.cginc
@@ -163,6 +163,8 @@ v2f domain(
float4 frag(v2f i, uint facing : SV_IsFrontFace) : SV_Target {
i.normal *= facing ? 1 : -1;
+ i.normal = normalize(i.normal);
+ i.tangent.xyz = normalize(i.tangent.xyz);
Pbr pbr = getPbr(i);
LightData light_data;
GetLighting(i, pbr, light_data);
diff --git a/3ner.shader b/3ner.shader
index 6321a9d..7b6fbac 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -27,10 +27,17 @@ Shader "yum_food/3ner"
{value:7,actions:[{type:SET_PROPERTY,data:render_queue=3000},{type:SET_PROPERTY,data:_AlphaForceOpaque=0}, {type:SET_PROPERTY,data:render_type=Transparent}, {type:SET_PROPERTY,data:_BlendOp=0}, {type:SET_PROPERTY,data:_BlendOpAlpha=4}, {type:SET_PROPERTY,data:_Cutoff=0}, {type:SET_PROPERTY,data:_SrcBlend=2}, {type:SET_PROPERTY,data:_DstBlend=3}, {type:SET_PROPERTY,data:_SrcBlendAlpha=1}, {type:SET_PROPERTY,data:_DstBlendAlpha=1}, {type:SET_PROPERTY,data:_AddSrcBlend=2}, {type:SET_PROPERTY,data:_AddDstBlend=1}, {type:SET_PROPERTY,data:_AddSrcBlendAlpha=0}, {type:SET_PROPERTY,data:_AddDstBlendAlpha=1}, {type:SET_PROPERTY,data:_AlphaToCoverage=0}, {type:SET_PROPERTY,data:_ZWrite=0}, {type:SET_PROPERTY,data:_ZTest=4}, {type:SET_PROPERTY,data:_AlphaPremultiply=0}, {type:SET_PROPERTY,data:_OutlineSrcBlend=2}, {type:SET_PROPERTY,data:_OutlineDstBlend=3}, {type:SET_PROPERTY,data:_OutlineSrcBlendAlpha=1}, {type:SET_PROPERTY,data:_OutlineDstBlendAlpha=1}, {type:SET_PROPERTY,data:_OutlineBlendOp=0}, {type:SET_PROPERTY,data:_OutlineBlendOpAlpha=4}]}
}]}]}", Int) = 0
- [HideInInspector] m_mainOptions("Main", Float) = 0
+ [HideInInspector] m_start_Main("Main", Float) = 0
+ _MainTex("Base color", 2D) = "white" {}
_Color("Tint", Color) = (1, 1, 1, 1)
+
+ _BumpMap("Normal", 2D) = "bump" {}
+ _BumpScale("Normal Scale", Float) = 1
+
+ _MetallicGlossMap("Metallic (r) smoothness (a)", 2D) = "white" {}
_Metallic("Metallic", Range(0, 1)) = 0
- _Smoothness("Smoothness", Range(0, 1)) = 0
+ _Glossiness("Smoothness", Range(0, 1)) = 0.5
+ [HideInInspector] m_end_Main("Main", Float) = 0
[HideInInspector] m_start_Gimmicks("Gimmicks", Float) = 0
//ifex _Marble_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index 897e077..b1db690 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -9,10 +9,20 @@ SamplerState bilinear_repeat_s;
SamplerState linear_clamp_s;
SamplerState trilinear_repeat_s;
+int _Mode; // opaque, cutout, transparent, etc.
+
+texture2D _MainTex;
+float4 _MainTex_ST;
float4 _Color;
-int _Mode;
-float _Smoothness;
+texture2D _BumpMap;
+float4 _BumpMap_ST;
+float _BumpScale;
+
+
+texture2D _MetallicGlossMap;
+float4 _MetallicGlossMap_ST;
+float _Glossiness;
float _Metallic;
float _Specular_AA_Variance;
diff --git a/pbr.cginc b/pbr.cginc
index 156fba2..1677ccc 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -8,6 +8,7 @@
struct Pbr {
float4 albedo;
float3 normal;
+ float3x3 tbn;
float smoothness;
float roughness_perceptual;
float roughness;
@@ -40,13 +41,23 @@ void apply_marble(float3 world_pos, inout float3 albedo) {
Pbr getPbr(v2f i) {
Pbr pbr = (Pbr) 0;
- pbr.normal = normalize(i.normal);
- pbr.albedo = _Color;
- pbr.smoothness = _Smoothness;
- propagateSmoothness(pbr);
+
+ pbr.albedo = _MainTex.Sample(trilinear_repeat_s, i.uv0 * _MainTex_ST.xy);
+ pbr.albedo *= _Color;
apply_marble(i.worldPos, pbr.albedo.xyz);
- pbr.metallic = _Metallic;
+ float3 normal_tangent = UnpackNormal(_BumpMap.Sample(trilinear_repeat_s, i.uv0 * _BumpMap_ST.xy));
+ normal_tangent.xy *= _BumpScale;
+ // 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(trilinear_repeat_s, i.uv0 * _MetallicGlossMap_ST.xy);
+ pbr.smoothness = metallic_gloss.a * _Glossiness;
+ pbr.metallic = metallic_gloss.r * _Metallic;
+
+ propagateSmoothness(pbr);
return pbr;
}