Skip to content

Commit 5888d55

Browse files
authored
Merge pull request #8706 from YuktiNandwana/feature/finalColor-texCoord-2.0
feat(webgl): add texCoord parameter to getFinalColor hook
2 parents 87ba686 + be41137 commit 5888d55

File tree

14 files changed

+39
-20
lines changed

14 files changed

+39
-20
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ class RendererGL extends Renderer3D {
723723
color.a = components.opacity;
724724
return color;
725725
}`,
726-
"vec4 getFinalColor": "(vec4 color) { return color; }",
726+
"vec4 getFinalColor": "(vec4 color, vec2 texCoord) { return color; }",
727727
"void afterFragment": "() {}",
728728
},
729729
}
@@ -760,7 +760,7 @@ class RendererGL extends Renderer3D {
760760
},
761761
fragment: {
762762
"void beforeFragment": "() {}",
763-
"vec4 getFinalColor": "(vec4 color) { return color; }",
763+
"vec4 getFinalColor": "(vec4 color, vec2 texCoord) { return color; }",
764764
"void afterFragment": "() {}",
765765
},
766766
}
@@ -788,7 +788,7 @@ class RendererGL extends Renderer3D {
788788
},
789789
fragment: {
790790
"void beforeFragment": "() {}",
791-
"vec4 getFinalColor": "(vec4 color) { return color; }",
791+
"vec4 getFinalColor": "(vec4 color, vec2 texCoord) { return color; }",
792792
"void afterFragment": "() {}",
793793
},
794794
}
@@ -820,7 +820,7 @@ class RendererGL extends Renderer3D {
820820
fragment: {
821821
"void beforeFragment": "() {}",
822822
"Inputs getPixelInputs": "(Inputs inputs) { return inputs; }",
823-
"vec4 getFinalColor": "(vec4 color) { return color; }",
823+
"vec4 getFinalColor": "(vec4 color, vec2 texCoord) { return color; }",
824824
"bool shouldDiscard": "(bool outside) { return outside; }",
825825
"void afterFragment": "() {}",
826826
},

src/webgl/p5.Shader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class Shader {
172172
* color.a = components.opacity;
173173
* return color;
174174
* }
175-
* vec4 getFinalColor(vec4 color) { return color; }
175+
* vec4 getFinalColor(vec4 color, vec2 texCoord) { return color; }
176176
* void afterFragment() {}
177177
* ```
178178
*

src/webgl/shaders/basic.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
IN vec4 vColor;
2+
IN highp vec2 vVertTexCoord;
23
void main(void) {
34
HOOK_beforeFragment();
4-
OUT_COLOR = HOOK_getFinalColor(vColor);
5+
OUT_COLOR = HOOK_getFinalColor(vColor, vVertTexCoord);
56
OUT_COLOR.rgb *= OUT_COLOR.a; // Premultiply alpha before rendering
67
HOOK_afterFragment();
7-
}
8+
}

src/webgl/shaders/line.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ void main() {
6969
discard;
7070
}
7171
}
72-
OUT_COLOR = HOOK_getFinalColor(vec4(inputs.color.rgb, 1.) * inputs.color.a);
72+
OUT_COLOR = HOOK_getFinalColor(vec4(inputs.color.rgb, 1.) * inputs.color.a, vec2(0.0, 0.0));
7373
HOOK_afterFragment();
7474
}

src/webgl/shaders/normal.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
IN vec3 vVertexNormal;
2+
IN highp vec2 vVertTexCoord;
23
void main(void) {
34
HOOK_beforeFragment();
4-
OUT_COLOR = HOOK_getFinalColor(vec4(vVertexNormal, 1.0));
5+
OUT_COLOR = HOOK_getFinalColor(vec4(vVertexNormal, 1.0), vVertTexCoord);
56
HOOK_afterFragment();
6-
}
7+
}

src/webgl/shaders/phong.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void main(void) {
7777
c.ambient = inputs.ambientLight;
7878
c.specular = specular;
7979
c.emissive = inputs.emissiveMaterial;
80-
OUT_COLOR = HOOK_getFinalColor(HOOK_combineColors(c));
80+
OUT_COLOR = HOOK_getFinalColor(HOOK_combineColors(c), vTexCoord);
8181
OUT_COLOR.rgb *= OUT_COLOR.a; // Premultiply alpha before rendering
8282
HOOK_afterFragment();
8383
}

src/webgpu/p5.RendererWebGPU.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,7 @@ function rendererWebGPU(p5, fn) {
23452345
rgb += components.emissive;
23462346
return vec4<f32>(rgb, components.opacity);
23472347
}`,
2348-
"vec4f getFinalColor": "(color: vec4<f32>) { return color; }",
2348+
"vec4f getFinalColor": "(color: vec4<f32>, texCoord: vec2<f32>) { return color; }",
23492349
"void afterFragment": "() {}",
23502350
},
23512351
}
@@ -2370,7 +2370,7 @@ function rendererWebGPU(p5, fn) {
23702370
},
23712371
fragment: {
23722372
"void beforeFragment": "() {}",
2373-
"vec4<f32> getFinalColor": "(color: vec4<f32>) { return color; }",
2373+
"vec4<f32> getFinalColor": "(color: vec4<f32>, texCoord: vec2<f32>) { return color; }",
23742374
"void afterFragment": "() {}",
23752375
},
23762376
}
@@ -2396,7 +2396,7 @@ function rendererWebGPU(p5, fn) {
23962396
fragment: {
23972397
"void beforeFragment": "() {}",
23982398
"Inputs getPixelInputs": "(inputs: Inputs) { return inputs; }",
2399-
"vec4<f32> getFinalColor": "(color: vec4<f32>) { return color; }",
2399+
"vec4<f32> getFinalColor": "(color: vec4<f32>, texCoord: vec2<f32>) { return color; }",
24002400
"bool shouldDiscard": "(outside: bool) { return outside; };",
24012401
"void afterFragment": "() {}",
24022402
},

src/webgpu/shaders/color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ${uniforms}
119119
@fragment
120120
fn main(input: FragmentInput) -> @location(0) vec4<f32> {
121121
HOOK_beforeFragment();
122-
var outColor = HOOK_getFinalColor(input.vColor);
122+
var outColor = HOOK_getFinalColor(input.vColor, input.vVertTexCoord);
123123
outColor = vec4<f32>(outColor.rgb * outColor.a, outColor.a);
124124
HOOK_afterFragment();
125125
return outColor;

src/webgpu/shaders/line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn main(input: StrokeFragmentInput) -> @location(0) vec4<f32> {
362362
discard;
363363
}
364364
}
365-
var col = HOOK_getFinalColor(inputs.color);
365+
var col = HOOK_getFinalColor(inputs.color, vec2<f32>(0.0, 0.0));
366366
col = vec4<f32>(col.rgb, 1.0) * col.a;
367367
HOOK_afterFragment();
368368
return vec4<f32>(col);

src/webgpu/shaders/material.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ fn main(input: FragmentInput) -> @location(0) vec4<f32> {
416416
inputs.emissiveMaterial
417417
);
418418
419-
var outColor = HOOK_getFinalColor(
420-
HOOK_combineColors(components)
421-
);
419+
var outColor = HOOK_getFinalColor(
420+
HOOK_combineColors(components), input.vTexCoord
421+
);
422422
outColor = vec4<f32>(outColor.rgb * outColor.a, outColor.a);
423423
HOOK_afterFragment();
424424
return outColor;

0 commit comments

Comments
 (0)