Skip to content

Commit 3e0dc95

Browse files
authored
Merge pull request #5800 from ShenpaiSharma/gsoc-wrapup
Added shubham-gsoc-2022-project-wrapup
2 parents 7968a8c + 8b7c1c6 commit 3e0dc95

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

contributor_docs/project_wrapups/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This folder contains wrap-up reports from p5.js related [Google Summer of Code](
88
### Google Summer of Code 2022
99
* [p5 /teach reorganize & update](https://github.com/processing/p5.js/blob/main/contributor_docs/project_wrapups/graciazhang_gsoc_2022.md) by Gracia Zhang, 2022
1010
* [p5xr Immersive Session Process and Controller API update](https://github.com/processing/p5.js/blob/main/contributor_docs/project_wrapups/smrghsh_gsoc_2022.md) by Samir Ghosh, 2022
11+
* [Improving p5.js WebGL functionality](https://github.com/processing/p5.js/blob/main/contributor_docs/project_wrapups/shubham_sharma_gsoc_2022.md) by Shubham Kumar Sharma, 2022
1112

1213
### Google Summer of Code 2021
1314
* [Adding Alt Text to the p5.js Website](https://github.com/processing/p5.js/blob/main/contributor_docs/project_wrapups/katiejliu_gsoc_2021.md) by Katie Liu, 2021
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# GSoC-2022-Wrap-Up
2+
3+
## Improving p5.js WebGL functionality
4+
5+
#### by Shubham Kumar Sharma([@ShenpaiSharma](https://github.com/ShenpaiSharma)) | GSoC 2022
6+
7+
### Overview
8+
9+
The primary purpose over the course of this summer through GSoC 2022 was to focus on the refactoring of the WebGL rendering pipeline so that multiple materials can be applied to geometry simultaneously and implementing the missing feature of certain geometry in WebGL mode like corner radius is not accepted for the rectangle in WebGL mode, etc.
10+
11+
Key areas of my proposals were -
12+
- Correcting the inappropriate behavior of certain geometry in WebGL mode.
13+
- Refactoring of the WebGL rendering pipeline so that multiple materials can be applied to geometry.
14+
15+
16+
### Task Details
17+
## Correcting the inappropriate behavior of rect() in WebGL: [PR](https://github.com/processing/p5.js/pull/5789)
18+
19+
I started my GSoC 2022 work by addressing [#issue5001](https://github.com/processing/p5.js/issues/5001), rect() function takes eight parameters in which the last four parameters define the determined corner radius for the top-left, top-right, lower-right, and lower-left corners, respectively. But, even after passing these parameters, the rect() does nothing in WebGL mode. It could be confusing for beginners as, currently, p5.js doesn’t show errors related to it.
20+
21+
We took the approach that processing follows to implement rounded corners of a rectangle, i.e., using immediate mode; thus, we implemented it using vertex and quadraticVertex().
22+
23+
```
24+
function setup() {
25+
// Create the canvas
26+
createCanvas(720, 400, WEBGL);
27+
background(200);
28+
29+
// Set colors
30+
fill(204, 101, 192, 127);
31+
stroke(127, 63, 120);
32+
33+
// A rectangle
34+
rect(-100, -100, 200, 80, 40, 1, 5, 1);
35+
}
36+
37+
38+
```
39+
40+
Before:
41+
![image](https://user-images.githubusercontent.com/47415702/189298839-4aac32dc-f74e-4f21-8637-05f2b2c22c82.png)
42+
43+
After:
44+
![image](https://user-images.githubusercontent.com/47415702/189298948-55e9306a-8a5e-4a82-b208-dbdc725365d8.png)
45+
46+
### Future Work:
47+
While using higher strokeWeight, it starts showing artifacts, for more minor strokeWeight it looks fine; this issue actually exists while using the thicker strokeWeight, so for this, we need to look upon the stroke renderer much more closely.
48+
49+
![image](https://user-images.githubusercontent.com/47415702/189299200-25d111b6-b135-4573-8659-f24f6ea8d67c.png)
50+
51+
52+
## Multiple Materials applied to Geometry: [PR](https://github.com/processing/p5.js/pull/5774)
53+
Each object reacts to light differently in the real world. Steel items, for example, are often shinier than clay vases, and wooden containers do not respond to light in the same way that steel containers do. Some objects absorb light with little scattering, resulting in small specular highlights, while others scatter widely, resulting in a greater radius for the highlight.
54+
55+
So finally, we have decided to move away from the current overwriting of fill colors to the geometry towards the approach that Processing uses where the material has different color properties (ambient, emissive, specular) that all contribute separately to the lighting of the surface.
56+
57+
So we have implemented a few new uniforms (uSpecularMatColor, uAmbientMatColor, uEmissiveMatColor), which store the RGB colors and fill the geometry with different color properties and thus contributing separately to the lighting of the surface.
58+
59+
Code:
60+
61+
```
62+
function setup() {
63+
createCanvas(600, 600, WEBGL);
64+
smooth(8);
65+
noStroke();
66+
}
67+
function draw() {
68+
background(0);
69+
70+
ambientLight(128, 128, 128);
71+
72+
directionalLight(128, 128, 128, cos(frameCount * 0.1), 1, -1);
73+
74+
push();
75+
translate(-width * 0.25, 0, 0);
76+
77+
ambientMaterial(255, 0, 0);
78+
specularMaterial(0, 0, 0);
79+
sphere(width * 0.2);
80+
81+
pop();
82+
83+
push();
84+
translate(width * 0.25, 0, 0);
85+
86+
ambientMaterial(255, 0, 0);
87+
specularMaterial(255, 255, 255);
88+
sphere(width * 0.2);
89+
90+
pop();
91+
}
92+
93+
94+
```
95+
Before:
96+
97+
![image](https://user-images.githubusercontent.com/47415702/189299616-9e047451-0d3c-4cb8-b04d-aa37ae1f3572.png)
98+
99+
After:
100+
101+
![image](https://user-images.githubusercontent.com/47415702/189299695-92683040-c3e8-46e8-9fe3-331681535e33.png)
102+
103+
104+
Effect of combining all the material propertied like fill(), ambientMaterial(), SpecularMaterial() and emissiveMaterial() over geometry now results in:
105+
106+
![image](https://user-images.githubusercontent.com/47415702/189299930-430735df-3aaa-46b5-8b4c-7fb1c7db6362.png)
107+
108+
### Pull Requests:
109+
- Added round corner property for rect() in WebGL mode. [PR#5789](https://github.com/processing/p5.js/pull/5789)
110+
111+
- Feature Implemented -- Multiple Material support for geometry [PR#5774](https://github.com/processing/p5.js/pull/5774)
112+
113+
## Conclusion & Acknowledgements
114+
Thanks to my mentor [@calebfoss](https://github.com/calebfoss) for all the guidance and feedback throughout the project, other contributors of p5.js, and the whole processing community for showing immense support and an encouraging environment, which helped me exceed my own expectations! Thank you so much 😄

0 commit comments

Comments
 (0)