@@ -1932,6 +1932,50 @@ export class Renderer3D extends Renderer {
19321932 return tex ;
19331933 }
19341934
1935+ _getSphereMapping ( img ) {
1936+ if ( ! this . sphereMapping ) {
1937+ const p5 = this . _pInst ;
1938+ this . sphereMapping = this . baseFilterShader ( ) . modify ( ( ) => {
1939+ const uEnvMap = p5 . uniformTexture ( ) ;
1940+ const uFovY = p5 . uniformFloat ( ) ;
1941+ const uAspect = p5 . uniformFloat ( ) ;
1942+ // Hack: we don't have matrix uniforms yet; use three vectors
1943+ const uN1 = p5 . uniformVec3 ( ) ;
1944+ const uN2 = p5 . uniformVec3 ( ) ;
1945+ const uN3 = p5 . uniformVec3 ( ) ;
1946+ p5 . getColor ( ( inputs ) => {
1947+ const uFovX = uFovY * uAspect ;
1948+ const angleY = p5 . mix ( uFovY / 2.0 , - uFovY / 2.0 , inputs . texCoord . y ) ;
1949+ const angleX = p5 . mix ( uFovX / 2.0 , - uFovX / 2.0 , inputs . texCoord . x ) ;
1950+ let rotatedNormal = p5 . normalize ( [ angleX , angleY , 1 ] ) ;
1951+ rotatedNormal = [
1952+ p5 . dot ( rotatedNormal , uN1 ) ,
1953+ p5 . dot ( rotatedNormal , uN2 ) ,
1954+ p5 . dot ( rotatedNormal , uN3 ) ,
1955+ ] ;
1956+ const temp = rotatedNormal . z ;
1957+ rotatedNormal . z = rotatedNormal . x ;
1958+ rotatedNormal . x = - temp ;
1959+ const suv = [
1960+ 0.5 + 0.5 * ( - rotatedNormal . y ) ,
1961+ p5 . atan ( rotatedNormal . z , rotatedNormal . x ) / ( 2.0 * p5 . PI ) + 0.5
1962+ ] ;
1963+ return p5 . getTexture ( uEnvMap , suv ) ;
1964+ } )
1965+ } , { p5 } ) ;
1966+ }
1967+ this . scratchMat3 . inverseTranspose4x4 ( this . states . uViewMatrix ) ;
1968+ this . scratchMat3 . invert ( this . scratchMat3 ) ; // uNMMatrix is 3x3
1969+ this . sphereMapping . setUniform ( "uFovY" , this . states . curCamera . cameraFOV ) ;
1970+ 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 ) ) ;
1975+ this . sphereMapping . setUniform ( "uEnvMap" , img ) ;
1976+ return this . sphereMapping ;
1977+ }
1978+
19351979 /*
19361980 * Abstract methods to be implemented by specific renderers
19371981 */
0 commit comments