diff options
| -rw-r--r-- | Editor/tooner.cs | 12 | ||||
| -rw-r--r-- | globals.cginc | 1 | ||||
| -rw-r--r-- | interpolators.cginc | 12 | ||||
| -rw-r--r-- | pbr.cginc | 69 | ||||
| -rw-r--r-- | tooner.shader | 1 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 4 | ||||
| -rw-r--r-- | tooner_outline_pass.cginc | 2 |
7 files changed, 24 insertions, 77 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index c4c2f5a..869d912 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -2055,15 +2055,6 @@ public class ToonerGUI : ShaderGUI { MaterialProperty bc; - bc = FindProperty("_Enable_World_Interpolators"); - bool world_interp = bc.floatValue > 1E-6; - EditorGUI.BeginChangeCheck(); - world_interp = EditorGUILayout.Toggle("World interpolators", - world_interp); - EditorGUI.EndChangeCheck(); - bc.floatValue = world_interp ? 1.0f : 0.0f; - SetKeyword("_WORLD_INTERPOLATORS", world_interp); - bc = FindProperty("_Enable_Brightness_Clamp"); bool brightness_clamp_enabled = bc.floatValue > 1E-6; EditorGUI.BeginChangeCheck(); @@ -2091,6 +2082,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bc, "Ambient occlusion"), bc); SetKeyword("_AMBIENT_OCCLUSION", bc.textureValue); + if (bc.textureValue) { + editor.TextureScaleOffsetProperty(bc); + } if (bc.textureValue) { bc = FindProperty("_Ambient_Occlusion_Strength"); diff --git a/globals.cginc b/globals.cginc index 25cd343..832d2cd 100644 --- a/globals.cginc +++ b/globals.cginc @@ -285,6 +285,7 @@ float _Global_Emission_Factor; #if defined(_AMBIENT_OCCLUSION) texture2D _Ambient_Occlusion; +float4 _Ambient_Occlusion_ST; float _Ambient_Occlusion_Strength; #endif diff --git a/interpolators.cginc b/interpolators.cginc index 09fd14c..ce0058a 100644 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -12,15 +12,11 @@ struct appdata float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; -#if defined(_WORLD_INTERPOLATORS) - UNITY_LIGHTING_COORDS(3, 4) -#else float2 uv3 : TEXCOORD3; float2 uv4 : TEXCOORD4; float2 uv5 : TEXCOORD5; float2 uv6 : TEXCOORD6; float2 uv7 : TEXCOORD7; -#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -31,7 +27,7 @@ struct v2f float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; -#if defined(_WORLD_INTERPOLATORS) +#if defined(LIGHTMAP_ON) UNITY_LIGHTING_COORDS(3, 4) #else float2 uv3 : TEXCOORD3; @@ -58,15 +54,11 @@ struct appdata float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; -#if defined(_WORLD_INTERPOLATORS) - UNITY_LIGHTING_COORDS(3, 4) -#else float2 uv3 : TEXCOORD3; float2 uv4 : TEXCOORD4; float2 uv5 : TEXCOORD5; float2 uv6 : TEXCOORD6; float2 uv7 : TEXCOORD7; -#endif float3 normal : NORMAL; float4 tangent : TANGENT; @@ -79,7 +71,7 @@ struct v2f float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; -#if defined(_WORLD_INTERPOLATORS) +#if defined(LIGHTMAP_ON) UNITY_LIGHTING_COORDS(3, 4) #else float2 uv3 : TEXCOORD3; @@ -82,43 +82,6 @@ float3 getDirectLightColor() return _LightColor0.rgb; } -#if defined(_WORLD_INTERPOLATORS) -UnityGI getBakedGI(v2f i, float3 view_dir, - UnityLight direct_light, float atten, float ao, float3 normal, - float smoothness, float3 specular_tint) { - UnityGIInput d; - d.light = direct_light; - d.worldPos = i.worldPos; - d.worldViewDir = view_dir; - d.atten = atten; - - d.ambient = 0; - d.lightmapUV.xy = i.uv2; - d.lightmapUV.zw = 0; - - d.probeHDR[0] = unity_SpecCube0_HDR; - d.probeHDR[1] = unity_SpecCube1_HDR; -#if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) - d.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending -#endif -#ifdef UNITY_SPECCUBE_BOX_PROJECTION - d.boxMax[0] = unity_SpecCube0_BoxMax; - d.probePosition[0] = unity_SpecCube0_ProbePosition; - d.boxMax[1] = unity_SpecCube1_BoxMax; - d.boxMin[1] = unity_SpecCube1_BoxMin; - d.probePosition[1] = unity_SpecCube1_ProbePosition; -#endif - - Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup(smoothness, -view_dir, normal, specular_tint); - // Replace the reflUVW if it has been compute in Vertex shader. Note: the compiler will optimize the calcul in UnityG lossyEnvironmentSetup itself -#if UNITY_STANDARD_SIMPLE - g.reflUVW = reflUVW; -#endif - - return UnityGlobalIllumination (d, ao, normal, g); -} -#endif // _WORLD_INTERPOLATORS - float GetRoughness(float smoothness) { float r = 1 - smoothness; r *= 1.7 - 0.7 * r; @@ -130,27 +93,34 @@ float3 BoxProjection ( float4 cubemapPosition, float3 boxMin, float3 boxMax ) { #if UNITY_SPECCUBE_BOX_PROJECTION + UNITY_BRANCH if (cubemapPosition.w > 0) { float3 factors = ((direction > 0 ? boxMax : boxMin) - position) / direction; float scalar = min(min(factors.x, factors.y), factors.z); - direction = direction * scalar + (position - cubemapPosition.xyz); + direction = direction * scalar + (position - cubemapPosition); } #endif return direction; } -float4 getIndirectDiffuse(float4 vertexLightColor, float3 normal) { +float4 getIndirectDiffuse(v2f i, float4 vertexLightColor, float3 normal) { float4 diffuse = vertexLightColor; +#if defined(FORWARD_BASE_PASS) +#if defined(LIGHTMAP_ON) + diffuse.xyz = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv2)); +#else if (_Mesh_Normals_Mode == 3) { // Toon diffuse.xyz += max(0, BetterSH9(float4(0, 0, 0, 1))); } else { diffuse.xyz += max(0, BetterSH9(float4(normal, 1))); } +#endif +#endif return diffuse; } -float3 getIndirectSpecular(float3 view_dir, float3 normal, +float3 getIndirectSpecular(v2f i, float3 view_dir, float3 normal, float smoothness, float metallic, float3 worldPos, float2 uv) { float3 specular = 0; @@ -167,7 +137,6 @@ float3 getIndirectSpecular(float3 view_dir, float3 normal, UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, env_data ); specular = probe0; -#if UNITY_SPECCUBE_BLENDING if (unity_SpecCube0_BoxMin.w < 0.99999) { env_data.reflUVW = BoxProjection( reflect_dir, worldPos, @@ -178,8 +147,7 @@ float3 getIndirectSpecular(float3 view_dir, float3 normal, unity_SpecCube1_HDR, env_data ); specular = lerp(probe1, probe0, unity_SpecCube0_BoxMin.w); - } -#endif // UNITY_SPECCUBE_BLENDING + } #if defined(_CUBEMAP) #if 0 @@ -256,7 +224,7 @@ float4 getLitColor( vertexLightColor *= _Vertex_Lighting_Factor; -#if defined(_WORLD_INTERPOLATORS) +#if defined(LIGHTMAP_ON) UNITY_LIGHT_ATTENUATION(shadow_attenuation, i, i.worldPos); #else float shadow_attenuation = getShadowAttenuation(i); @@ -266,14 +234,6 @@ float4 getLitColor( direct_light.dir = getDirectLightDirection(i); direct_light.ndotl = DotClamped(normal, direct_light.dir); direct_light.color = 0; -#if defined(_WORLD_INTERPOLATORS) - { - UnityGI gi = getBakedGI(i, view_dir, direct_light, shadow_attenuation, ao, - normal, smoothness, specular_tint); - direct_light = gi.light; - indirect_light = gi.indirect; - } -#else { direct_light.dir = getDirectLightDirection(i); direct_light.ndotl = DotClamped(normal, direct_light.dir); @@ -283,11 +243,10 @@ float4 getLitColor( #else direct_light.color = getDirectLightColor(); #endif - indirect_light.diffuse = getIndirectDiffuse(vertexLightColor, normal); - indirect_light.specular = getIndirectSpecular(view_dir, normal, smoothness, + indirect_light.diffuse = getIndirectDiffuse(i, vertexLightColor, normal); + indirect_light.specular = getIndirectSpecular(i, view_dir, normal, smoothness, metallic, worldPos, uv); } -#endif // _WORLD_INTERPOLATORS if (normals_mode == 0) { float e = 0.8; diff --git a/tooner.shader b/tooner.shader index 645a3db..335f050 100644 --- a/tooner.shader +++ b/tooner.shader @@ -179,7 +179,6 @@ Shader "yum_food/tooner" _Indirect_Specular_Lighting_Factor2("Indirect specular lighting factor", Range(0, 5)) = 1 _Indirect_Diffuse_Lighting_Factor("Indirect diffuse lighting factor", Range(0, 5)) = 1 _Reflection_Probe_Saturation("Reflection probe saturation", Range(0, 1)) = 1 - _Enable_World_Interpolators("Enable world interpolators", Float) = 0 _Enable_Brightness_Clamp("Enable brightness clamp", Float) = 1 _Min_Brightness("Min brightness", Range(0, 1)) = 0 _Max_Brightness("Max brightness", Range(0, 1.5)) = 1 diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 19063f3..eec82af 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -2107,7 +2107,9 @@ float4 effect(inout v2f i) #endif #if defined(_AMBIENT_OCCLUSION) - float ao = _Ambient_Occlusion.SampleBias(linear_repeat_s, i.uv0, _Global_Sample_Bias); + float ao = _Ambient_Occlusion.SampleBias(linear_repeat_s, + UV_SCOFF(i, _Ambient_Occlusion_ST, /*uv_channel=*/0), + _Global_Sample_Bias); ao = 1 - (1 - ao) * _Ambient_Occlusion_Strength; #else float ao = 1; diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc index d8be2a7..9444c84 100644 --- a/tooner_outline_pass.cginc +++ b/tooner_outline_pass.cginc @@ -81,7 +81,7 @@ v2f vert(appdata v) o.normal = UnityObjectToWorldNormal(v.normal); o.uv0 = v.uv0; o.uv1 = v.uv1; -#if defined(_WORLD_INTERPOLATORS) +#if defined(LIGHTMAP_ON) o.uv2 = v.uv2 * unity_LightmapST.xy + unity_LightmapST.zw; UNITY_TRANSFER_LIGHTING(o, v.uv1); #else |
