天堂国产午夜亚洲专区-少妇人妻综合久久蜜臀-国产成人户外露出视频在线-国产91传媒一区二区三区

當(dāng)前位置:主頁 > 論文百科 > 英文數(shù)據(jù)庫 >

webgl入門指南pdf_《webgl入門指南》學(xué)習(xí)筆記三之three.js創(chuàng)建多重紋理

發(fā)布時(shí)間:2016-12-06 12:05

  本文關(guān)鍵詞:WebGL入門指南,由筆耕文化傳播整理發(fā)布。


WebGL入門指南》學(xué)習(xí)筆記三之three.js創(chuàng)建多重紋理,有需要的朋友可以參考下。

 

之前的demo看起來已經(jīng)很真了,當(dāng)然是在大家,一步一步step by step的情況下,被各種初始化的代碼虐的體無完膚后的,才會(huì)有這么個(gè)感受。但是從一個(gè)對(duì)計(jì)算機(jī)圖形無感的人來看,這當(dāng)然是很粗糙的,比如看起來比較‘平’光線好像,對(duì)比不正常,所以我們現(xiàn)在要使用多重紋理,在這個(gè)新的demo里面我們使用了以下三種貼圖

1.顏色貼圖

這個(gè)提供了最基本的顏色,比如之前demo我們使用的。

2.法線貼圖

法線貼圖的本質(zhì)是將一種額外的網(wǎng)格屬性編碼成RGB值存儲(chǔ)在一張位圖文件中,和光線的關(guān)系很大,光線入射到模型表面以后,發(fā)射光的方向就取決于法線方向。所以物體的明暗效果,就是由法線和光線決定的,而法線貼圖,就是他們的基礎(chǔ)色因?yàn)? 漫反射下 漫反射光顏色 = 基礎(chǔ)色*入射光顏色*cosa 。這個(gè)基礎(chǔ)色就是法線貼圖中獲取的顏色。

3.高光貼圖

這個(gè)高光貼圖是指網(wǎng)格表面反光程度和反光量,和法線貼圖類似。

demo來自第三章earth-shader.js 建議大家自己對(duì)照著官方demo看,這里暫時(shí)不提供下載,后續(xù)會(huì)集體放出

 

