@@ -1644,6 +1644,9 @@ export class Renderer3D extends Renderer {
16441644 let specularLight = this . getSpecularTexture ( this . states . activeImageLight ) ;
16451645
16461646 shader . setUniform ( "environmentMapSpecular" , specularLight ) ;
1647+ } else {
1648+ shader . setUniform ( "environmentMapDiffused" , this . _getEmptyTexture ( ) ) ;
1649+ shader . setUniform ( "environmentMapSpecular" , this . _getEmptyTexture ( ) ) ;
16471650 }
16481651 }
16491652
@@ -1830,7 +1833,7 @@ export class Renderer3D extends Renderer {
18301833 * an angle to each pixel. This creates and caches textures for reuse, since
18311834 * creating this texture is somewhat expensive.
18321835 */
1833- getDiffusedTexture ( input ) {
1836+ makeDiffusedTexture ( input ) {
18341837 // if one already exists for a given input image
18351838 if ( this . diffusedTextures . get ( input ) != null ) {
18361839 return this . diffusedTextures . get ( input ) ;
@@ -1861,6 +1864,9 @@ export class Renderer3D extends Renderer {
18611864 this . diffusedTextures . set ( input , newFramebuffer ) ;
18621865 return newFramebuffer ;
18631866 }
1867+ getDiffusedTexture ( input ) {
1868+ return this . diffusedTextures . get ( input ) ;
1869+ }
18641870
18651871 /*
18661872 * used in imageLight,
@@ -1871,7 +1877,7 @@ export class Renderer3D extends Renderer {
18711877 * Storing the texture for input image in map called `specularTextures`
18721878 * maps the input Image to a p5.MipmapTexture
18731879 */
1874- getSpecularTexture ( input ) {
1880+ makeSpecularTexture ( input ) {
18751881 // check if already exits (there are tex of diff resolution so which one to check)
18761882 // currently doing the whole array
18771883 if ( this . specularTextures . get ( input ) != null ) {
@@ -1931,6 +1937,9 @@ export class Renderer3D extends Renderer {
19311937 this . specularTextures . set ( input , tex ) ;
19321938 return tex ;
19331939 }
1940+ getSpecularTexture ( input ) {
1941+ return this . specularTextures . get ( input ) ;
1942+ }
19341943
19351944 _getSphereMapping ( img ) {
19361945 if ( ! this . sphereMapping ) {
@@ -1949,6 +1958,7 @@ export class Renderer3D extends Renderer {
19491958 const angleX = p5 . mix ( uFovX / 2.0 , - uFovX / 2.0 , inputs . texCoord . x ) ;
19501959 let rotatedNormal = p5 . normalize ( [ angleX , angleY , 1 ] ) ;
19511960 rotatedNormal = [
1961+ // Don't mind me, just doing matrix vector multiplication...
19521962 p5 . dot ( rotatedNormal , uN1 ) ,
19531963 p5 . dot ( rotatedNormal , uN2 ) ,
19541964 p5 . dot ( rotatedNormal , uN3 ) ,
@@ -1957,8 +1967,8 @@ export class Renderer3D extends Renderer {
19571967 rotatedNormal . z = rotatedNormal . x ;
19581968 rotatedNormal . x = - temp ;
19591969 const suv = [
1960- 0.5 + 0.5 * ( - rotatedNormal . y ) ,
1961- p5 . atan ( rotatedNormal . z , rotatedNormal . x ) / ( 2.0 * p5 . PI ) + 0.5
1970+ p5 . atan ( rotatedNormal . z , rotatedNormal . x ) / ( 2.0 * p5 . PI ) + 0.5 ,
1971+ 0.5 + 0.5 * ( - rotatedNormal . y )
19621972 ] ;
19631973 return p5 . getTexture ( uEnvMap , suv ) ;
19641974 } )
@@ -1968,10 +1978,12 @@ export class Renderer3D extends Renderer {
19681978 this . scratchMat3 . invert ( this . scratchMat3 ) ; // uNMMatrix is 3x3
19691979 this . sphereMapping . setUniform ( "uFovY" , this . states . curCamera . cameraFOV ) ;
19701980 this . sphereMapping . setUniform ( "uAspect" , this . states . curCamera . aspectRatio ) ;
1971- // this.sphereMapping.setUniform("uNewNormalMatrix", this.scratchMat3.mat3);
1972- this . sphereMapping . setUniform ( "uN1" , this . scratchMat3 . mat3 . slice ( 0 , 3 ) ) ;
1973- this . sphereMapping . setUniform ( "uN2" , this . scratchMat3 . mat3 . slice ( 3 , 6 ) ) ;
1974- this . sphereMapping . setUniform ( "uN3" , this . scratchMat3 . mat3 . slice ( 6 ) ) ;
1981+ // Pass in the normal matrix as three vectors. TODO replace this with
1982+ // an actual matrix uniform once we have those again.
1983+ const m = this . scratchMat3 . mat3 ;
1984+ this . sphereMapping . setUniform ( "uN1" , [ m [ 0 ] , m [ 3 ] , m [ 6 ] ] ) ;
1985+ this . sphereMapping . setUniform ( "uN2" , [ m [ 1 ] , m [ 4 ] , m [ 7 ] ] ) ;
1986+ this . sphereMapping . setUniform ( "uN3" , [ m [ 2 ] , m [ 5 ] , m [ 8 ] ] ) ;
19751987 this . sphereMapping . setUniform ( "uEnvMap" , img ) ;
19761988 return this . sphereMapping ;
19771989 }
0 commit comments