Skip to content

opt: reduce duplicate albedo calculations in URP#718

Merged
sindharta merged 14 commits intomasterfrom
refactor-urp-function
Jan 23, 2026
Merged

opt: reduce duplicate albedo calculations in URP#718
sindharta merged 14 commits intomasterfrom
refactor-urp-function

Conversation

@sindharta
Copy link
Collaborator

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors shader code to eliminate redundant calculations by introducing intermediate variables for commonly reused color computations. The changes improve code readability and maintainability by extracting repeated albedo calculations (_BaseColor * mainTex, _1st_ShadeColor * firstShadeTex, _2nd_ShadeColor * secondShadeTex) into named variables.

Changes:

  • Introduced baseAlbedo, firstShadeAlbedo, and secondShadeAlbedo variables to store pre-calculated color values
  • Replaced all instances of redundant inline calculations with references to these new variables
  • Removed an outdated comment

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
UniversalToonBodyShadingGradeMap.hlsl Introduces albedo variables at the top of the fragment shader and refactors color calculations across forward base and additional light passes to use these variables
UniversalToonBodyDoubleShadeWithFeather.hlsl Introduces albedo variables within the forward base pass and refactors color calculations across all lighting passes to use these variables

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const float3 baseAlbedo = _BaseColor.rgb * mainTex.rgb;
const float4 firstShadeTex = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_MainTex, mainTexUV),mainTex, _Use_BaseAs1st);
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * firstShadeTex.rgb),((_1st_ShadeColor.rgb * firstShadeTex.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
const float3 firstShadeAlbedo = _1st_ShadeColor.rgb * firstShadeTex.rgb;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace should be removed from the end of this line.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +147 to +151
const float3 baseAlbedo = _BaseColor.rgb * mainTex.rgb;
const float4 firstShadeTex = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_MainTex, mainTexUV),mainTex, _Use_BaseAs1st);
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * firstShadeTex.rgb),((_1st_ShadeColor.rgb * firstShadeTex.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
const float3 firstShadeAlbedo = _1st_ShadeColor.rgb * firstShadeTex.rgb;
const float4 secondShadeTex = lerp(SAMPLE_TEXTURE2D(_2nd_ShadeMap, sampler_MainTex, mainTexUV),firstShadeTex, _Use_1stAs2nd);
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * secondShadeTex.rgb),((_2nd_ShadeColor.rgb * secondShadeTex.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
const float3 secondShadeAlbedo = _2nd_ShadeColor.rgb * secondShadeTex.rgb;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The albedo variables are declared within the _IS_PASS_FWDBASE block but are used in other code paths (lines 363, 365-366, 455, 457-458). These variables should be moved outside the #ifdef _IS_PASS_FWDBASE block to be accessible in all rendering passes, similar to how they are declared at the top of the function in UniversalToonBodyShadingGradeMap.hlsl.

Copilot uses AI. Check for mistakes.
…BodyShadingGradeMap.hlsl

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

Copilot AI commented Jan 23, 2026

@sindharta-tanuwijaya I've opened a new pull request, #719, to work on those changes. Once the pull request is ready, I'll request review from you.

@sindharta sindharta changed the title Refactor urp function opt: reduce duplicate albedo calculations in URP Jan 23, 2026
@sindharta sindharta merged commit 7d886c0 into master Jan 23, 2026
24 checks passed
@sindharta sindharta deleted the refactor-urp-function branch January 23, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants