Skip to content

Commit 16bd562

Browse files
mvaligurskyMartin Valigurskywilleastcott
authored
[BREAKING] Deprecated pc.createShader and pc.createShaderFromCode (playcanvas#7657)
* [BREAKING] Deprecated pc.createShader and pc.createShaderFromCode * lint imports * Update src/scene/shader-lib/shader-utils.js Co-authored-by: Will Eastcott <will@playcanvas.com> --------- Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com> Co-authored-by: Will Eastcott <will@playcanvas.com>
1 parent d69f4d7 commit 16bd562

33 files changed

Lines changed: 479 additions & 388 deletions

‎examples/src/examples/graphics/integer-textures.example.mjs‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,31 +127,29 @@ const outputRenderTarget = createPixelRenderTarget(2, outputTexture);
127127

128128
// This is shader runs the sand simulation
129129
// It uses integer textures to store the state of each pixel
130-
const sandShader = pc.createShaderFromCode(
131-
device,
132-
pc.RenderPassShaderQuad.quadVertexShader,
133-
files['sandSimulation.frag'],
134-
'SandShader',
135-
{ aPosition: pc.SEMANTIC_POSITION },
130+
const sandShader = pc.ShaderUtils.createShader(device, {
131+
uniqueName: 'SandShader',
132+
attributes: { aPosition: pc.SEMANTIC_POSITION },
133+
vertexGLSL: pc.RenderPassShaderQuad.quadVertexShader,
134+
fragmentGLSL: files['sandSimulation.frag'],
136135
// Note that we are changing the shader output type to 'uint'
137136
// This means we only have to return a single integer value from the shader,
138137
// whereas the default is to return a vec4. This option allows you to pass
139138
// an array of types to specify the output type for each color attachment.
140139
// Unspecified types are assumed to be 'vec4'.
141-
{ fragmentOutputTypes: ['uint'] }
142-
);
140+
fragmentOutputTypes: ['uint']
141+
});
143142

144143
// This shader reads the integer textures
145144
// and renders a visual representation of the simulation
146-
const outputShader = pc.createShaderFromCode(
147-
device,
148-
pc.RenderPassShaderQuad.quadVertexShader,
149-
files['renderOutput.frag'],
150-
'RenderOutputShader',
151-
{ aPosition: pc.SEMANTIC_POSITION }
145+
const outputShader = pc.ShaderUtils.createShader(device, {
146+
uniqueName: 'RenderOutputShader',
147+
attributes: { aPosition: pc.SEMANTIC_POSITION },
148+
vertexGLSL: pc.RenderPassShaderQuad.quadVertexShader,
149+
fragmentGLSL: files['renderOutput.frag']
152150
// For the output shader, we don't need to specify the output type,
153151
// as we are returning a vec4 by default.
154-
);
152+
});
155153

156154
// Write the initial simulation state to the integer texture
157155
const resetData = () => {

‎scripts/posteffects/posteffect-blend.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ function BlendEffect(graphicsDevice) {
2727
'}'
2828
].join('\n');
2929

30-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'BlendShader', {
31-
aPosition: pc.SEMANTIC_POSITION
30+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
31+
uniqueName: 'BlendShader',
32+
attributes: { aPosition: pc.SEMANTIC_POSITION },
33+
vertexGLSL: pc.PostEffect.quadVertexShader,
34+
fragmentGLSL: fshader
3235
});
3336

3437
// Uniforms

‎scripts/posteffects/posteffect-bloom.js‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,26 @@ function BloomEffect(graphicsDevice) {
137137
'}'
138138
].join('\n');
139139

140-
this.extractShader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, extractFrag, 'BloomExtractShader', attributes);
141-
this.blurShader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, gaussianBlurFrag, 'BloomBlurShader', attributes);
142-
this.combineShader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, combineFrag, 'BloomCombineShader', attributes);
140+
this.extractShader = pc.ShaderUtils.createShader(graphicsDevice, {
141+
uniqueName: 'BloomExtractShader',
142+
attributes: attributes,
143+
vertexGLSL: pc.PostEffect.quadVertexShader,
144+
fragmentGLSL: extractFrag
145+
});
146+
147+
this.blurShader = pc.ShaderUtils.createShader(graphicsDevice, {
148+
uniqueName: 'BloomBlurShader',
149+
attributes: attributes,
150+
vertexGLSL: pc.PostEffect.quadVertexShader,
151+
fragmentGLSL: gaussianBlurFrag
152+
});
153+
154+
this.combineShader = pc.ShaderUtils.createShader(graphicsDevice, {
155+
uniqueName: 'BloomCombineShader',
156+
attributes: attributes,
157+
vertexGLSL: pc.PostEffect.quadVertexShader,
158+
fragmentGLSL: combineFrag
159+
});
143160

