Skip to content

Commit aa45dc1

Browse files
authored
Merge pull request #8502 from processing/webgpu-perf
More performance updates for WebGPU mode
2 parents 4fc91bf + 71dfa90 commit aa45dc1

9 files changed

Lines changed: 592 additions & 334 deletions

File tree

src/core/p5.Renderer3D.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,10 +1448,6 @@ export class Renderer3D extends Renderer {
14481448
this.scratchMat3.inverseTranspose4x4(this.states.uViewMatrix);
14491449
shader.setUniform("uCameraNormalMatrix", this.scratchMat3.mat3);
14501450
}
1451-
if (shader.uniforms.uCameraRotation) {
1452-
this.scratchMat3.inverseTranspose4x4(this.states.uViewMatrix);
1453-
shader.setUniform("uCameraRotation", this.scratchMat3.mat3);
1454-
}
14551451
shader.setUniform("uViewport", this._viewport);
14561452
}
14571453

src/webgl/p5.Shader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,12 @@ class Shader {
10281028
return;
10291029
} else {
10301030
if (Array.isArray(data)) {
1031+
if (uniform._cachedData && this._renderer._arraysEqual(uniform._cachedData, data)) {
1032+
return;
1033+
}
10311034
uniform._cachedData = data.slice(0);
10321035
} else {
1036+
if (uniform._cachedData === data) return;
10331037
uniform._cachedData = data;
10341038
}
10351039
}

src/webgl/shaders/lighting.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ precision highp float;
44
precision highp int;
55

66
uniform mat4 uViewMatrix;
7+
uniform mat3 uCameraNormalMatrix;
78

89
uniform bool uUseLighting;
910

10-
uniform mat3 uCameraRotation;
1111
uniform int uDirectionalLightCount;
1212
uniform vec3 uLightingDirection[5];
1313
uniform vec3 uDirectionalDiffuseColors[5];
@@ -108,7 +108,7 @@ vec2 mapTextureToNormal( vec3 v ){
108108
vec3 calculateImageDiffuse(vec3 vNormal, vec3 vViewPosition, float metallic){
109109
// make 2 seperate builds
110110
vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0); // hardcoded world camera position
111-
vec3 worldNormal = normalize(vNormal * uCameraRotation);
111+
vec3 worldNormal = normalize(vNormal * uCameraNormalMatrix);
112112
vec2 newTexCoor = mapTextureToNormal( worldNormal );
113113
vec4 texture = TEXTURE( environmentMapDiffused, newTexCoor );
114114
// this is to make the darker sections more dark
@@ -120,7 +120,7 @@ vec3 calculateImageSpecular(vec3 vNormal, vec3 vViewPosition, float shininess, f
120120
vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0);
121121
vec3 worldNormal = normalize(vNormal);
122122
vec3 lightDirection = normalize( vViewPosition - worldCameraPosition );
123-
vec3 R = reflect(lightDirection, worldNormal) * uCameraRotation;
123+
vec3 R = reflect(lightDirection, worldNormal) * uCameraNormalMatrix;
124124
vec2 newTexCoor = mapTextureToNormal( R );
125125
#ifdef WEBGL2
126126
// In p5js the range of shininess is >= 1,

0 commit comments

Comments
 (0)