// ConstructorEarthApp = function(){ Sim.App.call(this);}// Subclass Sim.App// 還是繼承Sim.AppEarthApp.prototype = new Sim.App();// Our custom initializer/** * [init description]自定義初始化對(duì)象 * @param {[type]} param [description] * @return {[type]} [description] * @author {[name]} Daniel Wong * @date {[date]} * @about {[關(guān)于]} */EarthApp.prototype.init = function(param){ // Call superclass init code to set up scene, renderer, default camera //這里已經(jīng)包括了必須的scene renderer camera Sim.App.prototype.init.call(this, param); // Create the Earth and add it to our sim // 初始化地球(在下面定義)傳遞給SIm框架 var earth = new Earth(); earth.init(); this.addObject(earth);// Let there be light! // 初始化光線,傳遞給地球 var sun = new Sun(); sun.init(); this.addObject(sun);}// Custom Earth class/** * [Earth description]自定義地球 * @author {[name]} Daniel Wong * @date {[date]} * @about {[關(guān)于]} */Earth = function(){ Sim.Object.call(this);}Earth.prototype = new Sim.Object();//以上為繼承自Sim.Object 和基于類的繼承有差別/** * [init description]創(chuàng)建一個(gè)群組(在里面創(chuàng)建地球這個(gè)整體包含的球和云) * @return {[type]} [description] * @author {[name]} Daniel Wong * @date {[date]} * @about {[關(guān)于]} */Earth.prototype.init = function(){ // Create a group to contain Earth and Clouds var earthGroup = new THREE.Object3D();// Tell the framework about our object this.setObject3D(earthGroup);//這兩句什么意思?? // Add the earth globe and clouds // 添加球和云(兩者在下文定義)到框架里面 this.createGlobe(); this.createClouds();}/** * [createGlobe description]創(chuàng)建地球的球體 * @return {[type]} [description] * @author {[name]} Daniel Wong * @date {[date]} * @about {[關(guān)于]}以上屬于為了讓邏輯清晰的封裝,從這個(gè)函數(shù)開始才是干貨 * */Earth.prototype.createGlobe = function(){ // Create our Earth with nice texture - normal map for elevation, specular highlights //創(chuàng)建多重紋理,法線貼圖,高光貼圖 var surfaceMap = THREE.ImageUtils.loadTexture( "../images/earth_surface_2048.jpg" ); var normalMap = THREE.ImageUtils.loadTexture( "../images/earth_normal_2048.jpg" ); var specularMap = THREE.ImageUtils.loadTexture( "../images/earth_specular_2048.jpg" ); var shader = THREE.ShaderUtils.lib[ "normal" ], //法線貼圖著色器 uniforms = THREE.UniformsUtils.clone( shader.uniforms ); //用之前的法線貼圖著色器 創(chuàng)建一個(gè)uniforms對(duì)象 uniforms[ "tNormal" ].texture = normalMap; //將之前創(chuàng)建的多重貼圖 填充進(jìn)uniforms對(duì)象 uniforms[ "tDiffuse" ].texture = surfaceMap; //法線貼圖著色器程序至少需要一張法線貼圖紋理來計(jì)算凹凸值 uniforms[ "tSpecular" ].texture = specularMap; uniforms[ "enableDiffuse" ].value = true; uniforms[ "enableSpecular" ].value = true; var shaderMaterial = new THREE.ShaderMaterial({ fragmentShader: shader.fragmentShader, //片元著色器 vertexShader: shader.vertexShader, //定點(diǎn)著色器 uniforms: uniforms, lights: true }); var globeGeometry = new THREE.SphereGeometry(1, 32, 32); // We'll need these tangents for our shader //計(jì)算切線,(默認(rèn)情況three.js不會(huì)為幾何體計(jì)算切線),切線是用于計(jì)算法線貼圖值時(shí)必要的向量值 globeGeometry.computeTangents(); var globeMesh = new THREE.Mesh( globeGeometry, shaderMaterial ); // Let's work in the tilt // 繞x軸偏離一定角度,模擬地球黃道 globeMesh.rotation.x = Earth.TILT; // Add it to our group // 將這個(gè)球的globeMesh添加到框架里面 this.object3D.add(globeMesh); // Save it away so we can rotate it // 本身globeMesh為局部變量,無法在其它函數(shù)調(diào)用,在這里保存globeMesh到this對(duì)象,以供下面調(diào)用 this.globeMesh = globeMesh;}Earth.prototype.createClouds = function(){ // Create our clouds // 創(chuàng)建云首先是創(chuàng)建一個(gè)貼圖,使用蘭伯特光照材質(zhì) var cloudsMap = THREE.ImageUtils.loadTexture( "../images/earth_clouds_1024.png" ); var cloudsMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, map: cloudsMap, transparent:true } ); //創(chuàng)建云的網(wǎng)格 var cloudsGeometry = new THREE.SphereGeometry(Earth.CLOUDS_SCALE, 32, 32); cloudsMesh = new THREE.Mesh( cloudsGeometry, cloudsMaterial ); cloudsMesh.rotation.x = Earth.TILT; // Add it to our group this.object3D.add(cloudsMesh); // Save it away so we can rotate it // 存在this對(duì)象里面,供下面調(diào)用,實(shí)現(xiàn)一些計(jì)算(自轉(zhuǎn)) this.cloudsMesh = cloudsMesh;}/** * [update description]update這個(gè)程序運(yùn)行時(shí),每一幀都會(huì)調(diào)用這里的內(nèi)容 * @return {[type]} [description] * @author {[name]} Daniel Wong * @date {[date]} 2015-07-01T10:45:38+0800 * @about {[關(guān)于]} */Earth.prototype.update = function(){ // "I feel the Earth move..." // 使地球繞y軸旋轉(zhuǎn),一定角度,因?yàn)槊恳粠紩?huì)調(diào)用,所以實(shí)現(xiàn)了自轉(zhuǎn)的效果 this.globeMesh.rotation.y += Earth.ROTATION_Y; // "Clouds, too..." //使地球繞y軸旋轉(zhuǎn),一定角度,因?yàn)槊恳粠紩?huì)調(diào)用,,所以實(shí)現(xiàn)了自轉(zhuǎn)的效果 this.cloudsMesh.rotation.y += Earth.CLOUDS_ROTATION_Y; Sim.Object.prototype.update.call(this);//}Earth.ROTATION_Y = 0.001;Earth.TILT = 0.41;Earth.CLOUDS_SCALE = 1.005;Earth.CLOUDS_ROTATION_Y = Earth.ROTATION_Y * 0.95;// Custom Sun class/** * [Sun description]創(chuàng)建太陽光 * @author {[name]} Daniel Wong * @date {[date]} 2015-07-01T10:48:34+0800 * @about {[關(guān)于]} */Sun = function(){ Sim.Object.call(this);}Sun.prototype = new Sim.Object();Sun.prototype.init = function(){ // Create a point light to show off the earth - set the light out back and to left a bit // 創(chuàng)建一個(gè)點(diǎn)光源模擬太陽 var light = new THREE.PointLight( 0xffffff, 2, 100); light.position.set(-10, 0, 20);// Tell the framework about our object // 傳遞給框架 this.setObject3D(light); }


  本文關(guān)鍵詞:WebGL入門指南,由筆耕文化傳播整理發(fā)布。



本文編號(hào):206315

資料下載
論文發(fā)表

本文鏈接:http://sikaile.net/wenshubaike/mishujinen/206315.html


Copyright(c)文論論文網(wǎng)All Rights Reserved | 網(wǎng)站地圖 |

版權(quán)申明:資料由用戶c4574***提供,本站僅收錄摘要或目錄,作者需要?jiǎng)h除請(qǐng)E-mail郵箱bigeng88@qq.com
国产精品久久精品毛片| 国产伦精品一区二区三区高清版| 黑丝国产精品一区二区| 麻豆剧果冻传媒一二三区| 成人精品国产亚洲av久久| 日本精品视频一二三区| 国产传媒高清视频在线| 69久久精品亚洲一区二区| 91人妻丝袜一区二区三区| 欧美日韩乱码一区二区三区| 在线观看免费午夜福利| 少妇人妻一级片一区二区三区| 中国美女偷拍福利视频| 东京热电东京热一区二区三区| 国产一级精品色特级色国产| 国产精品欧美一级免费| 在线免费国产一区二区三区| 国产综合欧美日韩在线精品 | 欧美国产精品区一区二区三区| 欧美同性视频免费观看| 91久久精品中文内射| 国产亚洲精品俞拍视频福利区| 日韩国产亚洲一区二区三区| 男人操女人下面国产剧情| 国产精品午夜福利免费阅读| 欧美二区视频在线观看| 黄色av尤物白丝在线播放网址| a久久天堂国产毛片精品| 精品丝袜一区二区三区性色| 久久婷婷综合色拍亚洲| 91人妻人人揉人人澡人| 美女露小粉嫩91精品久久久| 亚洲av日韩一区二区三区四区| 欧美在线观看视频三区| 亚洲av成人一区二区三区在线| 欧美日韩精品综合在线| 激情丁香激情五月婷婷| 欧美人妻少妇精品久久性色| 国产免费一区二区三区不卡| 福利一区二区视频在线| 国产原创中文av在线播放|