Skip to content

Commit bf3041d

Browse files
Add Shader#setUniform and ShaderQuadConfig#initialUniforms.
1 parent 14df322 commit bf3041d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

changelog/4.0/CHANGELOG-v4.0-rc.2.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Updates since RC1:
55
## New Features
66

77
- `RenderConfig#renderNodes` allows you to add render nodes at game boot.
8+
- `ShaderQuadConfig#initialUniforms` lets you initialize a Shader with uniforms on creation.
9+
- `Shader#setUniform(name, value)` lets you set shader program uniforms just once, instead of putting them all into the `setupUniforms()` method, where some uniforms might be set redundantly after init. This wraps `Shader#renderNode.programManager.setUniform`.
810

911
## Changes
1012

@@ -17,3 +19,5 @@ Updates since RC1:
1719
- Add typedefs for the `{ internal, external }` structure of `Camera#filters` (and `GameObject#filters`).
1820
- Fix `FilterList#addMask` docs.
1921
- In Layer and Container objects, use that object's children for the `displayList` passed to `RenderWebGLSteps`.
22+
- Fix positioning of Group members and offset objects in `DynamicTexture#draw`.
23+
- Fix Shadow filter direction.

src/gameobjects/shader/Shader.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ var Shader = new Class({
157157
this.renderNode.updateShaderConfig = config.updateShaderConfig;
158158
}
159159

160+
var initialUniforms = GetFastValue(config, 'initialUniforms', {});
161+
Object.entries(initialUniforms).forEach(function (entry)
162+
{
163+
this.setUniform(entry[0], entry[1]);
164+
}, this);
165+
160166
/**
161167
* The drawing context containing the framebuffer and texture that the shader is rendered to.
162168
* This is only set if the shader is rendering to a texture.
@@ -255,7 +261,7 @@ var Shader = new Class({
255261
* will modify the original.
256262
*
257263
* It's generally better to use the `setupUniforms` function in the
258-
* shader configuration object to set the uniform values.
264+
* shader configuration object to set uniform values on changing uniforms.
259265
* This method is provided in the spirit of reading back the values.
260266
*
261267
* @method Phaser.GameObjects.Shader#getUniform
@@ -268,6 +274,26 @@ var Shader = new Class({
268274
return this.renderNode.programManager.uniforms[name];
269275
},
270276

277+
/**
278+
* Set the value of a uniform in the shader.
279+
* This value is actually copied to all shaders that use it.
280+
*
281+
* It's generally better to use the `setupUniforms` function in the
282+
* shader configuration object to set uniform values on changing uniforms.
283+
* Use this method to set uniforms just once.
284+
*
285+
* @method Phaser.GameObjects.Shader#setUniform
286+
* @since 4.0.0
287+
* @param {string} name - The name of the uniform to set.
288+
* @param {any} value - The value to set the uniform to.
289+
* @return {this}
290+
*/
291+
setUniform: function (name, value)
292+
{
293+
this.renderNode.programManager.setUniform(name, value);
294+
return this;
295+
},
296+
271297
/**
272298
* Set the textures that the shader uses.
273299
*

src/gameobjects/shader/typedefs/ShaderQuadConfig.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)