罗 乾 林
2020-08-11
第一题: const sphereGeometry = new Sphere(gl, { widthSegments: 160, }); 第二题: const fragment = /* glsl */ ` precision highp float; varying vec3 vNormal; uniform vec3 uColor; void main() { vec3 normal = normalize(vNormal); float lighting = dot(normal, normalize(vec3(-0.3, 0.8, 0.6))); gl_FragColor.rgb = uColor + lighting * 0.1; gl_FragColor.a = 1.0; } `; function createProgram(r,g,b){ return new Program(gl,{ vertex, fragment, uniforms:{ uColor:{value:new Vec3(r,g,b)} } }) } const program_red =createProgram(1.0,0,0); const program_green =createProgram(0,1.0,0); const program_blue = createProgram(0.0,0,1.0); const program_yellow = createProgram(1.0,1.0,0); const torus = new Mesh(gl, {geometry: torusGeometry, program:program_red}); torus.position.set(0, 1.3, 0); torus.setParent(scene); const sphere = new Mesh(gl, {geometry: sphereGeometry, program:program_green}); sphere.position.set(1.3, 0, 0); sphere.setParent(scene); const cube = new Mesh(gl, {geometry: cubeGeometry, program:program_blue}); cube.position.set(0, -1.3, 0); cube.setParent(scene); const cylinder = new Mesh(gl, {geometry: cylinderGeometry, program:program_yellow}); cylinder.position.set(-1.3, 0, 0); cylinder.setParent(scene); 望老师指正
展开
作者回复: 不错~
3