提交 4901440e 编写于 作者: M Mr.doob

Merging alteredq's branch

上级 d961ee52
此差异已折叠。
此差异已折叠。
......@@ -28,10 +28,14 @@
a:hover {
color: #0080ff;
}
#log { color:#fff; position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
</style>
</head>
<body>
<pre id="log"></pre>
<div id="container"></div>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - point lights WebGL demo.<br />
......@@ -124,7 +128,7 @@
scene.addObject( l3 );
//renderer = new THREE.CanvasRenderer();
renderer = new THREE.WebGLRenderer( );
renderer = new THREE.WebGLRenderer( scene );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
......@@ -162,7 +166,11 @@
}
function log() {
function log( text ) {
var e = document.getElementById("log");
e.innerHTML = text + "<br/>" + e.innerHTML;
}
</script>
......
......@@ -17,7 +17,7 @@
a:hover { color: #0080ff; }
canvas { pointer-events:none; z-index:10; position:relative; }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
#d { text-align:center; margin:1em 0 -7.5em 0; z-index:1000; position:relative; display:block }
.button { background:orange; color:#fff; padding:0.2em 0.5em; cursor:pointer }
.inactive { background:#999; color:#eee }
......@@ -103,7 +103,8 @@
var images = loadImageArray( urls );
var cubeMaterial3 = new THREE.MeshLambertMaterial( { color: 0xffaa00, env_map: new THREE.TextureCube( images ) } );
//var cubeMaterial3 = new THREE.MeshPhongMaterial( { color: 0x000000, specular:0xaa0000, env_map: new THREE.TextureCube( images ), combine: THREE.Mix, reflectivity: 0.25 } );
var cubeMaterial3 = new THREE.MeshLambertMaterial( { color: 0xff6600, env_map: new THREE.TextureCube( images ), combine: THREE.Mix, reflectivity: 0.3 } );
var cubeMaterial2 = new THREE.MeshLambertMaterial( { color: 0xffee00, env_map: new THREE.TextureCube( images ) } );
var cubeMaterial1 = new THREE.MeshLambertMaterial( { color: 0xffffff, env_map: new THREE.TextureCube( images ) } )
......
......@@ -16,7 +16,7 @@
a { color: #ff0080; text-decoration: none; }
a:hover { color: #0080ff; }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
#d { text-align:center; margin:1em auto -9.0em; z-index:1000; position:relative; display:block;
background:rgba(0,0,0,0.75); padding:0.25em; width:300px; border-radius:10px; -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,0.5) }
</style>
......
......@@ -10,10 +10,13 @@
margin: 0px;
overflow: hidden;
}
#log { color:#fff; position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
</style>
</head>
<body>
<pre id="log"></pre>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
......@@ -77,19 +80,19 @@
materials.push( { material: new THREE.MeshBasicMaterial( { color: 0x665500, blending: THREE.AdditiveBlending } ), overdraw: false, doubleSided: true } );
//materials.push( { material: new THREE.MeshBasicMaterial( { color: 0xff0000, blending: THREE.SubtractiveBlending } ), overdraw: false, doubleSided: true } );
materials.push( { material: new THREE.MeshLambertMaterial( { color: 0xdddddd, shading: THREE.SmoothShading } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshLambertMaterial( { color: 0xdddddd, shading: THREE.SmoothShading } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshPhongMaterial( { ambient: 0x030303, color: 0xdddddd, specular: 0x009900, shininess: 30, shading: THREE.SmoothShading } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshNormalMaterial( { shading: THREE.SmoothShading } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshBasicMaterial( { color: 0xffaa00, wireframe: true } ), overdraw: false, doubleSided: true } );
materials.push( { material: new THREE.MeshBasicMaterial( { color: 0xffaa00, wireframe: true } ), overdraw: false, doubleSided: true } );
materials.push( { material: new THREE.MeshDepthMaterial( { near: 1, far: 2000 } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshBasicMaterial( { map: generatedTexture } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshLambertMaterial( { map: generatedTexture } ), overdraw: true, doubleSided: false } );
materials.push( { material: new THREE.MeshLambertMaterial( { map: generatedTexture } ), overdraw: true, doubleSided: false } );
// Extra mesh to be broken down for MeshFaceMaterial
var geometry2 = new Sphere( 70, 32, 16, true );
// Extra mesh to be broken down for MeshFaceMaterial
var geometry2 = new Sphere( 70, 32, 16, true );
for ( var i = 0, l = geometry2.faces.length; i < l; i ++ ) {
var face = geometry2.faces[ i ];
......@@ -101,14 +104,14 @@
objects = [];
var sphere, geometry;
var sphere, geometry;
for ( var i = 0, l = materials.length; i < l; i ++ ) {
geometry = materials[ i ].material instanceof THREE.MeshFaceMaterial ? geometry2 : geometry1;
sphere = new THREE.Mesh( geometry, materials[ i ].material );
geometry = materials[ i ].material instanceof THREE.MeshFaceMaterial ? geometry2 : geometry1;
sphere = new THREE.Mesh( geometry, materials[ i ].material );
sphere.overdraw = materials[ i ].overdraw;
sphere.doubleSided = materials[ i ].doubleSided;
......@@ -142,7 +145,7 @@
pointLight = new THREE.PointLight( 0xffffff, 1 );
scene.addLight( pointLight );
renderer = new THREE.WebGLRenderer();
renderer = new THREE.WebGLRenderer( scene );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
......@@ -224,6 +227,13 @@
stats.update();
}
function log( text ) {
var e = document.getElementById("log");
e.innerHTML = text + "<br/>" + e.innerHTML;
}
</script>
......
......@@ -15,7 +15,7 @@
h1 { }
a { color:skyblue }
canvas { pointer-events:none; z-index:10; position:relative; }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:1; pointer-events:none; }
#d { text-align:center; margin:1em 0 -15.7em 0; z-index:0; position:relative; display:block }
.button { background:#000; color:#fff; padding:0.2em 0.5em; cursor:pointer }
.inactive { background:#999; color:#eee }
......@@ -40,7 +40,7 @@
</div>
<div id="log"></div>
<pre id="log"></pre>
<script type="text/javascript" src="../build/Three.js"></script>
......@@ -153,7 +153,7 @@
if ( render_gl ) {
try {
webglRenderer = new THREE.WebGLRenderer();
webglRenderer = new THREE.WebGLRenderer( scene );
webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
container.appendChild( webglRenderer.domElement );
has_gl = 1;
......
......@@ -15,7 +15,7 @@
h1 { }
a { color:skyblue }
canvas { pointer-events:none; z-index:10; position:relative; }
#log { position:absolute; top:0; display:block; text-align:left; z-index:1000 }
#log { position:absolute; top:0; display:block; text-align:left; z-index:1000; pointer-events:none; }
#d { text-align:center; margin:1em 0 -15.7em 0; z-index:0; position:relative; display:block }
.button { background:#000; color:#fff; padding:0.2em 0.5em; cursor:pointer }
.inactive { background:#999; color:#eee }
......@@ -170,7 +170,7 @@
if ( render_gl ) {
try {
webglRenderer = new THREE.WebGLRenderer();
webglRenderer = new THREE.WebGLRenderer( scene );
webglRenderer.setFaceCulling(0);
webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
container.appendChild( webglRenderer.domElement );
......@@ -283,7 +283,7 @@
}
function log(text) {
function log( text ) {
var e = document.getElementById("log");
e.innerHTML = text + "<br/>" + e.innerHTML;
......
......@@ -5,8 +5,12 @@
* parameters = {
* color: <hex>,
* map: new THREE.Texture( <Image> ),
* env_map: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
* combine: THREE.Multiply,
* reflectivity: <float>,
* refraction_ratio: <float>,
* opacity: <float>,
* shading: THREE.SmoothShading,
* blending: THREE.NormalBlending,
......@@ -21,8 +25,12 @@ THREE.MeshBasicMaterial = function ( parameters ) {
this.color = new THREE.Color( 0xeeeeee );
this.map = null;
this.env_map = null;
this.combine = THREE.Multiply;
this.reflectivity = 1;
this.refraction_ratio = 0.98;
this.opacity = 1;
this.shading = THREE.SmoothShading;
this.blending = THREE.NormalBlending;
......@@ -33,8 +41,12 @@ THREE.MeshBasicMaterial = function ( parameters ) {
if ( parameters.color !== undefined ) this.color.setHex( parameters.color );
if ( parameters.map !== undefined ) this.map = parameters.map;
if ( parameters.env_map !== undefined ) this.env_map = parameters.env_map;
if ( parameters.combine !== undefined ) this.combine = parameters.combine;
if ( parameters.reflectivity !== undefined ) this.reflectivity = parameters.reflectivity;
if ( parameters.refraction_ratio !== undefined ) this.refraction_ratio = parameters.refraction_ratio;
if ( parameters.opacity !== undefined ) this.opacity = parameters.opacity;
if ( parameters.shading !== undefined ) this.shading = parameters.shading;
if ( parameters.blending !== undefined ) this.blending = parameters.blending;
......@@ -49,8 +61,12 @@ THREE.MeshBasicMaterial = function ( parameters ) {
'id: ' + this.id + '<br/>' +
'color: ' + this.color + '<br/>' +
'map: ' + this.map + '<br/>' +
'env_map: ' + this.env_map + '<br/>' +
'combine: ' + this.combine + '<br/>' +
'reflectivity: ' + this.reflectivity + '<br/>' +
'refraction_ratio: ' + this.refraction_ratio + '<br/>' +
'opacity: ' + this.opacity + '<br/>' +
'blending: ' + this.blending + '<br/>' +
'wireframe: ' + this.wireframe + '<br/>' +
......
......@@ -5,8 +5,12 @@
* parameters = {
* color: <hex>,
* map: new THREE.Texture( <Image> ),
* env_map: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
* combine: THREE.Multiply,
* reflectivity: <float>,
* refraction_ratio: <float>,
* opacity: <float>,
* shading: THREE.SmoothShading,
* blending: THREE.NormalBlending,
......@@ -21,8 +25,12 @@ THREE.MeshLambertMaterial = function ( parameters ) {
this.color = new THREE.Color( 0xeeeeee );
this.map = null;
this.env_map = null;
this.combine = THREE.Multiply;
this.reflectivity = 1;
this.refraction_ratio = 0.98;
this.opacity = 1;
this.shading = THREE.SmoothShading;
this.blending = THREE.NormalBlending;
......@@ -33,8 +41,12 @@ THREE.MeshLambertMaterial = function ( parameters ) {
if ( parameters.color !== undefined ) this.color.setHex( parameters.color );
if ( parameters.map !== undefined ) this.map = parameters.map;
if ( parameters.env_map !== undefined ) this.env_map = parameters.env_map;
if ( parameters.combine !== undefined ) this.combine = parameters.combine;
if ( parameters.reflectivity !== undefined ) this.reflectivity = parameters.reflectivity;
if ( parameters.refraction_ratio !== undefined ) this.refraction_ratio = parameters.refraction_ratio;
if ( parameters.opacity !== undefined ) this.opacity = parameters.opacity;
if ( parameters.shading !== undefined ) this.shading = parameters.shading;
if ( parameters.blending !== undefined ) this.blending = parameters.blending;
......@@ -49,8 +61,12 @@ THREE.MeshLambertMaterial = function ( parameters ) {
'id: ' + this.id + '<br/>' +
'color: ' + this.color + '<br/>' +
'map: ' + this.map + '<br/>' +
'env_map: ' + this.env_map + '<br/>' +
'combine: ' + this.combine + '<br/>' +
'reflectivity: ' + this.reflectivity + '<br/>' +
'refraction_ratio: ' + this.refraction_ratio + '<br/>' +
'opacity: ' + this.opacity + '<br/>' +
'shading: ' + this.shading + '<br/>' +
'blending: ' + this.blending + '<br/>' +
......
......@@ -3,14 +3,19 @@
* @author alteredq / http://alteredqualia.com/
*
* parameters = {
* ambient: <hex>,
* color: <hex>,
* ambient: <hex>,
* specular: <hex>,
* shininess: <float>,
* map: new THREE.Texture( <Image> ),
* specular_map: new THREE.Texture( <Image> ),
* env_map: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
* shininess: <float>,
* combine: THREE.Multiply,
* reflectivity: <float>,
* refraction_ratio: <float>,
* opacity: <float>,
* shading: THREE.SmoothShading,
* blending: THREE.NormalBlending,
......@@ -24,13 +29,18 @@ THREE.MeshPhongMaterial = function ( parameters ) {
this.id = THREE.MeshPhongMaterialCounter.value ++;
this.color = new THREE.Color( 0xeeeeee );
this.map = null;
this.ambient = new THREE.Color( 0x050505 );
this.specular = new THREE.Color( 0x111111 );
this.shininess = 30;
this.map = null;
this.specular_map = null;
this.env_map = null;
this.shininess = 30;
this.combine = THREE.Multiply;
this.reflectivity = 1;
this.refraction_ratio = 0.98;
this.opacity = 1;
this.shading = THREE.SmoothShading;
this.blending = THREE.NormalBlending;
......@@ -40,13 +50,18 @@ THREE.MeshPhongMaterial = function ( parameters ) {
if ( parameters ) {
if ( parameters.color !== undefined ) this.color = new THREE.Color( parameters.color );
if ( parameters.map !== undefined ) this.map = parameters.map;
if ( parameters.ambient !== undefined ) this.ambient = new THREE.Color( parameters.ambient );
if ( parameters.specular !== undefined ) this.specular = new THREE.Color( parameters.specular );
if ( parameters.shininess !== undefined ) this.shininess = parameters.shininess;
if ( parameters.map !== undefined ) this.map = parameters.map;
if ( parameters.specular_map !== undefined ) this.specular_map = parameters.specular_map;
if ( parameters.env_map !== undefined ) this.env_map = parameters.env_map;
if ( parameters.shininess !== undefined ) this.shininess = parameters.shininess;
if ( parameters.combine !== undefined ) this.combine = parameters.combine;
if ( parameters.reflectivity !== undefined ) this.reflectivity = parameters.reflectivity;
if ( parameters.refraction_ratio !== undefined ) this.refraction_ratio = parameters.refraction_ratio;
if ( parameters.opacity !== undefined ) this.opacity = parameters.opacity;
if ( parameters.shading !== undefined ) this.shading = parameters.shading;
if ( parameters.blending !== undefined ) this.blending = parameters.blending;
......@@ -60,13 +75,18 @@ THREE.MeshPhongMaterial = function ( parameters ) {
return 'THREE.MeshPhongMaterial (<br/>' +
'id: ' + this.id + '<br/>' +
'color: ' + this.color + '<br/>' +
'map: ' + this.map + '<br/>' +
'env_map: ' + this.env_map + '<br/>' +
'ambient: ' + this.ambient + '<br/>' +
'specular: ' + this.specular + '<br/>' +
'specular_map: ' + this.specular_map + '<br/>' +
'shininess: ' + this.shininess + '<br/>' +
'map: ' + this.map + '<br/>' +
'specular_map: ' + this.specular_map + '<br/>' +
'env_map: ' + this.env_map + '<br/>' +
'combine: ' + this.combine + '<br/>' +
'reflectivity: ' + this.reflectivity + '<br/>' +
'refraction_ratio: ' + this.refraction_ratio + '<br/>' +
'opacity: ' + this.opacity + '<br/>' +
'shading: ' + this.shading + '<br/>' +
'wireframe: ' + this.wireframe + '<br/>' +
......
......@@ -22,3 +22,6 @@ THREE.Texture = function ( image, mapping ) {
THREE.UVMapping = 0;
THREE.ReflectionMap = 1;
THREE.RefractionMap = 2;
THREE.Multiply = 0;
THREE.Mix = 1;
......@@ -20,7 +20,7 @@ THREE.WebGLRenderer = function ( scene ) {
BASIC = 0, LAMBERT = 1, PHONG = 2, DEPTH = 3, NORMAL = 4, // material constants used in shader
maxLightCount = allocateLights( scene, 5 );
maxLightCount = allocateLights( scene, 4 );
this.domElement = _canvas;
this.autoClear = true;
......@@ -382,7 +382,8 @@ THREE.WebGLRenderer = function ( scene ) {
var mColor, mOpacity, mReflectivity,
mWireframe, mLineWidth, mBlending,
mAmbient, mSpecular, mShininess,
mMap, envMap;
mMap, envMap, mixEnvMap,
mRefractionRatio, useRefract;
if ( material instanceof THREE.MeshPhongMaterial ||
material instanceof THREE.MeshLambertMaterial ||
......@@ -390,7 +391,6 @@ THREE.WebGLRenderer = function ( scene ) {
mColor = material.color;
mOpacity = material.opacity;
mReflectivity = material.reflectivity;
mWireframe = material.wireframe;
mLineWidth = material.wireframe_linewidth;
......@@ -399,9 +399,21 @@ THREE.WebGLRenderer = function ( scene ) {
mMap = material.map;
envMap = material.env_map;
mixEnvMap = material.combine == THREE.Mix;
mReflectivity = material.reflectivity;
useRefract = material.env_map && material.env_map.mapping == THREE.RefractionMap;
mRefractionRatio = material.refraction_ratio;
_gl.uniform4f( _program.mColor, mColor.r * mOpacity, mColor.g * mOpacity, mColor.b * mOpacity, mOpacity );
_gl.uniform1i( _program.mixEnvMap, mixEnvMap );
_gl.uniform1f( _program.mReflectivity, mReflectivity );
_gl.uniform1i( _program.useRefract, useRefract );
_gl.uniform1f( _program.mRefractionRatio, mRefractionRatio );
}
if ( material instanceof THREE.MeshNormalMaterial ) {
......@@ -824,6 +836,7 @@ THREE.WebGLRenderer = function ( scene ) {
"uniform bool enableMap;",
"uniform bool enableCubeMap;",
"uniform bool mixEnvMap;",
"uniform samplerCube tCube;",
"uniform float mReflectivity;",
......@@ -874,7 +887,7 @@ THREE.WebGLRenderer = function ( scene ) {
"if ( enableCubeMap ) {",
"cubeColor = mReflectivity * textureCube( tCube, vReflect );",
"cubeColor = textureCube( tCube, vReflect );",
"}",
......@@ -909,7 +922,7 @@ THREE.WebGLRenderer = function ( scene ) {
maxPointLights ? "vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );" : "",
maxPointLights ? "vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );" : "",
maxPointLights ? "for( int i = 0; i < pointLightNumber; i++ ) {" : "",
maxPointLights ? "for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {" : "",
maxPointLights ? "vec3 pointVector = normalize( vPointLightVector[ i ] );" : "",
maxPointLights ? "vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );" : "",
......@@ -942,7 +955,7 @@ THREE.WebGLRenderer = function ( scene ) {
maxDirLights ? "vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );" : "",
maxDirLights ? "vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );" : "",
maxDirLights ? "for( int i = 0; i < directionalLightNumber; i++ ) {" : "",
maxDirLights ? "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {" : "",
maxDirLights ? "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );" : "",
......@@ -970,19 +983,43 @@ THREE.WebGLRenderer = function ( scene ) {
// looks nicer with weighting
"gl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );",
"if ( mixEnvMap ) {",
"gl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );",
"} else {",
"gl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );",
"}",
// Lambert: diffuse lighting
"} else if ( material == 1 ) {",
"gl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );",
"if ( mixEnvMap ) {",
"gl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );",
"} else {",
"gl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );",
"}",
// Basic: unlit color / texture
"} else {",
"gl_FragColor = mColor * mapColor * cubeColor;",
"if ( mixEnvMap ) {",
"gl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );",
"} else {",
"gl_FragColor = mColor * mapColor * cubeColor;",
"}",
"}",
......@@ -1006,6 +1043,7 @@ THREE.WebGLRenderer = function ( scene ) {
"uniform vec3 cameraPosition;",
"uniform bool enableLighting;",
"uniform bool useRefract;",
"uniform int pointLightNumber;",
"uniform int directionalLightNumber;",
......@@ -1034,6 +1072,7 @@ THREE.WebGLRenderer = function ( scene ) {
"varying vec3 vViewPosition;",
"varying vec3 vReflect;",
"uniform float mRefractionRatio;",
"void main(void) {",
......@@ -1061,7 +1100,7 @@ THREE.WebGLRenderer = function ( scene ) {
// directional lights
maxDirLights ? "for( int i = 0; i < directionalLightNumber; i++ ) {" : "",
maxDirLights ? "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {" : "",
maxDirLights ? "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );" : "",
maxDirLights ? "float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );" : "",
maxDirLights ? "vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;" : "",
......@@ -1069,7 +1108,7 @@ THREE.WebGLRenderer = function ( scene ) {
// point lights
maxPointLights ? "for( int i = 0; i < pointLightNumber; i++ ) {" : "",
maxPointLights ? "for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {" : "",
maxPointLights ? "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );" : "",
maxPointLights ? "vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );" : "",
maxPointLights ? "float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );" : "",
......@@ -1081,8 +1120,16 @@ THREE.WebGLRenderer = function ( scene ) {
"vNormal = transformedNormal;",
"vUv = uv;",
"vReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );",
"if ( useRefract ) {",
"vReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );",
"} else {",
"vReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );",
"}",
"gl_Position = projectionMatrix * mvPosition;",
"}" ];
......@@ -1107,8 +1154,8 @@ THREE.WebGLRenderer = function ( scene ) {
alert( "Could not initialise shaders" );
//alert( "VALIDATE_STATUS: " + _gl.getProgramParameter( _program, _gl.VALIDATE_STATUS ) );
//alert( _gl.getError() );
alert( "VALIDATE_STATUS: " + _gl.getProgramParameter( _program, _gl.VALIDATE_STATUS ) );
alert( _gl.getError() );
}
......@@ -1165,19 +1212,29 @@ THREE.WebGLRenderer = function ( scene ) {
// texture (diffuse map)
_program.enableMap = _gl.getUniformLocation( _program, "enableMap" );
_gl.uniform1i( _program.enableMap, 0 );
_gl.uniform1i( _program.enableMap, 0 );
_program.tMap = _gl.getUniformLocation( _program, "tMap" );
_gl.uniform1i( _program.tMap, 0 );
_gl.uniform1i( _program.tMap, 0 );
// cube texture
_program.enableCubeMap = _gl.getUniformLocation( _program, "enableCubeMap" );
_gl.uniform1i( _program.enableCubeMap, 0 );
_gl.uniform1i( _program.enableCubeMap, 0 );
_program.tCube = _gl.getUniformLocation( _program, "tCube" );
_gl.uniform1i( _program.tCube, 1 ); // it's important to use non-zero texture unit, otherwise it doesn't work
_gl.uniform1i( _program.tCube, 1 ); // it's important to use non-zero texture unit, otherwise it doesn't work
_program.mixEnvMap = _gl.getUniformLocation( _program, "mixEnvMap" );
_gl.uniform1i( _program.mixEnvMap, 0 );
// refraction
_program.mRefractionRatio = _gl.getUniformLocation( _program, 'mRefractionRatio' );
_program.useRefract = _gl.getUniformLocation( _program, "useRefract" );
_gl.uniform1i( _program.useRefract, 0 );
// material properties (Depth)
_program.m2Near = _gl.getUniformLocation( _program, 'm2Near' );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册