Skip to content
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

MeshToonMaterial: Only sample the red channel of gradientMap. #22911

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions examples/webgl_materials_variations_toon.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x444488 );

//

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
renderer.outputEncoding = THREE.sRGBEncoding;

// Materials

const cubeWidth = 400;
const numberOfSphersPerSide = 5;
const sphereRadius = ( cubeWidth / numberOfSphersPerSide ) * 0.8 * 0.5;
const stepSize = 1.0 / numberOfSphersPerSide;
const format = ( renderer.capabilities.isWebGL2 ) ? THREE.RedFormat : THREE.LuminanceFormat;
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, is there a way to hide this? 🤔

Copy link
Collaborator Author

@Mugen87 Mugen87 Nov 30, 2021

Choose a reason for hiding this comment

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

We use this approach at a different location, too:

const format = ( renderer.capabilities.isWebGL2 ) ? THREE.RedFormat : THREE.LuminanceFormat;

Hiding this detail in the renderer is problematic since THREE.RedFormat behaves differently than THREE.LuminanceFormat. If we would internally convert luminance to red, users could be confused because it would be only possible to sample the r channel.

IMO, we could leave the code as it is or just use THREE.RedFormat in both examples (which would make them WebGL 2 only though).


const geometry = new THREE.SphereGeometry( sphereRadius, 32, 16 );

Expand All @@ -67,10 +76,7 @@

}

const gradientMap = new THREE.DataTexture( colors, colors.length, 1, THREE.LuminanceFormat );
gradientMap.minFilter = THREE.NearestFilter;
gradientMap.magFilter = THREE.NearestFilter;
gradientMap.generateMipmaps = false;
const gradientMap = new THREE.DataTexture( colors, colors.length, 1, format );

for ( let beta = 0; beta <= 1.0; beta += stepSize ) {

Expand Down Expand Up @@ -138,12 +144,6 @@

//

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
renderer.outputEncoding = THREE.sRGBEncoding;

effect = new OutlineEffect( renderer );

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {

#ifdef USE_GRADIENTMAP

return texture2D( gradientMap, coord ).rgb;
return vec3( texture2D( gradientMap, coord ).r );

#else

Expand Down