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

Examples: Remove need for manually assigning Line2 material resolution #28343

Merged
merged 11 commits into from
May 14, 2024
5 changes: 2 additions & 3 deletions examples/jsm/lines/LineMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* dashSize: <float>,
* dashOffset: <float>,
* gapSize: <float>,
* resolution: <Vector2>, // to be set by renderer
* resolution: <Vector2>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line should be removed.

@Mugen87 How do you feel about removing this entire comment block? Apparently, we no longer use this coding pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll fix it. It's time to move on.

* }
*/

Expand All @@ -16,10 +16,9 @@ import {
ShaderMaterial,
UniformsLib,
UniformsUtils,
Vector2
Vector2,
} from 'three';


UniformsLib.line = {

worldUnits: { value: 1 },
Expand Down
13 changes: 13 additions & 0 deletions examples/jsm/lines/LineSegments2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry.js';
import { LineMaterial } from '../lines/LineMaterial.js';

const _viewport = new Vector4();

const _start = new Vector3();
const _end = new Vector3();

Expand Down Expand Up @@ -356,6 +358,17 @@ class LineSegments2 extends Mesh {

}

onBeforeRender( renderer ) {

if ( this.material.uniforms.resolution ) {

renderer.getCurrentViewport( _viewport ).multiplyScalar( 1 / renderer.getPixelRatio() );
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be:

renderer.getViewport( _viewport );

this.material.uniforms.resolution.value.set( _viewport.z, _viewport.w );

}

}

}

export { LineSegments2 };
15 changes: 14 additions & 1 deletion examples/jsm/lines/Wireframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import {
InstancedInterleavedBuffer,
InterleavedBufferAttribute,
Mesh,
Vector3
Vector3,
Vector4
} from 'three';
import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry.js';
import { LineMaterial } from '../lines/LineMaterial.js';

const _start = new Vector3();
const _end = new Vector3();
const _viewport = new Vector4();

class Wireframe extends Mesh {

Expand Down Expand Up @@ -51,6 +53,17 @@ class Wireframe extends Mesh {

}

onBeforeRender( renderer ) {

if ( this.material.uniforms.resolution ) {

renderer.getCurrentViewport( _viewport ).multiplyScalar( 1 / renderer.getPixelRatio() );
this.material.uniforms.resolution.value.set( _viewport.z, _viewport.w );

}

}

}

export { Wireframe };
7 changes: 0 additions & 7 deletions examples/webgl_lines_fat.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
linewidth: 5, // in world units with size attenuation, pixels otherwise
vertexColors: true,

//resolution: // to be set by renderer, eventually
dashed: false,
alphaToCoverage: true,

Expand Down Expand Up @@ -175,9 +174,6 @@

controls.update();

// renderer will set this eventually
matLine.resolution.set( window.innerWidth, window.innerHeight ); // resolution of the viewport

gpuPanel.startQuery();
renderer.render( scene, camera );
gpuPanel.endQuery();
Expand All @@ -197,9 +193,6 @@
camera2.position.copy( camera.position );
camera2.quaternion.copy( camera.quaternion );

// renderer will set this eventually
matLine.resolution.set( insetWidth, insetHeight ); // resolution of the inset viewport

renderer.render( scene, camera2 );

renderer.setScissorTest( false );
Expand Down
6 changes: 0 additions & 6 deletions examples/webgl_lines_fat_raycasting.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
worldUnits: true,
vertexColors: true,

//resolution: // to be set by renderer, eventually
alphaToCoverage: true,

} );
Expand All @@ -75,7 +74,6 @@
opacity: 0.2,
depthTest: false,
visible: false,
//resolution: // to be set by renderer, eventually

} );

Expand Down Expand Up @@ -213,10 +211,6 @@

renderer.setSize( window.innerWidth, window.innerHeight );

// renderer will set this eventually
matLine.resolution.set( window.innerWidth, window.innerHeight );
matThresholdLine.resolution.set( window.innerWidth, window.innerHeight );

}

function onPointerMove( event ) {
Expand Down
7 changes: 0 additions & 7 deletions examples/webgl_lines_fat_wireframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@

color: 0x4080ff,
linewidth: 5, // in pixels
//resolution: // to be set by renderer, eventually
dashed: false

} );
Expand Down Expand Up @@ -136,9 +135,6 @@

renderer.setViewport( 0, 0, window.innerWidth, window.innerHeight );

// renderer will set this eventually
matLine.resolution.set( window.innerWidth, window.innerHeight ); // resolution of the viewport

renderer.render( scene, camera );

// inset scene
Expand All @@ -156,9 +152,6 @@
camera2.position.copy( camera.position );
camera2.quaternion.copy( camera.quaternion );

// renderer will set this eventually
matLine.resolution.set( insetWidth, insetHeight ); // resolution of the inset viewport

renderer.render( scene, camera2 );

renderer.setScissorTest( false );
Expand Down