diff options
| author | yum <yum.food.vr@gmail.com> | 2025-02-18 16:35:22 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-02-18 16:35:22 -0800 |
| commit | 547c6064f6a8ab2749f496ce7ea2856e8cc1bcda (patch) | |
| tree | 080e30ef69f9e4daa476e529c9f015bd2cf77fa8 | |
| parent | 3087ea990dfea49c32a8a9d9f6ac9c1790817efc (diff) | |
Add matcaps and rim lighting
* Add min brightness
* MainTex and BumpMap can be independently tiled
* Fix outlines
* Remove lightDirTS (unused)
* Normalize i.normal in pixel shader
* Elide unused AO when locked
* Wrap lines at 80 columns
| -rw-r--r-- | 2ner.cginc | 30 | ||||
| -rw-r--r-- | 2ner.shader | 81 | ||||
| -rw-r--r-- | features.cginc | 26 | ||||
| -rw-r--r-- | globals.cginc | 51 | ||||
| -rw-r--r-- | interpolators.cginc | 1 | ||||
| -rw-r--r-- | matcaps.cginc | 87 | ||||
| -rw-r--r-- | texture_utils.cginc | 24 | ||||
| -rw-r--r-- | yum_lighting.cginc | 13 | ||||
| -rw-r--r-- | yum_pbr.cginc | 16 |
9 files changed, 296 insertions, 33 deletions
@@ -7,12 +7,19 @@ #include "features.cginc"
#include "globals.cginc"
#include "interpolators.cginc"
+#include "matcaps.cginc"
#include "poi.cginc"
#include "yum_brdf.cginc"
#include "yum_pbr.cginc"
#include "yum_lighting.cginc"
v2f vert(appdata v) {
+#if defined(OUTLINE_PASS) && !defined(_OUTLINES)
+ // The outline pass will be entirely elided when locked. This just lets us
+ // hide outlines when not locked.
+ return (v2f) (0.0/0.0);
+#endif
+
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
@@ -30,23 +37,17 @@ v2f vert(appdata v) { v.normal *= -1;
v.tangent *= -1;
#endif // OUTLINE_PASS
+
o.pos = UnityObjectToClipPos(v.vertex);
- o.uv01.xy = TRANSFORM_TEX(v.uv01.xy, _MainTex);
- o.uv01.zw = TRANSFORM_TEX(v.uv01.zw, _MainTex);
+ o.uv01 = v.uv01;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.eyeVec.xyz = normalize(o.worldPos - _WorldSpaceCameraPos);
- // Calculate TBN matrix
+ // These are used to convert normals from tangent space to world space.
o.normal = UnityObjectToWorldNormal(v.normal);
o.tangent = UnityObjectToWorldDir(v.tangent.xyz);
- o.binormal = cross(o.normal, o.tangent) * v.tangent.w * unity_WorldTransformParams.w;
-
- // From filamented
- float3 lightDirWS = normalize(_WorldSpaceLightPos0.xyz - o.worldPos * _WorldSpaceLightPos0.w);
- o.lightDirTS = float3(
- dot(o.tangent, lightDirWS),
- dot(o.binormal, lightDirWS),
- dot(o.normal, lightDirWS));
+ o.binormal = cross(o.normal, o.tangent) * v.tangent.w *
+ unity_WorldTransformParams.w;
UNITY_TRANSFER_LIGHTING(o, v.uv1);
UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos);
@@ -61,6 +62,9 @@ float4 frag(v2f i) : SV_Target { UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
+ // Not necessarily normalized after interpolation
+ i.normal = normalize(i.normal);
+
YumPbr pbr = GetYumPbr(i);
UNITY_BRANCH
@@ -69,6 +73,10 @@ float4 frag(v2f i) : SV_Target { pbr.albedo.a = 1;
}
+#if defined(FORWARD_BASE_PASS)
+ applyMatcapsAndRimLighting(i, pbr);
+#endif
+
#if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS) || defined(OUTLINE_PASS)
YumLighting l = GetYumLighting(i, pbr);
diff --git a/2ner.shader b/2ner.shader index ace35f9..bbb8fa3 100644 --- a/2ner.shader +++ b/2ner.shader @@ -1,7 +1,7 @@ Shader "yum_food/2ner" { - Properties - { + Properties + { [HideInInspector] shader_master_label("<color=#de719bff>2ner</color>", Float) = 0 [HideInInspector] shader_is_using_thry_editor("", Float) = 0 [HideInInspector] shader_presets("ThryPresetsExample", Float) = 0 @@ -33,9 +33,14 @@ Shader "yum_food/2ner" _MainTex("Base color", 2D) = "white" {} [PanningTexture][Normal]_BumpMap("Normals", 2D) = "bump" {} _BumpScale("Normal Intensity", Range(0, 10)) = 1 - _OcclusionMap("Ambient occlusion", 2D) = "white" {} - _OcclusionStrength("Ambient occlusion", Range(0,1)) = 1 _Clip("Alpha Cuttoff", Range(0, 1.001)) = 0.5 + //ifex _Ambient_Occlusion_Enabled==0 + [HideInInspector] m_start_AO("Ambient occlusion", Float) = 0 + [ThryToggle(_AMBIENT_OCCLUSION)]_Ambient_Occlusion_Enabled("Enable", Float) = 0 + _OcclusionMap("Ambient occlusion", 2D) = "white" {} + _OcclusionStrength("Ambient occlusion", Range(0,1)) = 1 + [HideInInspector] m_end_AO("Metallics", Float) = 0 + //endex [HideInInspector] m_reflectionOptions("Reflections", Float) = 0 [HideInInspector] m_start_Metallic("Metallics", Float) = 0 @@ -45,9 +50,9 @@ Shader "yum_food/2ner" [HideInInspector] m_end_Metallic("Metallics", Float) = 0 [HideInInspector] m_gimmicks("Gimmicks", Float) = 0 - //ifex _OutlinesEnabled==0 + //ifex _Outlines_Enabled==0 [HideInInspector] m_start_Outlines("Outlines", Float) = 0 - [ThryToggle(_)]_OutlinesEnabled("Enable", Float) = 0 + [ThryToggle(_OUTLINES)]_Outlines_Enabled("Enable", Float) = 0 _Outline_Color("Color", Color) = (0, 0, 0, 1) _Outline_Width("Width", Float) = 0.01 [HideInInspector] m_start_OutlinesMask("Mask", Float) = 0 @@ -56,6 +61,52 @@ Shader "yum_food/2ner" [HideInInspector] m_end_OutlinesMask("Mask", Float) = 0 [HideInInspector] m_end_Outlines("Outlines", Float) = 0 //endex + //ifex _Matcap0_Enabled==0 + [HideInInspector] m_start_Matcaps("Matcaps", Float) = 0 + [HideInInspector] m_start_Matcap0("Matcap 0", Float) = 0 + [ThryToggle(_MATCAP0)]_Matcap0_Enabled("Enable", Float) = 0 + _Matcap0("Matcap", 2D) = "white" {} + [Toggle(_)]_Matcap0_Invert("Invert", Float) = 0 + [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] + _Matcap0_Mode("Mode", Int) = 0 + _Matcap0_Strength("Strength", Float) = 1 + [HideInInspector] m_start_Matcap0_Mask("Mask", Float) = 0 + [ThryToggle(_MATCAP0_MASK)]_Matcap0_Mask_Enabled("Enable", Float) = 0 + _Matcap0_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Matcap0_Mask("Mask", Float) = 0 + [HideInInspector] m_end_Matcap0("Matcaps", Float) = 0 + [HideInInspector] m_end_Matcaps("Matcaps", Float) = 0 + //endex + //ifex _Rim_Lighting0_Enabled==0 + [HideInInspector] m_start_Rim_Lighting("Rim lighting", Float) = 0 + [HideInInspector] m_start_Rim_Lighting0("Rim lighting 0", Float) = 0 + [ThryToggle(_RIM_LIGHTING0)]_Rim_Lighting0_Enabled("Enable", Float) = 0 + _Rim_Lighting0_Center("Center", Range(0, 0.5)) = 0.5 + _Rim_Lighting0_Power("Power", Float) = 5 + _Rim_Lighting0_Color("Color", Color) = (1, 1, 1, 1) + _Rim_Lighting0_Brightness("Brightness", Float) = 1 + [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] + _Rim_Lighting0_Mode("Mode", Int) = 0 + [HideInInspector] m_start_Rim_Lighting0_Mask("Mask", Float) = 0 + [ThryToggle(_RIM_LIGHTING0_MASK)]_Rim_Lighting0_Mask_Enabled("Enable", Float) = 0 + _Rim_Lighting0_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Rim_Lighting0_Mask("Mask", Float) = 0 + [HideInInspector] m_end_Rim_Lighting0("Rim lighting", Float) = 0 + [HideInInspector] m_start_Rim_Lighting1("Rim lighting 1", Float) = 0 + [ThryToggle(_RIM_LIGHTING1)]_Rim_Lighting1_Enabled("Enable", Float) = 0 + _Rim_Lighting1_Center("Center", Range(0, 0.5)) = 0.5 + _Rim_Lighting1_Power("Power", Float) = 5 + _Rim_Lighting1_Color("Color", Color) = (1, 1, 1, 1) + _Rim_Lighting1_Brightness("Brightness", Float) = 1 + [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] + _Rim_Lighting1_Mode("Mode", Int) = 0 + [HideInInspector] m_start_Rim_Lighting1_Mask("Mask", Float) = 0 + [ThryToggle(_RIM_LIGHTINg1_MASK)]_Rim_Lighting1_Mask_Enabled("Enable", Float) = 0 + _Rim_Lighting1_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Rim_Lighting1_Mask("Mask", Float) = 0 + [HideInInspector] m_end_Rim_Lighting1("Rim lighting", Float) = 0 + [HideInInspector] m_end_Rim_Lighting("Rim lighting", Float) = 0 + //endex [HideInInspector] m_lightingOptions("Lighting Options", Float) = 0 //ifex _Receive_Shadows_Enabled==0 @@ -75,6 +126,12 @@ Shader "yum_food/2ner" _Wrap_NoL_Specular_Strength("Specular strength", Range(0, 1)) = 0.1 [HideInInspector] m_end_WrappedLighting("Wrapped lighting", Float) = 0 //endex + //ifex _Min_Brightness_Enabled==0 + [HideInInspector] m_start_Min_Brightness("Minimum brightness", Float) = 0 + [ThryToggle(_MIN_BRIGHTNESS)] _Min_Brightness_Enabled("Enable", Float) = 0 + _Min_Brightness("Value", Range(0, 1)) = 0 + [HideInInspector] m_end_Min_Brightness("Minimum brightness", Float) = 0 + //endex [HideInInspector] m_renderingOptions("Rendering Options", Float) = 0 [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Float) = 2 @@ -101,7 +158,7 @@ Shader "yum_food/2ner" [DoNotAnimate][Enum(UnityEngine.Rendering.BlendMode)] _AddDstBlendAlpha ("Alpha Destination Blend", Int) = 1 [DoNotAnimate][HideInInspector] m_end_alphaBlending ("Advanced Alpha Blending", Float) = 0 [HideInInspector] m_end_blending ("Blending", Float) = 0 - //ifex _OutlinesEnabled==0 + //ifex _Outlines_Enabled==0 // Outline Blending Options [HideInInspector] m_start_outlineBlending ("Outline Blending", Float) = 0 [Enum(Thry.BlendOp)]_OutlineBlendOp ("RGB Blend Op", Int) = 0 @@ -134,7 +191,7 @@ Shader "yum_food/2ner" Cull [_Cull] ZWrite [_ZWrite] ZTest [_ZTest] - + CGPROGRAM #pragma target 5.0 #pragma multi_compile_fwdbase @@ -157,7 +214,7 @@ Shader "yum_food/2ner" ZTest [_ZTest] BlendOp [_AddBlendOp], [_AddBlendOpAlpha] Blend [_AddSrcBlend] [_AddDstBlend], [_AddSrcBlendAlpha] [_AddDstBlendAlpha] - + CGPROGRAM #pragma target 5.0 #pragma multi_compile_fwdadd_fullshadows @@ -171,7 +228,7 @@ Shader "yum_food/2ner" #include "2ner.cginc" ENDCG } - //ifex _OutlinesEnabled==0 + //ifex _Outlines_Enabled==0 Pass { Name "OUTLINES" Name "FORWARD" @@ -181,7 +238,7 @@ Shader "yum_food/2ner" ZTest [_ZTest] BlendOp [_OutlineBlendOp], [_OutlineBlendOpAlpha] Blend [_OutlineSrcBlend] [_OutlineDstBlend], [_OutlineSrcBlendAlpha] [_OutlineDstBlendAlpha] - + CGPROGRAM #pragma target 5.0 #pragma multi_compile_fwdbase @@ -196,8 +253,6 @@ Shader "yum_food/2ner" ENDCG } //endex - // TODO I think this is unnecessary? I'm casting shadows just fine in - // testbed. Pass { Name "ShadowCaster" Tags { "LightMode" = "ShadowCaster" } diff --git a/features.cginc b/features.cginc index 5040db0..53f8c38 100644 --- a/features.cginc +++ b/features.cginc @@ -1,12 +1,38 @@ #ifndef __FEATURES_INC #define __FEATURES_INC +//ifex _Ambient_Occlusion_Enabled==0 +#pragma shader_feature_local _AMBIENT_OCCLUSION +//endex + //ifex _Wrapped_Lighting_Enabled==0 #pragma shader_feature_local _WRAPPED_LIGHTING //endex + +//ifex _Min_Brightness_Enabled==0 +#pragma shader_feature_local _MIN_BRIGHTNESS +//endex + +//ifex _Outlines_Enabled==0 +#pragma shader_feature_local _OUTLINES +//endex //ifex _Outline_Mask_Enabled==0 #pragma shader_feature_local _OUTLINE_MASK //endex +//ifex _Matcap0_Enabled==0 +#pragma shader_feature_local _MATCAP0 +#pragma shader_feature_local _MATCAP0_MASK +//endex + +//ifex _Rim_Lighting0_Enabled==0 +#pragma shader_feature_local _RIM_LIGHTING0 +#pragma shader_feature_local _RIM_LIGHTING0_MASK +//endex +//ifex _Rim_Lighting1_Enabled==0 +#pragma shader_feature_local _RIM_LIGHTING1 +#pragma shader_feature_local _RIM_LIGHTING1_MASK +//endex + #endif // __FEATURES_INC diff --git a/globals.cginc b/globals.cginc index 5ca95a8..948b69a 100644 --- a/globals.cginc +++ b/globals.cginc @@ -1,6 +1,8 @@ #ifndef __GLOBALS_INC
#define __GLOBALS_INC
+#include "features.cginc"
+
SamplerState linear_repeat_s;
sampler2D _MainTex;
@@ -8,18 +10,26 @@ float4 _MainTex_ST; fixed4 _Color;
sampler2D _BumpMap;
+float4 _BumpMap_ST;
half _BumpScale;
float _BumpShadowHeightScale;
float _BumpShadowHardness;
+#if defined(_AMBIENT_OCCLUSION)
sampler2D _OcclusionMap;
float _OcclusionStrength;
+#endif
float _Shadow_Strength;
-//ifex _Wrap_NoL_Strength>0
+
+#if defined(_WRAPPED_LIGHTING)
float _Wrap_NoL_Diffuse_Strength;
float _Wrap_NoL_Specular_Strength;
-//endex
+#endif
+
+#if defined(_MIN_BRIGHTNESS)
+float _Min_Brightness;
+#endif
float _Clip;
int _Mode;
@@ -39,4 +49,41 @@ texture2D _Outline_Mask; #endif
#endif
+#define MATCAP_MODE_REPLACE 0
+#define MATCAP_MODE_ADD 1
+#define MATCAP_MODE_MULTIPLY 2
+#define MATCAP_MODE_SUBTRACT 3
+#define MATCAP_MODE_ADD_PRODUCT 4
+
+#if defined(_MATCAP0)
+texture2D _Matcap0;
+uint _Matcap0_Mode;
+float _Matcap0_Invert;
+float _Matcap0_Strength;
+#if defined(_MATCAP0_MASK)
+texture2D _Matcap0_Mask;
+#endif
+#endif
+
+#if defined(_RIM_LIGHTING0)
+uint _Rim_Lighting0_Mode;
+float _Rim_Lighting0_Center;
+float _Rim_Lighting0_Power;
+float3 _Rim_Lighting0_Color;
+float _Rim_Lighting0_Brightness;
+#if defined(_RIM_LIGHTING0_MASK)
+texture2D _Rim_Lighting0_Mask;
+#endif
+#endif
+#if defined(_RIM_LIGHTING1)
+uint _Rim_Lighting1_Mode;
+float _Rim_Lighting1_Center;
+float _Rim_Lighting1_Power;
+float3 _Rim_Lighting1_Color;
+float _Rim_Lighting1_Brightness;
+#if defined(_RIM_LIGHTING1_MASK)
+texture2D _Rim_Lighting1_Mask;
+#endif
+#endif
+
#endif // __GLOBALS_INC
diff --git a/interpolators.cginc b/interpolators.cginc index 1b3abc5..c75b725 100644 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -21,7 +21,6 @@ struct v2f { float3 binormal : TEXCOORD4;
float4 eyeVec : TEXCOORD5; // eyeVec.xyz | fogCoord
UNITY_LIGHTING_COORDS(6,7)
- float3 lightDirTS : TEXCOORD8;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
diff --git a/matcaps.cginc b/matcaps.cginc new file mode 100644 index 0000000..555dcc7 --- /dev/null +++ b/matcaps.cginc @@ -0,0 +1,87 @@ +#ifndef __MATCAPS_INC +#define __MATCAPS_INC + +#include "features.cginc" +#include "globals.cginc" +#include "interpolators.cginc" +#include "yum_pbr.cginc" + +#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) +float2 getMatcapUV(v2f i, inout YumPbr pbr) { + const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(pbr.normal, 0))); + const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(-i.eyeVec.xyz, 0))); + const float3 cam_refl = -reflect(cam_view_dir, cam_normal); + float m = 2.0 * sqrt( + cam_refl.x * cam_refl.x + + cam_refl.y * cam_refl.y + + (cam_refl.z + 1) * (cam_refl.z + 1)); + return cam_refl.xy / m + 0.5; +} + +void applyMatcap(inout YumPbr pbr, float3 sample, uint mode, float mask) +{ + [forcecase] + switch(mode) { + case MATCAP_MODE_REPLACE: + pbr.albedo.rgb = lerp(pbr.albedo.rgb, sample, mask); + break; + case MATCAP_MODE_ADD: + pbr.albedo.rgb += lerp(0, sample, mask); + break; + case MATCAP_MODE_MULTIPLY: + pbr.albedo.rgb *= lerp(1, sample, mask); + break; + case MATCAP_MODE_SUBTRACT: + pbr.albedo.rgb -= lerp(0, sample, mask); + break; + case MATCAP_MODE_ADD_PRODUCT: + pbr.albedo.rgb += lerp(0, sample * pbr.albedo.rgb, mask); + break; + default: + break; + } +} +#endif + +void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { +#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) + float2 muv = getMatcapUV(i, pbr); +#endif +#if defined(_MATCAP0) + float3 m0 = _Matcap0.Sample(linear_repeat_s, muv); + m0 = lerp(m0, 1 - m0, _Matcap0_Invert); + m0 *= _Matcap0_Strength; +#if defined(_MATCAP0_MASK) + float m0_mask = _Matcap0_Mask.Sample(linear_repeat_s, i.uv01.xy); +#else + float m0_mask = 1; +#endif + applyMatcap(pbr, m0, _Matcap0_Mode, m0_mask); +#endif +#if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) + float rl_radius = length(muv - 0.5); +#endif +#if defined(_RIM_LIGHTING0) + float rl0_dist = exp2(-_Rim_Lighting0_Power * abs(rl_radius - _Rim_Lighting0_Center)); + float3 rl0 = _Rim_Lighting0_Color * _Rim_Lighting0_Brightness * rl0_dist; +#if defined(_RIM_LIGHTING0_MASK) + float rl0_mask = _Rim_Lighting0_Mask.Sample(linear_repeat_s, i.uv01.xy); +#else + float rl0_mask = 1; +#endif + applyMatcap(pbr, rl0, _Rim_Lighting0_Mode, rl0_mask); +#endif +#if defined(_RIM_LIGHTING1) + float rl1_dist = exp2(-_Rim_Lighting1_Power * abs(rl_radius - _Rim_Lighting1_Center)); + float3 rl1 = _Rim_Lighting1_Color * _Rim_Lighting1_Brightness * rl1_dist; +#if defined(_RIM_LIGHTING1_MASK) + float rl1_mask = _Rim_Lighting1_Mask.Sample(linear_repeat_s, i.uv01.xy); +#else + float rl1_mask = 1; +#endif + applyMatcap(pbr, rl1, _Rim_Lighting1_Mode, rl1_mask); +#endif +} + +#endif + diff --git a/texture_utils.cginc b/texture_utils.cginc new file mode 100644 index 0000000..4d02fbc --- /dev/null +++ b/texture_utils.cginc @@ -0,0 +1,24 @@ +#ifndef __TEXTURE_UTILS_INC +#define __TEXTURE_UTILS_INC + +#include "interpolators.cginc" + +float2 get_uv_by_channel(v2f i, uint which_channel) { + [forcecase] + switch (which_channel) { + case 0: + return i.uv01.xy; + break; + case 1: + return i.uv01.zw; + break; + default: + return 0; + break; + } +} + +#define UV_SCOFF(i, tex_st, which_channel) get_uv_by_channel(i, round(which_channel)) * (tex_st).xy + (tex_st).zw + +#endif // __TEXTURE_UTILS_INC + diff --git a/yum_lighting.cginc b/yum_lighting.cginc index 4022764..e34ec10 100644 --- a/yum_lighting.cginc +++ b/yum_lighting.cginc @@ -6,6 +6,7 @@ #include "UnityPBSLighting.cginc"
#include "UnityLightingCommon.cginc"
+#include "features.cginc"
#include "yum_pbr.cginc"
struct YumLighting {
@@ -42,9 +43,11 @@ float getShadowAttenuation(v2f i) #elif defined(SPOT)
DECLARE_LIGHT_COORD(i, i.worldPos);
float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos);
- attenuation = (lightCoord.z > 0) * UnitySpotCookie(lightCoord) * UnitySpotAttenuate(lightCoord.xyz);
+ attenuation = (lightCoord.z > 0) * UnitySpotCookie(lightCoord) *
+ UnitySpotAttenuate(lightCoord.xyz);
#elif defined(POINT)
- unityShadowCoord3 lightCoord = mul(unity_WorldToLight, unityShadowCoord4(i.worldPos, 1)).xyz;
+ unityShadowCoord3 lightCoord =
+ mul(unity_WorldToLight, unityShadowCoord4(i.worldPos, 1)).xyz;
float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos);
attenuation = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).r;
#else
@@ -86,7 +89,8 @@ float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir) { data.boxMin[1] = unity_SpecCube1_BoxMin;
data.probePosition[1] = unity_SpecCube1_ProbePosition;
#endif
- return UnityGI_prefilteredRadiance(data, pbr.roughness_perceptual, reflect_dir);
+ return UnityGI_prefilteredRadiance(data, pbr.roughness_perceptual,
+ reflect_dir);
}
float4 getIndirectDiffuse(v2f i, float4 vertexLightColor) {
@@ -122,6 +126,9 @@ YumLighting GetYumLighting(v2f i, YumPbr pbr) { //ifex _Spherical_Harmonics==1
light.diffuse = max(0, BetterSH9(float4(0, 0, 0, 1)));
//endex
+#if defined(_MIN_BRIGHTNESS)
+ light.diffuse = max(_Min_Brightness, light.diffuse);
+#endif
light.specular = getIndirectSpecular(i, pbr, light.view_dir);
diff --git a/yum_pbr.cginc b/yum_pbr.cginc index 8b4d8e3..93c615d 100644 --- a/yum_pbr.cginc +++ b/yum_pbr.cginc @@ -1,8 +1,10 @@ #ifndef __YUM_PBR #define __YUM_PBR +#include "features.cginc" #include "filamented.cginc" #include "globals.cginc" +#include "texture_utils.cginc" struct YumPbr { float4 albedo; @@ -19,12 +21,16 @@ YumPbr GetYumPbr(v2f i) { #if defined(OUTLINE_PASS) result.albedo = _Outline_Color; - result.albedo.a *= tex2D(_MainTex, i.uv01).a; + result.albedo.a *= tex2D(_MainTex, + UV_SCOFF(i, _MainTex_ST, /*which_channel=*/0)).a; #else - result.albedo = tex2D(_MainTex, i.uv01) * _Color; + result.albedo = tex2D(_MainTex, + UV_SCOFF(i, _MainTex_ST, /*which_channel=*/0)) * _Color; #endif - float3 normal_raw = UnpackScaleNormal(tex2D(_BumpMap, i.uv01), _BumpScale); + float3 normal_raw = UnpackScaleNormal( + tex2D(_BumpMap, UV_SCOFF(i, _BumpMap_ST, /*which_channel=*/0)), + _BumpScale); float3x3 tangentToWorld = float3x3(i.tangent, i.binormal, i.normal); result.normal = normalize(mul(normal_raw, tangentToWorld)); @@ -35,7 +41,11 @@ YumPbr GetYumPbr(v2f i) { result.metallic = _Metallic; +#if defined(_AMBIENT_OCCLUSION) result.ao = lerp(1, tex2D(_OcclusionMap, i.uv01), _OcclusionStrength); +#else + result.ao = 1; +#endif return result; } |