144161
this.targets = [];
145162

‎scripts/posteffects/posteffect-bokeh.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ function BokehEffect(graphicsDevice) {
9696
'}'
9797
].join('\n');
9898

99-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'BokehShader', {
100-
aPosition: pc.SEMANTIC_POSITION
99+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
100+
uniqueName: 'BokehShader',
101+
attributes: { aPosition: pc.SEMANTIC_POSITION },
102+
vertexGLSL: pc.PostEffect.quadVertexShader,
103+
fragmentGLSL: fshader
101104
});
102105

103106
// Uniforms

‎scripts/posteffects/posteffect-brightnesscontrast.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ function BrightnessContrastEffect(graphicsDevice) {
3232
'}'
3333
].join('\n');
3434

35-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'BrightnessContrastShader', {
36-
aPosition: pc.SEMANTIC_POSITION
35+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
36+
uniqueName: 'BrightnessContrastShader',
37+
attributes: { aPosition: pc.SEMANTIC_POSITION },
38+
vertexGLSL: pc.PostEffect.quadVertexShader,
39+
fragmentGLSL: fshader
3740
});
3841

3942
// Uniforms

‎scripts/posteffects/posteffect-edgedetect.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ function EdgeDetectEffect(graphicsDevice) {
5252
'}'
5353
].join('\n');
5454

55-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'EdgeDetectShader', {
56-
aPosition: pc.SEMANTIC_POSITION
55+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
56+
uniqueName: 'EdgeDetectShader',
57+
attributes: { aPosition: pc.SEMANTIC_POSITION },
58+
vertexGLSL: pc.PostEffect.quadVertexShader,
59+
fragmentGLSL: fshader
5760
});
5861

5962
// Uniforms

‎scripts/posteffects/posteffect-fxaa.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ function FxaaEffect(graphicsDevice) {
7070
'}'
7171
].join('\n');
7272

73-
this.fxaaShader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fxaaFrag, 'FxaaShader', {
74-
aPosition: pc.SEMANTIC_POSITION
73+
this.fxaaShader = pc.ShaderUtils.createShader(graphicsDevice, {
74+
uniqueName: 'FxaaShader',
75+
attributes: { aPosition: pc.SEMANTIC_POSITION },
76+
vertexGLSL: pc.PostEffect.quadVertexShader,
77+
fragmentGLSL: fxaaFrag
7578
});
7679

7780
// Uniforms

‎scripts/posteffects/posteffect-horizontaltiltshift.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ function HorizontalTiltShiftEffect(graphicsDevice) {
3737
'}'
3838
].join('\n');
3939

40-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'HorizontalTiltShiftShader', {
41-
aPosition: pc.SEMANTIC_POSITION
40+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
41+
uniqueName: 'HorizontalTiltShiftShader',
42+
attributes: { aPosition: pc.SEMANTIC_POSITION },
43+
vertexGLSL: pc.PostEffect.quadVertexShader,
44+
fragmentGLSL: fshader
4245
});
4346

4447
// uniforms

‎scripts/posteffects/posteffect-huesaturation.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ function HueSaturationEffect(graphicsDevice) {
4444
'}'
4545
].join('\n');
4646

47-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'HueSaturationShader', {
48-
aPosition: pc.SEMANTIC_POSITION
47+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
48+
uniqueName: 'HueSaturationShader',
49+
attributes: { aPosition: pc.SEMANTIC_POSITION },
50+
vertexGLSL: pc.PostEffect.quadVertexShader,
51+
fragmentGLSL: fshader
4952
});
5053

5154
// uniforms

‎scripts/posteffects/posteffect-luminosity.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ function LuminosityEffect(graphicsDevice) {
2323
'}'
2424
].join('\n');
2525

26-
this.shader = pc.createShaderFromCode(graphicsDevice, pc.PostEffect.quadVertexShader, fshader, 'LuminosityShader', {
27-
aPosition: pc.SEMANTIC_POSITION
26+
this.shader = pc.ShaderUtils.createShader(graphicsDevice, {
27+
uniqueName: 'LuminosityShader',
28+
attributes: { aPosition: pc.SEMANTIC_POSITION },
29+
vertexGLSL: pc.PostEffect.quadVertexShader,
30+
fragmentGLSL: fshader
2831
});
2932
}
3033

0 commit comments

Comments
 (0)