-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Toon shading add antialiasing #24406
Conversation
Do you have any before / after pictures? |
@gkjohnson Updated the post with a screenshot of our game before/after. The example provided is using the exact same logic: // before
vec3 res = ( coord.x < 0.7 ) ? backColor : vec3( 1.0 );
// after
vec3 res = mix( backColor, vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x)); |
@@ -18,7 +18,8 @@ vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { | |||
|
|||
#else | |||
|
|||
return ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 ); | |||
vec2 fw = fwidth( coord ); | |||
return mix( vec3( 0.7 ), vec3( 1. ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x)); |
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.
Have you considered halving the fw when using it as a step in the smoothstep function? As it is the step will happen over two pixels which will result in a less crisp edge than it could be:
return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x * 0.5, 0.7 + fw.x * 0.5, coord.x ) );
Also nit: can we use 1.0
instead of 1.
for consistency and make sure we have consistent spaces inside the parens.
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.
Indeed! Updated the PR with the changes.
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.
Code looks good to me! I trust @RenaudRohlinger has tested it.
Thanks! |
* Toon shading add antialiasing * Update gradientmap_pars_fragment.glsl.js * Update gradientmap_pars_fragment.glsl.js * Update gradientmap_pars_fragment.glsl.js Co-authored-by: Michael Herzog <[email protected]>
* Toon shading add antialiasing * Update gradientmap_pars_fragment.glsl.js * Update gradientmap_pars_fragment.glsl.js * Update gradientmap_pars_fragment.glsl.js Co-authored-by: Michael Herzog <[email protected]>
Adds antialiasing to the getGradientIrradiance function.
Before:
.
After:
Edit: Added screenshot example.