|
@@ -11,10 +11,11 @@
|
|
* by this class.
|
|
* by this class.
|
|
*/
|
|
*/
|
|
|
|
|
|
-THREE.PMREMGenerator = function( sourceTexture ) {
|
|
|
|
|
|
+THREE.PMREMGenerator = function( sourceTexture, samplesPerLevel, resolution ) {
|
|
|
|
|
|
this.sourceTexture = sourceTexture;
|
|
this.sourceTexture = sourceTexture;
|
|
- this.resolution = 256; // NODE: 256 is currently hard coded in the glsl code for performance reasons
|
|
|
|
|
|
+ this.resolution = ( resolution !== undefined ) ? resolution : 256; // NODE: 256 is currently hard coded in the glsl code for performance reasons
|
|
|
|
+ this.samplesPerLevel = ( samplesPerLevel !== undefined ) ? samplesPerLevel : 16;
|
|
|
|
|
|
var monotonicEncoding = ( sourceTexture.encoding === THREE.LinearEncoding ) ||
|
|
var monotonicEncoding = ( sourceTexture.encoding === THREE.LinearEncoding ) ||
|
|
( sourceTexture.encoding === THREE.GammaEncoding ) || ( sourceTexture.encoding === THREE.sRGBEncoding );
|
|
( sourceTexture.encoding === THREE.GammaEncoding ) || ( sourceTexture.encoding === THREE.sRGBEncoding );
|
|
@@ -37,11 +38,12 @@ THREE.PMREMGenerator = function( sourceTexture ) {
|
|
};
|
|
};
|
|
|
|
|
|
// how many LODs fit in the given CubeUV Texture.
|
|
// how many LODs fit in the given CubeUV Texture.
|
|
- this.numLods = Math.log2( size ) - 2;
|
|
|
|
|
|
+ this.numLods = Math.log( size ) / Math.log( 2 ) - 2; // IE11 doesn't support Math.log2
|
|
|
|
|
|
for ( var i = 0; i < this.numLods; i ++ ) {
|
|
for ( var i = 0; i < this.numLods; i ++ ) {
|
|
|
|
|
|
var renderTarget = new THREE.WebGLRenderTargetCube( size, size, params );
|
|
var renderTarget = new THREE.WebGLRenderTargetCube( size, size, params );
|
|
|
|
+ renderTarget.texture.name = "PMREMGenerator.cube" + i;
|
|
this.cubeLods.push( renderTarget );
|
|
this.cubeLods.push( renderTarget );
|
|
size = Math.max( 16, size / 2 );
|
|
size = Math.max( 16, size / 2 );
|
|
|
|
|
|
@@ -50,6 +52,7 @@ THREE.PMREMGenerator = function( sourceTexture ) {
|
|
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0.0, 1000 );
|
|
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0.0, 1000 );
|
|
|
|
|
|
this.shader = this.getShader();
|
|
this.shader = this.getShader();
|
|
|
|
+ this.shader.defines['SAMPLES_PER_LEVEL'] = this.samplesPerLevel;
|
|
this.planeMesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2, 0 ), this.shader );
|
|
this.planeMesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2, 0 ), this.shader );
|
|
this.planeMesh.material.side = THREE.DoubleSide;
|
|
this.planeMesh.material.side = THREE.DoubleSide;
|
|
this.scene = new THREE.Scene();
|
|
this.scene = new THREE.Scene();
|
|
@@ -97,6 +100,7 @@ THREE.PMREMGenerator.prototype = {
|
|
|
|
|
|
var r = i / ( this.numLods - 1 );
|
|
var r = i / ( this.numLods - 1 );
|
|
this.shader.uniforms[ 'roughness' ].value = r * 0.9; // see comment above, pragmatic choice
|
|
this.shader.uniforms[ 'roughness' ].value = r * 0.9; // see comment above, pragmatic choice
|
|
|
|
+ this.shader.uniforms[ 'queryScale' ].value.x = ( i == 0 ) ? -1 : 1;
|
|
var size = this.cubeLods[ i ].width;
|
|
var size = this.cubeLods[ i ].width;
|
|
this.shader.uniforms[ 'mapSize' ].value = size;
|
|
this.shader.uniforms[ 'mapSize' ].value = size;
|
|
this.renderToCubeMapTarget( renderer, this.cubeLods[ i ] );
|
|
this.renderToCubeMapTarget( renderer, this.cubeLods[ i ] );
|
|
@@ -134,12 +138,17 @@ THREE.PMREMGenerator.prototype = {
|
|
|
|
|
|
return new THREE.ShaderMaterial( {
|
|
return new THREE.ShaderMaterial( {
|
|
|
|
|
|
|
|
+ defines: {
|
|
|
|
+ "SAMPLES_PER_LEVEL": 20,
|
|
|
|
+ },
|
|
|
|
+
|
|
uniforms: {
|
|
uniforms: {
|
|
"faceIndex": { value: 0 },
|
|
"faceIndex": { value: 0 },
|
|
"roughness": { value: 0.5 },
|
|
"roughness": { value: 0.5 },
|
|
"mapSize": { value: 0.5 },
|
|
"mapSize": { value: 0.5 },
|
|
"envMap": { value: null },
|
|
"envMap": { value: null },
|
|
- "testColor": { value: new THREE.Vector3( 1, 1, 1 ) }
|
|
|
|
|
|
+ "queryScale": { value: new THREE.Vector3( 1, 1, 1 ) },
|
|
|
|
+ "testColor": { value: new THREE.Vector3( 1, 1, 1 ) },
|
|
},
|
|
},
|
|
|
|
|
|
vertexShader:
|
|
vertexShader:
|
|
@@ -157,6 +166,7 @@ THREE.PMREMGenerator.prototype = {
|
|
uniform samplerCube envMap;\n\
|
|
uniform samplerCube envMap;\n\
|
|
uniform float mapSize;\n\
|
|
uniform float mapSize;\n\
|
|
uniform vec3 testColor;\n\
|
|
uniform vec3 testColor;\n\
|
|
|
|
+ uniform vec3 queryScale;\n\
|
|
\n\
|
|
\n\
|
|
float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\
|
|
float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\
|
|
float a = ggxRoughness + 0.0001;\n\
|
|
float a = ggxRoughness + 0.0001;\n\
|
|
@@ -227,12 +237,12 @@ THREE.PMREMGenerator.prototype = {
|
|
} else {\n\
|
|
} else {\n\
|
|
sampleDirection = vec3(-uv.x, -uv.y, -1.0);\n\
|
|
sampleDirection = vec3(-uv.x, -uv.y, -1.0);\n\
|
|
}\n\
|
|
}\n\
|
|
- mat3 vecSpace = matrixFromVector(normalize(sampleDirection));\n\
|
|
|
|
|
|
+ mat3 vecSpace = matrixFromVector(normalize(sampleDirection * queryScale));\n\
|
|
vec3 rgbColor = vec3(0.0);\n\
|
|
vec3 rgbColor = vec3(0.0);\n\
|
|
- const int NumSamples = 1024;\n\
|
|
|
|
|
|
+ const int NumSamples = SAMPLES_PER_LEVEL;\n\
|
|
vec3 vect;\n\
|
|
vec3 vect;\n\
|
|
float weight = 0.0;\n\
|
|
float weight = 0.0;\n\
|
|
- for(int i=0; i<NumSamples; i++) {\n\
|
|
|
|
|
|
+ for( int i = 0; i < NumSamples; i ++ ) {\n\
|
|
float sini = sin(float(i));\n\
|
|
float sini = sin(float(i));\n\
|
|
float cosi = cos(float(i));\n\
|
|
float cosi = cos(float(i));\n\
|
|
float r = rand(vec2(sini, cosi));\n\
|
|
float r = rand(vec2(sini, cosi));\n\
|