|
148 | 148 | // uniform float _Occlusion_Rim;
|
149 | 149 | // uniform float _Occlusion_MatAdd;
|
150 | 150 | uniform int _ToonRampLightSourceType_Backwards;
|
| 151 | + uniform half _diffuseIndirectDirectSimMix; |
151 | 152 | uniform int _UseSpecularSystem;
|
152 | 153 | uniform float3 _backFaceColorTint;
|
153 | 154 | uniform float4 _SpecularMaskHSV;
|
154 | 155 | uniform int _forceLightClamp;
|
155 | 156 | uniform float _rimAlbedoMix;
|
156 | 157 | uniform float _directLightIntensity;
|
| 158 | + uniform half _McDiffAlbedoMix; |
| 159 | + uniform half _indirectAlbedoMaxAveScale; |
| 160 | + uniform half _indirectGIDirectionalMix; |
| 161 | + uniform half _indirectGIBlur; |
| 162 | + uniform half _emissiveUseMainTexA; |
| 163 | + uniform half _emissiveUseMainTexCol; |
157 | 164 |
|
158 | 165 |
|
159 | 166 |
|
|
576 | 583 | float dynamicShadowMask = _DynamicShadowMask.SampleGrad(sampler_MainTex_trilinear_repeat, uv_toon.uv, uv_toon.dx, uv_toon.dy).g;
|
577 | 584 | float tmp = max(_shadowCastMin_black, dynamicShadowMask);
|
578 | 585 | shadowBlackness = saturate( (shadowAttenuation + tmp)/(1 - tmp));
|
579 |
| - shadowMinPotential = saturate( (_LightShadowData.x + tmp)/(1 - tmp)); |
| 586 | + // shadowMinPotential = saturate( (_LightShadowData.x + tmp)/(1 - tmp)); |
580 | 587 | } else
|
581 | 588 | {
|
582 | 589 | shadowBlackness = shadowAttenuation;
|
|
587 | 594 |
|
588 | 595 | //// collect scene light sources
|
589 | 596 | #ifdef UNITY_PASS_FORWARDBASE
|
| 597 | + //// build indirect light source |
590 | 598 | float3 lightIndirectColAve = DecodeLightProbe_average(); //// average light from raw L0
|
591 |
| - float3 lightIndirectMaxCol = SHEvalDirectL1(float4(i.dirGI,1)); //// direct most light raw L1 |
592 |
| - float3 lightIndirectAngCol = shadeSH9LinearAndWhole(float4(i.wNormal,1)); //// All GI from direction and fixed for no negatives |
593 |
| - // float scaleGIL0L1 = saturate(LinearRgbToLuminance_ac(lightIndirectMaxCol) / (LinearRgbToLuminance_ac(lightIndirectColAve) + 0.00001) * .9); |
594 |
| - float scaleGIL0L1 = saturate(LinearRgbToLuminance_ac(lightIndirectMaxCol) - (LinearRgbToLuminance_ac(lightIndirectColAve)).xxx + 0.00001) * 1; |
595 |
| - float3 lightIndirectCol = lerp(lightIndirectMaxCol, lightIndirectColAve, scaleGIL0L1); |
596 |
| - //// build direct light sources |
597 |
| - float3 lightDirect = _LightColor0.rgb; |
598 |
| - float3 lightDirectSave = lightDirect; |
| 599 | + float3 lightIndirectColMax = SHEvalDirectL1(float4(i.dirGI,1)); //// direct most light raw L1 |
| 600 | + float3 lightIndirectColStatic = 0, lightIndirectColDir = 0; |
| 601 | + if ((_indirectGIDirectionalMix) < 1) |
| 602 | + { |
| 603 | + half GI_Max = LinearRgbToLuminance_ac(lightIndirectColMax), GI_Ave = LinearRgbToLuminance_ac(lightIndirectColAve); |
| 604 | + half GI_MaxAveDif = ((GI_Max * _indirectAlbedoMaxAveScale) - GI_Ave); |
| 605 | + half GI_MaxAveSum = GI_Max + GI_Ave; |
| 606 | + half GI_MaxAveRatio = saturate(GI_MaxAveDif / GI_MaxAveSum); |
| 607 | + lightIndirectColStatic = lerp(lightIndirectColMax, lightIndirectColAve, GI_MaxAveRatio); |
| 608 | + } |
| 609 | + if (_indirectGIDirectionalMix > 0) |
| 610 | + { |
| 611 | + float4 indirectGIDirectionBlur = float4(i.wNormal, (_indirectGIBlur + 0.001) ); |
| 612 | + lightIndirectColDir = max(0, ShadeSH9_ac(indirectGIDirectionBlur)) / (indirectGIDirectionBlur.w); |
| 613 | + // float3 lightIndirectColAngle = shadeSH9LinearAndWhole(float4(i.wNormal,1)); //// not blur adaptiable without intense math |
| 614 | + } |
| 615 | + float3 lightIndirectCol = lerp(lightIndirectColStatic, lightIndirectColDir, _indirectGIDirectionalMix); |
| 616 | + //// build direct light source |
| 617 | + float3 lightDirect = _LightColor0.rgb; |
| 618 | + float3 lightDirectSave = lightDirect; |
599 | 619 | //// build ambient LUM for reflection types
|
600 | 620 | float lightAverageLum = LinearRgbToLuminance_ac((lightDirectSave * _LightShadowData.x * .5) + lightDirectSave + (lightIndirectCol)) * .34;
|
601 | 621 | float3 vertexLit = i.vertexLighting;
|
602 | 622 | //// out light source by types
|
603 |
| - float3 lightDirectSource = (mixColorsMaxAve(lightIndirectMaxCol, lightDirect) + vertexLit) * _directLightIntensity; |
604 |
| - float3 lightIndirectSource = lightIndirectCol + vertexLit; |
| 623 | + float3 lightDirectSource = (mixColorsMaxAve(lightIndirectColMax, lightDirect) + vertexLit) * _directLightIntensity; |
| 624 | + float3 lightIndirectSource = (lightIndirectCol + vertexLit); |
605 | 625 | #elif UNITY_PASS_FORWARDADD
|
606 | 626 | float3 lightIndirectColAve = 0;
|
607 |
| - float3 lightIndirectAngCol = 0; |
| 627 | + float3 lightIndirectColAngle = 0; |
608 | 628 | float3 lightDirect = _LightColor0.rgb;
|
609 | 629 | float3 lightDirectSave = lightDirect;
|
610 | 630 | lightDirect *= lightAtten;
|
|
689 | 709 | if (_ToonRampLightSourceType_Backwards > 0) //// diffuse lighting: backface ramp is part of shadow
|
690 | 710 | {
|
691 | 711 | float n2ShadowMask = 1 - min((1-shadeRamp_n2), shadowBlackness);
|
692 |
| - shadeRamp_n2 = n2ShadowMask; |
| 712 | + shadeRamp_n2 = n2ShadowMask; //// make Backward Area be forced Dynamic shadow from its wrap |
693 | 713 | float3 lightDirectSim = (lightDirectSource * shadowBlackness) + lightIndirectSource;
|
694 | 714 | shadeCol_1 *= lightDirectSim;
|
695 | 715 | shadeCol_2 *= lightDirectSim;
|
696 |
| - shadeCol_3 *= lightIndirectSource; |
697 |
| - // shadeCol_3 *= (lightDirectSource * max(shadowMinPotential, _LightShadowData.x)) + lightIndirectSource; |
| 716 | + shadeCol_3 *= lerp(lightIndirectSource, lightDirectSim, _diffuseIndirectDirectSimMix); |
698 | 717 | } else //// diffuse lighting: shadow is independent of ramp
|
699 | 718 | {
|
700 | 719 | float3 lightDirectSim = (lightDirectSource * shadowBlackness) + lightIndirectSource;
|
|
941 | 960 | #ifdef UNITY_PASS_FORWARDBASE
|
942 | 961 | float4 emissiveMask = _Emissive_Tex.Sample( sampler_EmissionColorTex_trilinear_repeat, TRANSFORM_TEX( i.uv, _Emissive_Tex));
|
943 | 962 | float4 emissionTex = _EmissionColorTex.Sample( sampler_EmissionColorTex_trilinear_repeat, TRANSFORM_TEX( i.uv, _EmissionColorTex));
|
| 963 | + if (_emissiveUseMainTexA) //// because i know games that store emission mask in main texture alpha channel |
| 964 | + { |
| 965 | + emissiveMask.g = mainTex.a; |
| 966 | + } |
| 967 | + if (_emissiveUseMainTexCol) //// and color from main texture |
| 968 | + { |
| 969 | + emissionTex.rgba = mainTex.rgba; |
| 970 | + } |
944 | 971 | float3 emissionColor = max( (_EmissiveProportional_Color * lightAverageLum), _Emissive_Color.rgb);
|
945 | 972 | float3 emissionMixReal = emissionTex.rgb * emissionColor * emissionTex.a;
|
946 | 973 | float3 emissionMix = emissionMixReal;
|
|
970 | 997 | {
|
971 | 998 | float3 lightDirectSim = (shadowBlackness * lightDirectSource) + lightIndirectSource;
|
972 | 999 | // float3 lightDirectSim = (shadowBlackness * lightDirectSource) + lightIndirectSource;
|
973 |
| - colDiffuse = lerp(colDiffuse, (colDiffuse + (lightDirectSim * mcMixMult.rgb * _MatCapColMult.rgb * _MatCapColMult.a)), matcapMask); |
| 1000 | + float3 diffMixMC = 1; |
| 1001 | + if (_McDiffAlbedoMix) |
| 1002 | + { |
| 1003 | + diffMixMC = lerp(1, colDiffuse, _McDiffAlbedoMix); |
| 1004 | + } |
| 1005 | + colDiffuse = lerp(colDiffuse, (colDiffuse + (diffMixMC * (lightDirectSim * mcMixMult.rgb * _MatCapColMult.rgb * _MatCapColMult.a))), matcapMask); |
974 | 1006 | }
|
975 | 1007 | }
|
976 | 1008 |
|
|
0 commit comments