Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename default shader methods to have a base* prefix #7288

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions src/webgl/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ p5.prototype.shader = function (s) {
* Get the default shader used with lights, materials,
* and textures.
*
* You can call <a href="#/p5.Shader/modify">`materialShader().modify()`</a>
* You can call <a href="#/p5.Shader/modify">`baseMaterialShader().modify()`</a>
* and change any of the following hooks:
*
* <table>
Expand Down Expand Up @@ -1032,10 +1032,10 @@ p5.prototype.shader = function (s) {
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.
*
* Call `materialShader().inspectHooks()` to see all the possible hooks and
* Call `baseMaterialShader().inspectHooks()` to see all the possible hooks and
* their default implementations.
*
* @method materialShader
* @method baseMaterialShader
* @beta
* @returns {p5.Shader} The material shader
*
Expand All @@ -1046,7 +1046,7 @@ p5.prototype.shader = function (s) {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* uniforms: {
* 'float time': () => millis()
* },
Expand Down Expand Up @@ -1075,7 +1075,7 @@ p5.prototype.shader = function (s) {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* declarations: 'vec3 myNormal;',
* 'Inputs getPixelInputs': `(Inputs inputs) {
* myNormal = inputs.normal;
Expand Down Expand Up @@ -1115,7 +1115,7 @@ p5.prototype.shader = function (s) {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* 'Inputs getPixelInputs': `(Inputs inputs) {
* float factor =
* sin(
Expand Down Expand Up @@ -1150,7 +1150,7 @@ p5.prototype.shader = function (s) {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* 'Inputs getPixelInputs': `(Inputs inputs) {
* vec3 newNormal = inputs.normal;
* // Simple bump mapping: adjust the normal based on position
Expand Down Expand Up @@ -1189,15 +1189,15 @@ p5.prototype.shader = function (s) {
* </code>
* </div>
*/
p5.prototype.materialShader = function() {
this._assert3d('materialShader');
return this._renderer.materialShader();
p5.prototype.baseMaterialShader = function() {
this._assert3d('baseMaterialShader');
return this._renderer.baseMaterialShader();
};

/**
* Get the shader used by <a href="#/p5/normalMaterial">`normalMaterial()`</a>.
*
* You can call <a href="#/p5.Shader/modify">`normalShader().modify()`</a>
* You can call <a href="#/p5.Shader/modify">`baseNormalShader().modify()`</a>
* and change any of the following hooks:
*
* Hook | Description
Expand All @@ -1217,10 +1217,10 @@ p5.prototype.materialShader = function() {
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.
*
* Call `normalShader().inspectHooks()` to see all the possible hooks and
* Call `baseNormalShader().inspectHooks()` to see all the possible hooks and
* their default implementations.
*
* @method normalShader
* @method baseNormalShader
* @beta
* @returns {p5.Shader} The `normalMaterial` shader
*
Expand All @@ -1231,7 +1231,7 @@ p5.prototype.materialShader = function() {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = normalShader().modify({
* myShader = baseNormalShader().modify({
* uniforms: {
* 'float time': () => millis()
* },
Expand All @@ -1258,7 +1258,7 @@ p5.prototype.materialShader = function() {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = normalShader().modify({
* myShader = baseNormalShader().modify({
* 'vec3 getWorldNormal': '(vec3 normal) { return abs(normal); }',
* 'vec4 getFinalColor': `(vec4 color) {
* // Map the r, g, and b values of the old normal to new colors
Expand All @@ -1284,15 +1284,15 @@ p5.prototype.materialShader = function() {
* </code>
* </div>
*/
p5.prototype.normalShader = function() {
this._assert3d('materialShader');
return this._renderer.normalShader();
p5.prototype.baseNormalShader = function() {
this._assert3d('baseNormalShader');
return this._renderer.baseNormalShader();
};

/**
* Get the shader used when no lights or materials are applied.
*
* You can call <a href="#/p5.Shader/modify">`colorShader().modify()`</a>
* You can call <a href="#/p5.Shader/modify">`baseColorShader().modify()`</a>
* and change any of the following hooks:
*
* Hook | Description
Expand All @@ -1312,10 +1312,10 @@ p5.prototype.normalShader = function() {
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.
*
* Call `colorShader().inspectHooks()` to see all the possible hooks and
* Call `baseColorShader().inspectHooks()` to see all the possible hooks and
* their default implementations.
*
* @method colorShader
* @method baseColorShader
* @beta
* @returns {p5.Shader} The color shader
*
Expand All @@ -1326,7 +1326,7 @@ p5.prototype.normalShader = function() {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = colorShader().modify({
* myShader = baseColorShader().modify({
* uniforms: {
* 'float time': () => millis()
* },
Expand All @@ -1347,15 +1347,15 @@ p5.prototype.normalShader = function() {
* </code>
* </div>
*/
p5.prototype.colorShader = function() {
this._assert3d('colorShader');
return this._renderer.colorShader();
p5.prototype.baseColorShader = function() {
this._assert3d('baseColorShader');
return this._renderer.baseColorShader();
};

/**
* Get the shader used when drawing the strokes of shapes.
*
* You can call <a href="#/p5.Shader/modify">`strokeShader().modify()`</a>
* You can call <a href="#/p5.Shader/modify">`baseStrokeShader().modify()`</a>
* and change any of the following hooks:
*
* <table>
Expand Down Expand Up @@ -1487,10 +1487,10 @@ p5.prototype.colorShader = function() {
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.
*
* Call `strokeShader().inspectHooks()` to see all the possible hooks and
* Call `baseStrokeShader().inspectHooks()` to see all the possible hooks and
* their default implementations.
*
* @method strokeShader
* @method baseStrokeShader
* @beta
* @returns {p5.Shader} The stroke shader
*
Expand All @@ -1501,7 +1501,7 @@ p5.prototype.colorShader = function() {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = strokeShader().modify({
* myShader = baseStrokeShader().modify({
* 'Inputs getPixelInputs': `(Inputs inputs) {
* float opacity = 1.0 - smoothstep(
* 0.0,
Expand Down Expand Up @@ -1535,7 +1535,7 @@ p5.prototype.colorShader = function() {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = strokeShader().modify({
* myShader = baseStrokeShader().modify({
* uniforms: {
* 'float time': () => millis()
* },
Expand Down Expand Up @@ -1581,7 +1581,7 @@ p5.prototype.colorShader = function() {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = strokeShader().modify({
* myShader = baseStrokeShader().modify({
* 'float random': `(vec2 p) {
* vec3 p3 = fract(vec3(p.xyx) * .1031);
* p3 += dot(p3, p3.yzx + 33.33);
Expand Down Expand Up @@ -1620,9 +1620,9 @@ p5.prototype.colorShader = function() {
* </code>
* </div>
*/
p5.prototype.strokeShader = function() {
this._assert3d('strokeShader');
return this._renderer.strokeShader();
p5.prototype.baseStrokeShader = function() {
this._assert3d('baseStrokeShader');
return this._renderer.baseStrokeShader();
};

/**
Expand Down
22 changes: 11 additions & 11 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
return this._getImmediateLineShader();
}

materialShader() {
baseMaterialShader() {
if (!this._pInst._glAttributes.perPixelLighting) {
throw new Error(
'The material shader does not support hooks without perPixelLighting. Try turning it back on.'
Expand Down Expand Up @@ -1872,7 +1872,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
return this._defaultImmediateModeShader;
}

normalShader() {
baseNormalShader() {
return this._getNormalShader();
}

Expand Down Expand Up @@ -1907,7 +1907,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
return this._defaultNormalShader;
}

colorShader() {
baseColorShader() {
return this._getColorShader();
}

Expand Down Expand Up @@ -1998,7 +1998,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
return this._defaultPointShader;
}

strokeShader() {
baseStrokeShader() {
return this._getLineShader();
}

Expand Down Expand Up @@ -2206,15 +2206,15 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
return new p5.Framebuffer(this, options);
}

_setStrokeUniforms(strokeShader) {
strokeShader.bindShader();
_setStrokeUniforms(baseStrokeShader) {
baseStrokeShader.bindShader();

// set the uniform values
strokeShader.setUniform('uUseLineColor', this._useLineColor);
strokeShader.setUniform('uMaterialColor', this.curStrokeColor);
strokeShader.setUniform('uStrokeWeight', this.curStrokeWeight);
strokeShader.setUniform('uStrokeCap', STROKE_CAP_ENUM[this.curStrokeCap]);
strokeShader.setUniform('uStrokeJoin', STROKE_JOIN_ENUM[this.curStrokeJoin]);
baseStrokeShader.setUniform('uUseLineColor', this._useLineColor);
baseStrokeShader.setUniform('uMaterialColor', this.curStrokeColor);
baseStrokeShader.setUniform('uStrokeWeight', this.curStrokeWeight);
baseStrokeShader.setUniform('uStrokeCap', STROKE_CAP_ENUM[this.curStrokeCap]);
baseStrokeShader.setUniform('uStrokeJoin', STROKE_JOIN_ENUM[this.curStrokeJoin]);
}

_setFillUniforms(fillShader) {
Expand Down
6 changes: 3 additions & 3 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ p5.Shader = class {
* For example, this shader will produce the following output:
*
* ```js
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* declarations: 'uniform float time;',
* 'vec3 getWorldPosition': `(vec3 pos) {
* pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
Expand Down Expand Up @@ -381,7 +381,7 @@ p5.Shader = class {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* uniforms: {
* 'float time': () => millis()
* },
Expand Down Expand Up @@ -410,7 +410,7 @@ p5.Shader = class {
*
* function setup() {
* createCanvas(200, 200, WEBGL);
* myShader = materialShader().modify({
* myShader = baseMaterialShader().modify({
* // Manually specifying a uniform
* declarations: 'uniform float time;',
* 'vec3 getWorldPosition': `(vec3 pos) {
Expand Down
Loading