threejs实战_理解光源

简介: threejs实战_理解光源

光源

光的三原色:red、绿green、蓝blue
image.png

色彩模式: HSL、HSV。
色相Hue、饱和度Saturation、亮度Lightness、明度 Value。
白色反射所有光(白色的物体利于测试灯光)

Three.js 的光源类

1.环境光

把颜色添加到整个场景和对象的当前颜色上
maya环境光测试
一个蓝色的环境光渲染灰色box
image.png

THREE代码重构
环境光的特点:

  • 光源颜色影响整个场景
  • 没有特定的光源,不需要指定位置
  • 均匀照射,需要配和其它光源弱化阴影

构造函数声明

THREE.AmbientLight( hex );
javascript function initLight() { var light=new THREE.AmbientLight(0x0000ff);//蓝色环境环境光 var light_help=new THREE.SphereGeometry(16,16,16); light.add(new THREE.Mesh(light_help,new THREE.MeshBasicMaterial({color:0xffffff})));//蓝色球体 scene.add(light); } function initObject() { var r=10; // var geometry = new THREE.SphereBufferGeometry( r,16,16); var geometry = new THREE.CubeGeometry(300,300,300,); //白色反射所有光线 var material = new THREE.MeshLambertMaterial( { color:0xFFFFFF} );//白色 var mesh = new THREE.Mesh( geometry,material); mesh.position = new THREE.Vector3(0,0,0); scene.add(mesh); }
image.png

#### 2.点光源
点发散光,例如蜡烛、白炽灯
maya点光测试
maya创建点光源预览
image.png

three代码重构

点光源PolintLight的构造函数
PointLight(color,intensity,distance);
  • color颜色,16进制
  • intensity强度,默认1.0,100%强度
  • distance距离光源的距离,超过这个距离越远光的强度会减弱
        function initLight() {
   
   
            var light_point = new THREE.PointLight(0x0000FF,1,1000);//点光源,绿色,rgb
            light_point.position.set(20,80,200);
             var sphere = new THREE.SphereBufferGeometry( 10, 16, 16 );//添加一个球体
            light_point.add(new THREE.Mesh(sphere,new THREE.MeshBasicMaterial({
   
   color:0x0000ff})));//绿色球体
            scene.add(light_point);
        }

image.png

2.聚光灯

光源的光线从一个锥体射出,在被照射的物体上产生聚光效果。舞台灯光
有一个顶角α
maya聚光灯测试
image.png

three代码重构

聚光灯的构造函数

THREE.SpotLight(hex,intensity,distance,angle,exponent);
前三个通俗易懂

  • angle:聚光灯的角度,以弧度为单位,这个角度和光源方向形成的角度
  • exponent:衰减参数,越大衰减越快
                var spotLight = new THREE.SpotLight( 0xffffff, 1 );
                spotLight.position.set( 15, 40, 35 );
                spotLight.angle = Math.PI / 4;
                spotLight.penumbra = 0.05;
                spotLight.decay = 2;
                spotLight.distance = 200;

                spotLight.castShadow = true;
                spotLight.shadow.mapSize.width = 1024;
                spotLight.shadow.mapSize.height = 1024;
                spotLight.shadow.camera.near = 10;
                spotLight.shadow.camera.far = 200;
                scene.add( spotLight );

                lightHelper = new THREE.SpotLightHelper( spotLight );
                scene.add( lightHelper );

                shadowCameraHelper = new THREE.CameraHelper( spotLight.shadow.camera );
                scene.add( shadowCameraHelper );

image.png

3.平行光源(方向光)

平行光束,太阳光进入地球变成生活中的平行光。
maya平行光测试
image.png

平行光构造函数

THREEE.DirectionalLight=function(hex,instensizty);
three代码重构

            var light_direction=new THREE.DirectionalLight(0x0000FF,1);//方向光蓝色
            light_direction.position.set(10,20,6);
            var ld_help=new THREE.DirectionalLightHelper(light_direction,20,0x0000FF);
            scene.add(light_direction);//方向光
            scene.add(ld_help);

image.png

目录
相关文章
|
存储 缓存 资源调度
npm、cnpm、yarn和pnpm,我们应该选择哪个包管理工具?
在前端开发中,包管理工具是必不可少的工具之一。目前,市面上有多种包管理工具可供选择,如 `npm`、`cnpm`、`yarn` 和 `pnpm` 等。这些工具都具有自己的优点和缺点,选择适合自己的工具可以提高开发效率和代码质量。 本文将对这些工具的特点、优缺点和使用方法进行详细介绍,从而选择最适合自己的包管理工具。
3246 1
npm、cnpm、yarn和pnpm,我们应该选择哪个包管理工具?
|
Android开发 开发者
安卓(Android) 刷机教程(任何机型、小米、华为等等)
安卓(Android) 刷机教程(任何机型、小米、华为等等)
4220 0
|
开发工具 C语言 git
Vcpkg 的安装与使用
Windows 下 Vcpkg 的安装与使用
1969 0
Vcpkg 的安装与使用
|
安全 NoSQL Redis
RateLimiter 限流 —— 通过切面对单个用户进行限流和黑名单处理
RateLimiter 限流 —— 通过切面对单个用户进行限流和黑名单处理
506 2
|
网络安全
deepin系统远程ssh连接
deepin系统远程ssh连接
696 0
|
SQL 存储 关系型数据库
【Hive】Hive有哪些方式保存元数据,各有哪些特点?
【4月更文挑战第17天】【Hive】Hive有哪些方式保存元数据,各有哪些特点?
已解决E: dpkg was interrupted, you must manually run ‘sudo dpkg --configure -a‘ to correct the problem.
已解决E: dpkg was interrupted, you must manually run ‘sudo dpkg --configure -a‘ to correct the problem.
415 0
|
弹性计算 监控 大数据
云计算中的弹性伸缩:原理与实践
云计算中的弹性伸缩:原理与实践
937 99