#746 Implemented RTE for basic line materials (non thick)
This commit is contained in:
@@ -7,6 +7,7 @@ import { Matrix4, Vector2, Vector3 } from 'three'
|
||||
import { Geometry } from './converter/Geometry'
|
||||
import SpeckleStandardMaterial from './materials/SpeckleStandardMaterial'
|
||||
import SpeckleLineMaterial from './materials/SpeckleLineMaterial'
|
||||
import SpeckleLineBasicMaterial from './materials/SpeckleLineBasicMaterial'
|
||||
/**
|
||||
* Manages objects and provides some convenience methods to focus on the entire scene, or one specific object.
|
||||
*/
|
||||
@@ -383,7 +384,7 @@ export default class SceneObjectManager {
|
||||
clippingPlanes: this.viewer.sectionBox.planes
|
||||
})
|
||||
} else {
|
||||
lineMaterial = new THREE.LineBasicMaterial({
|
||||
lineMaterial = new SpeckleLineBasicMaterial({
|
||||
color: 0x7f7f7f,
|
||||
clippingPlanes: this.viewer.sectionBox.planes
|
||||
})
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { speckle_line_basic_vert } from './shaders/speckle-line-basic-vert'
|
||||
import { speckle_line_basic_frag } from './shaders/speckle-line-basic-frag'
|
||||
import { UniformsUtils, ShaderLib, Vector3, LineBasicMaterial } from 'three'
|
||||
import { Matrix4 } from 'three'
|
||||
import { Geometry } from '../converter/Geometry'
|
||||
|
||||
class SpeckleLineBasicMaterial extends LineBasicMaterial {
|
||||
private static readonly matBuff: Matrix4 = new Matrix4()
|
||||
|
||||
constructor(parameters, defines = []) {
|
||||
super(parameters)
|
||||
|
||||
this.userData.uViewer_high = {
|
||||
value: new Vector3()
|
||||
}
|
||||
this.userData.uViewer_low = {
|
||||
value: new Vector3()
|
||||
}
|
||||
;(this as any).vertProgram = speckle_line_basic_vert
|
||||
;(this as any).fragProgram = speckle_line_basic_frag
|
||||
;(this as any).uniforms = UniformsUtils.merge([
|
||||
ShaderLib.line.uniforms,
|
||||
{
|
||||
uViewer_high: {
|
||||
value: this.userData.uViewer_high.value
|
||||
},
|
||||
uViewer_low: {
|
||||
value: this.userData.uViewer_low.value
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
this.onBeforeCompile = function (shader) {
|
||||
shader.uniforms.uViewer_high = this.userData.uViewer_high
|
||||
shader.uniforms.uViewer_low = this.userData.uViewer_low
|
||||
shader.vertexShader = this.vertProgram
|
||||
shader.fragmentShader = this.fragProgram
|
||||
}
|
||||
|
||||
for (var k = 0; k < defines.length; k++) {
|
||||
this.defines[defines[k]] = ''
|
||||
}
|
||||
|
||||
if (Geometry.USE_RTE) {
|
||||
this.defines = {}
|
||||
this.defines['USE_RTE'] = ' '
|
||||
}
|
||||
}
|
||||
|
||||
copy(source) {
|
||||
super.copy(source)
|
||||
this.userData = {}
|
||||
this.userData.uViewer_high = {
|
||||
value: new Vector3()
|
||||
}
|
||||
this.userData.uViewer_low = {
|
||||
value: new Vector3()
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
onBeforeRender(_this, scene, camera, geometry, object, group) {
|
||||
if (Geometry.USE_RTE) {
|
||||
SpeckleLineBasicMaterial.matBuff.copy(camera.matrixWorldInverse)
|
||||
SpeckleLineBasicMaterial.matBuff.elements[12] = 0
|
||||
SpeckleLineBasicMaterial.matBuff.elements[13] = 0
|
||||
SpeckleLineBasicMaterial.matBuff.elements[14] = 0
|
||||
SpeckleLineBasicMaterial.matBuff.multiply(object.matrixWorld)
|
||||
object.modelViewMatrix.copy(SpeckleLineBasicMaterial.matBuff)
|
||||
|
||||
let uViewer_low = new Vector3()
|
||||
let uViewer_high = new Vector3()
|
||||
let uViewer = new Vector3(
|
||||
camera.matrixWorld.elements[12],
|
||||
camera.matrixWorld.elements[13],
|
||||
camera.matrixWorld.elements[14]
|
||||
)
|
||||
|
||||
Geometry.DoubleToHighLowVector(uViewer, uViewer_low, uViewer_high)
|
||||
this.userData.uViewer_high.value.copy(uViewer_high)
|
||||
this.userData.uViewer_low.value.copy(uViewer_low)
|
||||
this.needsUpdate = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default SpeckleLineBasicMaterial
|
||||
@@ -0,0 +1,53 @@
|
||||
export const speckle_line_basic_frag = /* glsl */ `
|
||||
uniform vec3 diffuse;
|
||||
uniform float opacity;
|
||||
#ifndef FLAT_SHADED
|
||||
varying vec3 vNormal;
|
||||
#endif
|
||||
#include <common>
|
||||
#include <dithering_pars_fragment>
|
||||
#include <color_pars_fragment>
|
||||
#include <uv_pars_fragment>
|
||||
#include <uv2_pars_fragment>
|
||||
#include <map_pars_fragment>
|
||||
#include <alphamap_pars_fragment>
|
||||
#include <alphatest_pars_fragment>
|
||||
#include <aomap_pars_fragment>
|
||||
#include <lightmap_pars_fragment>
|
||||
#include <envmap_common_pars_fragment>
|
||||
#include <envmap_pars_fragment>
|
||||
#include <cube_uv_reflection_fragment>
|
||||
#include <fog_pars_fragment>
|
||||
#include <specularmap_pars_fragment>
|
||||
#include <logdepthbuf_pars_fragment>
|
||||
#include <clipping_planes_pars_fragment>
|
||||
void main() {
|
||||
#include <clipping_planes_fragment>
|
||||
vec4 diffuseColor = vec4( diffuse, opacity );
|
||||
#include <logdepthbuf_fragment>
|
||||
#include <map_fragment>
|
||||
#include <color_fragment>
|
||||
#include <alphamap_fragment>
|
||||
#include <alphatest_fragment>
|
||||
#include <specularmap_fragment>
|
||||
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
||||
// accumulation (baked indirect lighting only)
|
||||
#ifdef USE_LIGHTMAP
|
||||
vec4 lightMapTexel = texture2D( lightMap, vUv2 );
|
||||
reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
|
||||
#else
|
||||
reflectedLight.indirectDiffuse += vec3( 1.0 );
|
||||
#endif
|
||||
// modulation
|
||||
#include <aomap_fragment>
|
||||
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
|
||||
vec3 outgoingLight = reflectedLight.indirectDiffuse;
|
||||
#include <envmap_fragment>
|
||||
#include <output_fragment>
|
||||
#include <tonemapping_fragment>
|
||||
#include <encodings_fragment>
|
||||
#include <fog_fragment>
|
||||
#include <premultiplied_alpha_fragment>
|
||||
#include <dithering_fragment>
|
||||
}
|
||||
`
|
||||
@@ -0,0 +1,51 @@
|
||||
export const speckle_line_basic_vert = /* glsl */ `
|
||||
#include <common>
|
||||
#include <uv_pars_vertex>
|
||||
#include <uv2_pars_vertex>
|
||||
#include <envmap_pars_vertex>
|
||||
#include <color_pars_vertex>
|
||||
#include <fog_pars_vertex>
|
||||
#include <morphtarget_pars_vertex>
|
||||
#include <skinning_pars_vertex>
|
||||
#include <logdepthbuf_pars_vertex>
|
||||
#include <clipping_planes_pars_vertex>
|
||||
#ifdef USE_RTE
|
||||
attribute vec3 position_high;
|
||||
attribute vec3 position_low;
|
||||
uniform vec3 uViewer_high;
|
||||
uniform vec3 uViewer_low;
|
||||
#endif
|
||||
void main() {
|
||||
#include <uv_vertex>
|
||||
#include <uv2_vertex>
|
||||
#include <color_vertex>
|
||||
#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
|
||||
#include <beginnormal_vertex>
|
||||
#include <morphnormal_vertex>
|
||||
#include <skinbase_vertex>
|
||||
#include <skinnormal_vertex>
|
||||
#include <defaultnormal_vertex>
|
||||
#endif
|
||||
#include <begin_vertex>
|
||||
#include <morphtarget_vertex>
|
||||
#include <skinning_vertex>
|
||||
// #include <project_vertex> COMMENTED CHUNK
|
||||
#ifdef USE_RTE
|
||||
vec3 highDifference = vec3(position_high.xyz - uViewer_high);
|
||||
vec3 lowDifference = vec3(position_low.xyz - uViewer_low);
|
||||
vec4 mvPosition = vec4(highDifference.xyz + lowDifference.xyz , 1.);
|
||||
#else
|
||||
vec4 mvPosition = vec4( transformed, 1.0 );
|
||||
#endif
|
||||
#ifdef USE_INSTANCING
|
||||
mvPosition = instanceMatrix * mvPosition;
|
||||
#endif
|
||||
mvPosition = modelViewMatrix * mvPosition;
|
||||
gl_Position = projectionMatrix * mvPosition;
|
||||
#include <logdepthbuf_vertex>
|
||||
#include <clipping_planes_vertex>
|
||||
#include <worldpos_vertex>
|
||||
#include <envmap_vertex>
|
||||
#include <fog_vertex>
|
||||
}
|
||||
`
|
||||
Reference in New Issue
Block a user