var vertexShader='precision highp float;
// Attributes
attribute vec3 position;
attribute vec4 color;
attribute vec3 normal;
// Varying
varying vec4 v_color;
void main(void) {
gl_Position = vec4(position, 1.0);
v_color = color;
}'
var fragmentShader='precision highp float;
// Varying
varying vec4 v_color;
void main(void) {
gl_FragColor = v_color;
}'
private _vertices = new Float32Array([
0, 0, 0.5, //顶点1坐标
0.5,0 , 0.5, //顶点2坐标
0, 0.5,0.5 , //顶点3坐标
0.5, 0.5, 0.5, //顶点4坐标
])
private _colors = new Float32Array([
1, 0, 0,1, //顶点1颜色
0, 1, 0,1, //顶点2颜色
0, 0, 1,1, //顶点3颜色
1, 1, 1,1, //顶点4颜色
])
private _normals = new Float32Array([
0, 0, 0, //顶点1颜色
0, 0, 0, //顶点2颜色
0, 0, 0, //顶点3颜色
0, 0, 0, //顶点4颜色
])
private _indexs = new Uint16Array([
0, 1, 2,
2,1,3
])
var material = new THREE.RawShaderMaterial( {
vertexShader: vertexShader,
fragmentShader: fragmentShader
} )
var _geometry=new BufferGeometry()
_geometry.attributes.position = new THREE.BufferAttribute(this._vertices, 3)
_geometry.attributes.color = new THREE.BufferAttribute(this._colors, 4)
_geometry.attributes.normal=new THREE.BufferAttribute(this._normals, 3)
_geometry.index = new THREE.BufferAttribute(this._indexs, 1)
var cube = new THREE.Mesh(this._geometry,material1)
this._scene.add(cube)
var Camera=new THREE.PerspectiveCamera( Math.PI / 4.0, this.width / this.height, 0.1, 1000 )
doRender() : void{
this._render.render(this._scene, Camera)
}
private doMouseWheel = (evt)=>{
Camera.position.x+=evt.wheelDelta*0.01
Camera.updateProjectionMatrix()
}
The main codes are as follows,
When I slide the mouse wheel, cube didn’t move with Camera.position,Why is it ineffective for RawShaderMaterial?Other Material such as MeshBasicMaterial can work.