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
16 changes: 1 addition & 15 deletions examples/jsm/lines/LineMaterial.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
/**
* parameters = {
* color: <hex>,
* linewidth: <float>,
* dashed: <boolean>,
* dashScale: <float>,
* dashSize: <float>,
* dashOffset: <float>,
* gapSize: <float>,
* resolution: <Vector2>, // to be set by renderer
* }
*/

import {
ShaderLib,
ShaderMaterial,
UniformsLib,
UniformsUtils,
Vector2
Vector2,
} from 'three';


UniformsLib.line = {

worldUnits: { value: 1 },
Expand Down
15 changes: 15 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,19 @@ class LineSegments2 extends Mesh {

}

onBeforeRender( renderer ) {

const uniforms = this.material.uniforms;

if ( uniforms && uniforms.resolution ) {

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

}

}

}

export { LineSegments2 };
17 changes: 16 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,19 @@ class Wireframe extends Mesh {

}

onBeforeRender( renderer ) {

const uniforms = this.material.uniforms;

if ( uniforms && uniforms.resolution ) {

renderer.getViewport( _viewport );
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