@@ -7,6 +7,7 @@ import { createShaderFromCode } from './program-lib/utils.js';
7
7
import { drawQuadWithShader } from './simple-post-effect.js' ;
8
8
import { shaderChunks } from './program-lib/chunks/chunks.js' ;
9
9
import { RenderTarget } from './render-target.js' ;
10
+ import { GraphicsDevice } from './graphics-device.js' ;
10
11
11
12
// get a coding string for texture based on its type and pixel format.
12
13
function getCoding ( texture ) {
@@ -48,15 +49,36 @@ function getProjectionName(projection) {
48
49
* function can read and write textures with pixel data in RGBE, RGBM, linear and sRGB formats. When
49
50
* specularPower is specified it will perform a phong-weighted convolution of the source (for generating
50
51
* a gloss maps).
51
- * @param {GraphicsDevice } device - The graphics device.
52
52
* @param {Texture } source - The source texture.
53
53
* @param {Texture } target - The target texture.
54
- * @param {number } [specularPower] - Optional specular power. When specular power is specified,
54
+ * @param {object } [options] - The options object.
55
+ * @param {number } [options.specularPower] - Optional specular power. When specular power is specified,
55
56
* the source is convolved by a phong-weighted kernel raised to the specified power. Otherwise
56
57
* the function performs a standard resample.
57
- * @param {number } [numSamples] - Optional number of samples (default is 1024).
58
+ * @param {number } [options.numSamples] - Optional number of samples (default is 1024).
59
+ * @param {number } [options.face] - Optional cubemap face to update (default is update all faces).
58
60
*/
59
- function reprojectTexture ( device , source , target , specularPower = 1 , numSamples = 1024 ) {
61
+ function reprojectTexture ( source , target , options = { } ) {
62
+ // maintain backwards compatibility with previous function signature
63
+ // reprojectTexture(device, source, target, specularPower = 1, numSamples = 1024)
64
+ if ( source instanceof GraphicsDevice ) {
65
+ source = arguments [ 1 ] ;
66
+ target = arguments [ 2 ] ;
67
+ options = {
68
+ specularPower : arguments [ 3 ] === undefined ? 1 : arguments [ 3 ] ,
69
+ numSamples : arguments [ 4 ] === undefined ? 1024 : arguments [ 4 ]
70
+ } ;
71
+ // #if _DEBUG
72
+ console . warn ( 'DEPRECATED: please use the updated pc.reprojectTexture API.' ) ;
73
+ // #endif
74
+ }
75
+
76
+ // extract options
77
+ const device = source . device ;
78
+ const specularPower = options . hasOwnProperty ( 'specularPower' ) ? options . specularPower : 1 ;
79
+ const numSamples = options . hasOwnProperty ( 'numSamples' ) ? options . numSamples : 1024 ;
80
+ const face = options . hasOwnProperty ( 'face' ) ? options . face : null ;
81
+
60
82
const processFunc = ( specularPower === 1 ) ? 'reproject' : 'prefilter' ;
61
83
const decodeFunc = "decode" + getCoding ( source ) ;
62
84
const encodeFunc = "encode" + getCoding ( target ) ;
@@ -91,23 +113,27 @@ function reprojectTexture(device, source, target, specularPower = 1, numSamples
91
113
constantSource . setValue ( source ) ;
92
114
93
115
const constantParams = device . scope . resolve ( "params" ) ;
94
- const params = new Float32Array ( 4 ) ;
95
- params [ 1 ] = specularPower ;
96
- params [ 2 ] = 1.0 - ( source . fixCubemapSeams ? 1.0 / source . width : 0.0 ) ; // source seam scale
97
- params [ 3 ] = 1.0 - ( target . fixCubemapSeams ? 1.0 / target . width : 0.0 ) ; // target seam scale
98
-
99
- for ( let face = 0 ; face < ( target . cubemap ? 6 : 1 ) ; face ++ ) {
100
- const renderTarget = new RenderTarget ( {
101
- colorBuffer : target ,
102
- face : face ,
103
- depth : false
104
- } ) ;
105
- params [ 0 ] = face ;
106
- constantParams . setValue ( params ) ;
107
-
108
- drawQuadWithShader ( device , renderTarget , shader ) ;
109
-
110
- renderTarget . destroy ( ) ;
116
+ const params = [
117
+ 0 ,
118
+ specularPower ,
119
+ 1.0 - ( source . fixCubemapSeams ? 1.0 / source . width : 0.0 ) , // source seam scale
120
+ 1.0 - ( target . fixCubemapSeams ? 1.0 / target . width : 0.0 ) // target seam scale
121
+ ] ;
122
+
123
+ for ( let f = 0 ; f < ( target . cubemap ? 6 : 1 ) ; f ++ ) {
124
+ if ( face === null || f === face ) {
125
+ const renderTarget = new RenderTarget ( {
126
+ colorBuffer : target ,
127
+ face : f ,
128
+ depth : false
129
+ } ) ;
130
+ params [ 0 ] = f ;
131
+ constantParams . setValue ( params ) ;
132
+
133
+ drawQuadWithShader ( device , renderTarget , shader ) ;
134
+
135
+ renderTarget . destroy ( ) ;
136
+ }
111
137
}
112
138
113
139
// #if _DEBUG
0 commit comments