Skip to content

Commit 51423cd

Browse files
mvaligurskyMartin Valigursky
andauthored
CoreExporter image transformation uses WGSL shader on WebGPU (#7623)
Co-authored-by: Martin Valigursky <[email protected]>
1 parent 7a0fb0a commit 51423cd

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/extras/exporters/core-exporter.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,17 @@ import { Texture } from '../../platform/graphics/texture.js';
33
import { BlendState } from '../../platform/graphics/blend-state.js';
44
import { drawQuadWithShader } from '../../scene/graphics/quad-render-utils.js';
55
import { RenderTarget } from '../../platform/graphics/render-target.js';
6-
import { FILTER_LINEAR, ADDRESS_CLAMP_TO_EDGE, isCompressedPixelFormat, PIXELFORMAT_RGBA8 } from '../../platform/graphics/constants.js';
6+
import {
7+
FILTER_LINEAR, ADDRESS_CLAMP_TO_EDGE, isCompressedPixelFormat, PIXELFORMAT_RGBA8,
8+
SEMANTIC_POSITION, SHADERLANGUAGE_WGSL, SHADERLANGUAGE_GLSL
9+
} from '../../platform/graphics/constants.js';
10+
import { shaderChunks } from '../../scene/shader-lib/chunks/chunks.js';
11+
import { shaderChunksWGSL } from '../../scene/shader-lib/chunks-wgsl/chunks-wgsl.js';
712

813
/**
914
* @import { Color } from '../../core/math/color.js'
1015
*/
1116

12-
const textureBlitVertexShader = /* glsl */`
13-
attribute vec2 vertex_position;
14-
varying vec2 uv0;
15-
void main(void) {
16-
gl_Position = vec4(vertex_position, 0.5, 1.0);
17-
uv0 = vertex_position.xy * 0.5 + 0.5;
18-
}`;
19-
20-
const textureBlitFragmentShader = /* glsl */`
21-
varying vec2 uv0;
22-
uniform sampler2D blitTexture;
23-
void main(void) {
24-
gl_FragColor = texture2D(blitTexture, uv0);
25-
}`;
26-
2717
/**
2818
* The base class for the exporters, implementing shared functionality.
2919
*
@@ -113,8 +103,14 @@ class CoreExporter {
113103
});
114104

115105
// render to a render target using a blit shader
116-
const shader = createShaderFromCode(device, textureBlitVertexShader, textureBlitFragmentShader, 'ShaderCoreExporterBlit');
117-
device.scope.resolve('blitTexture').setValue(texture);
106+
const shader = device.isWebGPU ?
107+
createShaderFromCode(device, shaderChunksWGSL.fullscreenQuadVS, shaderChunksWGSL.outputTex2DPS, 'ShaderCoreExporterBlit',
108+
{ vertex_position: SEMANTIC_POSITION }, { shaderLanguage: SHADERLANGUAGE_WGSL }
109+
) :
110+
createShaderFromCode(device, shaderChunks.fullscreenQuadVS, shaderChunks.outputTex2DPS, 'ShaderCoreExporterBlit',
111+
{ vertex_position: SEMANTIC_POSITION }, { shaderLanguage: SHADERLANGUAGE_GLSL }
112+
);
113+
device.scope.resolve('source').setValue(texture);
118114
device.setBlendState(BlendState.NOBLEND);
119115
drawQuadWithShader(device, renderTarget, shader);
120116

0 commit comments

Comments
 (0)