环境光

作者: Codifier | 来源:发表于2019-11-11 14:09 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ambient Light</title>
    <script src="../../three-part/threejs/three.js"></script>
    <script src="../../three-part/utils/stats.min.js"></script>
    <script src="../../three-part/utils/dat.gui.min.js"></script>
    <script src="../controls/TrackballControls.js"></script>
    <script src="../util/util.js"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
    init();
    function init() {
        // show FPS
        let stats = initStats();
        // resize
        window.addEventListener('resize', onResize, false);

        let scene = new THREE.Scene();
        let camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.x = -30;
        camera.position.y = 40;
        camera.position.z = 30;
        camera.lookAt(scene.position);

        let renderer = new THREE.WebGLRenderer();
        renderer.setClearColor(new THREE.Color(0x000000));
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.shadowMap.enabled = true;
        document.getElementById("container").appendChild(renderer.domElement);

        // init trackball control
        let trackballControls = initTrackballControls(camera, renderer);
        let clock = new THREE.Clock();

        // add ambient light
        /**
         * AmbientLight( color : Integer, intensity : Float )
         * color - (optional) Numeric value of the RGB component of the color. Default is 0xffffff.
         * intensity - (optional) Numeric value of the light's strength/intensity. Default is 1.
         */
        let ambientLight = new THREE.AmbientLight("#606008", 1);
        scene.add(ambientLight);

        // add spotlight
        let spotLight = new THREE.SpotLight(0xffffff, 1, 180, Math.PI / 4);
        spotLight.shadow.mapSize.set(2048, 2048);
        spotLight.position.set(-30, 40, -10);
        spotLight.castShadow = true;
        scene.add(spotLight);

        // add a plane
        let planeGeometry = new THREE.PlaneGeometry(60, 40, 1, 1);
        let planeMaterial = new THREE.MeshLambertMaterial({
            color: 0xffffff
        });
        let plane = new THREE.Mesh(planeGeometry, planeMaterial);
        plane.receiveShadow = true;
        plane.rotation.x = -0.5 * Math.PI;
        scene.add(plane);

        // add a sphere
        let sphereGeometry = new THREE.SphereGeometry(4, 20, 20);
        let sphereMatrial = new THREE.MeshLambertMaterial({
            color : 0x7777ff
        });
        let sphere = new THREE.Mesh(sphereGeometry, sphereMatrial);
        sphere.position.set(0, 4, 2);
        sphere.castShadow = true;
        scene.add(sphere);

        // attributes which can be modified in GUI
        const controls = {
            "intensity" : ambientLight.intensity,
            "ambientColor" : ambientLight.color.getStyle(),
            "disableSpotlight" : false
        };
        // init GUI
        initGUI();

        renderScene();

        function initGUI(){
            let gui = new dat.GUI();
            gui.add(controls, 'intensity', 0, 3, 0.1).onChange(function (e) {
                ambientLight.color = new THREE.Color(controls.ambientColor);
                ambientLight.intensity = controls.intensity;
            });
            gui.addColor(controls, 'ambientColor').onChange(function (e) {
                ambientLight.color = new THREE.Color(controls.ambientColor);
                ambientLight.intensity = controls.intensity;
            });
            gui.add(controls, 'disableSpotlight').onChange(function (e) {
                spotLight.visible = !e;
            });
        }

        function onResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        }

        function renderScene(){
            trackballControls.update(clock.getDelta());
            stats.update();
            requestAnimationFrame(renderScene);
            renderer.render(scene, camera);
        }
    }
</script>
</body>
</html>

运行结果:

  1. 打开聚光灯效果:


  2. 关闭聚光灯效果:


相关文章

  • 环境光

    运行结果: 打开聚光灯效果: 关闭聚光灯效果:

  • 视频布光

    1、环境光:环境光,又称为后台光,是指专一使用以照明后台和环境的光耀。环境光主假定颠末环境光耀所构成的后台光调和被...

  • OpenGL ES-光照计算(公式)

    环境光的计算 环境光 = 光源的环境光颜色 * 物体的材质颜⾊ 发射光的计算 发射颜色 = 物体的反射材质颜⾊ 漫...

  • OpenGL ES 􏳆􏰤􏷐􏶾􏲗􏵘光照计算

    光照基础 环境光 漫反射光 镜面光 光照特性 发射光:由物体自身发光 环境光:环境中充分散射的光,而且无法分辨它的...

  • 3d物体光照类型和效果

    光照分为环境光,散射光和镜面光 1. 环境光 环境光是均匀的光,不依赖光源位置,没有方向,环境光不会对物体表面产生...

  • c4d-redshift红移渲染器关于AO环境光遮蔽详解

    环境光遮蔽(Ambient Occlusion)“AO”为Amblent Occlusion的缩写,中文译为环境光...

  • OpenGL ES 光照计算

    光照计算在片元着色器执行,计算每一个像素点的颜色 一、光照计算 1、环境光计算 环境光 = 光源的环境光颜色 * ...

  • 灯光

    点光源 聚光灯 环境光(漫反射) 平行光

  • 3 环境+体积雾

    环境 没有衰减不会有雾气 环境 区域光 雾气

  • OpenGL ES光照公式及GLSL实现

    1.光照特性 发射光:由物体自身发光 环境光:就是在环境中充分散射的光,而且无法分辨它的方向 漫反射光:光线来自某...

网友评论

      本文标题:环境光

      本文链接:https://www.haomeiwen.com/subject/jrdtictx.html