Skip to content

Commit d076f26

Browse files
mvaligurskyMartin Valigursky
and
Martin Valigursky
authored
WGSL version of outputTex2DPS chunk used by outline-renderer (#7613)
* WGSL version of outputTex2DPS chunk used by outline-renderer * shadow catcher fix --------- Co-authored-by: Martin Valigursky <[email protected]>
1 parent a9c32f2 commit d076f26

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/extras/renderers/outline-renderer.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { BlendState } from '../../platform/graphics/blend-state.js';
44
import {
55
ADDRESS_CLAMP_TO_EDGE, BLENDEQUATION_ADD, BLENDMODE_ONE_MINUS_SRC_ALPHA, BLENDMODE_SRC_ALPHA,
66
CULLFACE_NONE,
7-
FILTER_LINEAR, FILTER_LINEAR_MIPMAP_LINEAR, PIXELFORMAT_SRGBA8
7+
FILTER_LINEAR, FILTER_LINEAR_MIPMAP_LINEAR, PIXELFORMAT_SRGBA8,
8+
SEMANTIC_POSITION,
9+
SHADERLANGUAGE_GLSL,
10+
SHADERLANGUAGE_WGSL
811
} from '../../platform/graphics/constants.js';
912
import { DepthState } from '../../platform/graphics/depth-state.js';
1013
import { RenderTarget } from '../../platform/graphics/render-target.js';
@@ -13,6 +16,7 @@ import { drawQuadWithShader } from '../../scene/graphics/quad-render-utils.js';
1316
import { QuadRender } from '../../scene/graphics/quad-render.js';
1417
import { StandardMaterialOptions } from '../../scene/materials/standard-material-options.js';
1518
import { StandardMaterial } from '../../scene/materials/standard-material.js';
19+
import { shaderChunksWGSL } from '../../scene/shader-lib/chunks-wgsl/chunks-wgsl.js';
1620
import { shaderChunks } from '../../scene/shader-lib/chunks/chunks.js';
1721
import { createShaderFromCode } from '../../scene/shader-lib/utils.js';
1822

@@ -114,7 +118,12 @@ class OutlineRenderer {
114118

115119
const device = this.app.graphicsDevice;
116120
this.shaderExtend = createShaderFromCode(device, shaderChunks.fullscreenQuadVS, shaderOutlineExtendPS, 'OutlineExtendShader');
117-
this.shaderBlend = createShaderFromCode(device, shaderChunks.fullscreenQuadVS, shaderChunks.outputTex2DPS, 'OutlineBlendShader');
121+
122+
this.shaderBlend = device.isWebGPU ?
123+
createShaderFromCode(device, shaderChunksWGSL.fullscreenQuadVS, shaderChunksWGSL.outputTex2DPS, 'OutlineBlendShader',
124+
{ vertex_position: SEMANTIC_POSITION }, { shaderLanguage: SHADERLANGUAGE_WGSL }) :
125+
createShaderFromCode(device, shaderChunks.fullscreenQuadVS, shaderChunks.outputTex2DPS, 'OutlineBlendShader',
126+
{ vertex_position: SEMANTIC_POSITION }, { shaderLanguage: SHADERLANGUAGE_GLSL });
118127

119128
this.quadRenderer = new QuadRender(this.shaderBlend);
120129

src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import opacityPS from './standard/frag/opacity.js';
9595
import opacityDitherPS from './standard/frag/opacity-dither.js';
9696
import outputPS from './lit/frag/output.js';
9797
import outputAlphaPS from './lit/frag/outputAlpha.js';
98-
// import outputTex2DPS from './common/frag/outputTex2D.js';
98+
import outputTex2DPS from './common/frag/outputTex2D.js';
9999
import sheenPS from './standard/frag/sheen.js';
100100
import sheenGlossPS from './standard/frag/sheenGloss.js';
101101
import parallaxPS from './standard/frag/parallax.js';
@@ -304,7 +304,7 @@ const shaderChunksWGSL = {
304304
opacityDitherPS,
305305
outputPS,
306306
outputAlphaPS,
307-
// outputTex2DPS,
307+
outputTex2DPS,
308308
sheenPS,
309309
sheenGlossPS,
310310
parallaxPS,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default /* wgsl */`
2+
varying vUv0: vec2f;
3+
var source: texture_2d<f32>;
4+
var sourceSampler: sampler;
5+
6+
@fragment fn fragmentMain(input : FragmentInput) -> FragmentOutput {
7+
var output: FragmentOutput;
8+
output.color = textureSample(source, sourceSampler, input.vUv0);
9+
return output;
10+
}
11+
`;

src/scene/shader-lib/chunks-wgsl/lit/frag/pass-forward/litForwardBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn evaluateBackend() -> FragmentOutput {
234234
235235
#ifdef LIT_SHADOW_CATCHER
236236
// output when the shadow catcher is enabled - accumulated shadows
237-
output.color = vec4f(dShadowCatcher, output.color.a);
237+
output.color = vec4f(vec3f(dShadowCatcher), output.color.a);
238238
#endif
239239
240240
return output;

0 commit comments

Comments
 (0)