-
Notifications
You must be signed in to change notification settings - Fork 203
[DONOTMERGE] Key Optimizations Applied: #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sindharta
wants to merge
1
commit into
master
Choose a base branch
from
opt-claude
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -170,10 +170,28 @@ void fragDoubleShadeFeather( | |||||
| _1st_ShadeMap_var, _Use_1stAs2nd); | ||||||
| float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb), | ||||||
| ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade); | ||||||
| float _HalfLambert_var = 0.5 * dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5; | ||||||
|
|
||||||
| float4 _Set_2nd_ShadePosition_var = tex2D(_Set_2nd_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition)); | ||||||
| float4 _Set_1st_ShadePosition_var = tex2D(_Set_1st_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition)); | ||||||
| // === OPTIMIZATION: Cache blended normal for shading === | ||||||
| float3 shadingNormal = lerp(i.normalDir, normalDirection, _Is_NormalMapToBase); | ||||||
| float _HalfLambert_var = dot(shadingNormal, lightDirection) * 0.5 + 0.5; | ||||||
|
|
||||||
| // === OPTIMIZATION: Pre-calculate UV transforms to avoid redundant TRANSFORM_TEX calls === | ||||||
| float2 uv_1st_ShadePos = TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition); | ||||||
| float2 uv_2nd_ShadePos = TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition); | ||||||
| float2 uv_HighColorMask = TRANSFORM_TEX(Set_UV0, _Set_HighColorMask); | ||||||
| float2 uv_HighColorTex = TRANSFORM_TEX(Set_UV0, _HighColor_Tex); | ||||||
|
|
||||||
| // === OPTIMIZATION: Sample textures ONCE (reused in additional lights loop) === | ||||||
| float4 _Set_2nd_ShadePosition_var = tex2D(_Set_2nd_ShadePosition, uv_2nd_ShadePos); | ||||||
| float4 _Set_1st_ShadePosition_var = tex2D(_Set_1st_ShadePosition, uv_1st_ShadePos); | ||||||
| float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, uv_HighColorMask); | ||||||
| float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, uv_HighColorTex); | ||||||
|
|
||||||
| // === OPTIMIZATION: Pre-calculate expensive math operations (exp2/pow) === | ||||||
| float highColorExp = exp2(lerp(11, 1, _HighColor_Power)); | ||||||
| float highColorPowThreshold = 1.0 - pow(abs(_HighColor_Power), 5); | ||||||
| float rimLightExp = exp2(lerp(3, 0, _RimLight_Power)); | ||||||
| float apRimLightExp = exp2(lerp(3, 0, _Ap_RimLight_Power)); | ||||||
| //v.2.0.6 | ||||||
| //Minmimum value is same as the Minimum Feather's value with the Minimum Step's value as threshold. | ||||||
| float _SystemShadowsLevel_var = (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel > 0.001 | ||||||
|
|
@@ -191,15 +209,13 @@ void fragDoubleShadeFeather( | |||||
| _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - | ||||||
| _1st2nd_Shades_Feather))))), Set_FinalShadowMask); // Final Color | ||||||
|
|
||||||
| float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); | ||||||
|
|
||||||
| // === OPTIMIZATION: Use cached texture samples (already sampled above) === | ||||||
| float _Specular_var = 0.5 * dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; | ||||||
| // Specular | ||||||
| // === OPTIMIZATION: Use pre-calculated exp2 and pow values === | ||||||
| float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp( | ||||||
| (1.0 - step(_Specular_var, (1.0 - pow(abs(_HighColor_Power), 5)))), | ||||||
| pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor)); | ||||||
|
|
||||||
| float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); | ||||||
| (1.0 - step(_Specular_var, highColorPowThreshold)), | ||||||
| pow(abs(_Specular_var), highColorExp), _Is_SpecularToHighColor)); | ||||||
|
|
||||||
| float3 _HighColor_var = (lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), | ||||||
| ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), | ||||||
|
|
@@ -215,7 +231,8 @@ void fragDoubleShadeFeather( | |||||
| float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), | ||||||
| _Is_LightColor_RimLight); | ||||||
| float _RimArea_var = abs(1.0 - dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToRimLight), viewDirection)); | ||||||
| float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power))); | ||||||
| // === OPTIMIZATION: Use pre-calculated exp2 values === | ||||||
| float _RimLightPower_var = pow(_RimArea_var, rimLightExp); | ||||||
| float _Rimlight_InsideMask_var = saturate(lerp( | ||||||
| (0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), | ||||||
| step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff)); | ||||||
|
|
@@ -224,7 +241,8 @@ void fragDoubleShadeFeather( | |||||
| (_Is_LightColor_RimLight_var * saturate( | ||||||
| (_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), | ||||||
| _LightDirection_MaskOn); | ||||||
| float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power))); | ||||||
| // === OPTIMIZATION: Use pre-calculated exp2 values === | ||||||
| float _ApRimLightPower_var = pow(_RimArea_var, apRimLightExp); | ||||||
| float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp( | ||||||
| _LightDirection_MaskOn_var, | ||||||
| (_LightDirection_MaskOn_var + ( | ||||||
|
|
@@ -247,19 +265,14 @@ void fragDoubleShadeFeather( | |||||
| float3 _Up_Unit = float3(0, 1, 0); | ||||||
| float3 _Right_Axis = cross(_Camera_Front, _Up_Unit); | ||||||
| //Invert if it's "inside the mirror". | ||||||
| if (_sign_Mirror < 0) | ||||||
| { | ||||||
| _Right_Axis = -1 * _Right_Axis; | ||||||
| _Rotate_MatCapUV = -1 * _Rotate_MatCapUV; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| _Right_Axis = _Right_Axis; | ||||||
| } | ||||||
| float _Camera_Right_Magnitude = sqrt( | ||||||
| _Camera_Right.x * _Camera_Right.x + _Camera_Right.y * _Camera_Right.y + _Camera_Right.z * _Camera_Right.z); | ||||||
| float _Right_Axis_Magnitude = sqrt( | ||||||
| _Right_Axis.x * _Right_Axis.x + _Right_Axis.y * _Right_Axis.y + _Right_Axis.z * _Right_Axis.z); | ||||||
| // === OPTIMIZATION: Branchless mirror handling === | ||||||
| float mirrorSign = _sign_Mirror < 0 ? -1.0 : 1.0; | ||||||
| _Right_Axis *= mirrorSign; | ||||||
| _Rotate_MatCapUV *= mirrorSign; | ||||||
|
|
||||||
| // === OPTIMIZATION: Use hardware-optimized length() intrinsic instead of manual sqrt === | ||||||
| float _Camera_Right_Magnitude = length(_Camera_Right); | ||||||
| float _Right_Axis_Magnitude = length(_Right_Axis); | ||||||
| float _Camera_Roll_Cos = dot(_Right_Axis, _Camera_Right) / (_Right_Axis_Magnitude * _Camera_Right_Magnitude); | ||||||
| float _Camera_Roll = acos(clamp(_Camera_Roll_Cos, -1, 1)); | ||||||
| fixed _Camera_Dir = _Camera_Right.y < 0 ? -1 : 1; | ||||||
|
|
@@ -285,14 +298,8 @@ void fragDoubleShadeFeather( | |||||
| (0.0 + ((_ViewNormalAsMatCapUV - (0.0 + _Tweak_MatCapUV)) * (1.0 - 0.0)) / ((1.0 - _Tweak_MatCapUV) - (0.0 + | ||||||
| _Tweak_MatCapUV))), _Rot_MatCapUV_var_ang, float2(0.5, 0.5), 1.0); | ||||||
| //If it is "inside the mirror", flip the UV left and right. | ||||||
| if (_sign_Mirror < 0) | ||||||
| { | ||||||
| _Rot_MatCapUV_var.x = 1 - _Rot_MatCapUV_var.x; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| _Rot_MatCapUV_var = _Rot_MatCapUV_var; | ||||||
| } | ||||||
| // === OPTIMIZATION: Branchless mirror UV flip === | ||||||
| _Rot_MatCapUV_var.x = _sign_Mirror < 0 ? (1.0 - _Rot_MatCapUV_var.x) : _Rot_MatCapUV_var.x; | ||||||
|
|
||||||
|
|
||||||
| float4 _MatCap_Sampler_var = tex2Dlod(_MatCap_Sampler, | ||||||
|
|
@@ -391,10 +398,10 @@ void fragDoubleShadeFeather( | |||||
| _1st_ShadeMap_var, _Use_1stAs2nd); | ||||||
| float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb * _LightIntensity), | ||||||
| ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade); | ||||||
| float _HalfLambert_var = 0.5 * dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5; | ||||||
| // === OPTIMIZATION: Use cached shadingNormal === | ||||||
| float _HalfLambert_var = dot(shadingNormal, lightDirection) * 0.5 + 0.5; | ||||||
|
|
||||||
| float4 _Set_2nd_ShadePosition_var = tex2D(_Set_2nd_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition)); | ||||||
| float4 _Set_1st_ShadePosition_var = tex2D(_Set_1st_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition)); | ||||||
| // === OPTIMIZATION: Use cached texture samples from main pass (no re-sampling needed) === | ||||||
|
|
||||||
| //v.2.0.5: | ||||||
| float Set_FinalShadowMask = saturate( | ||||||
|
|
@@ -410,17 +417,13 @@ void fragDoubleShadeFeather( | |||||
| Set_FinalShadowMask); // Final Color | ||||||
|
|
||||||
| //v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False | ||||||
|
|
||||||
|
|
||||||
| float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); | ||||||
| // === OPTIMIZATION: Use cached texture samples and pre-calculated values === | ||||||
|
|
||||||
| float _Specular_var = 0.5 * dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; | ||||||
| // Specular | ||||||
| float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp( | ||||||
| (1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), | ||||||
| pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor)); | ||||||
|
|
||||||
| float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); | ||||||
| (1.0 - step(_Specular_var, highColorPowThreshold)), | ||||||
| pow(_Specular_var, highColorExp), _Is_SpecularToHighColor)); | ||||||
|
||||||
| pow(_Specular_var, highColorExp), _Is_SpecularToHighColor)); | |
| pow(abs(_Specular_var), highColorExp), _Is_SpecularToHighColor)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'mirrorSign' is ambiguous. Consider renaming it to 'mirrorMultiplier' or 'mirrorFlipSign' to better convey that it's used as a multiplication factor for mirroring.