Skip to content

Commit

Permalink
Merge pull request #6735 from perminder-17/orbitControl
Browse files Browse the repository at this point in the history
`OrbitControl()` Compatibility with `imageLight()` by fixing camera.
  • Loading branch information
davepagurek authored Jan 19, 2024
2 parents 464ccc8 + f2af2b3 commit 832612b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
this.uMVMatrix = new p5.Matrix();
this.uPMatrix = new p5.Matrix();
this.uNMatrix = new p5.Matrix('mat3');
this.curMatrix = new p5.Matrix('mat3');

// Current vertex normal
this._currentNormal = new p5.Vector(0, 0, 1);
Expand Down
5 changes: 5 additions & 0 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ p5.Shader = class {
this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix);
this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3);
}
if (this.uniforms.uCameraRotation) {
this._renderer.curMatrix.inverseTranspose(this._renderer.
_curCamera.cameraMatrix);
this.setUniform('uCameraRotation', this._renderer.curMatrix.mat3);
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/webgl/shaders/lighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uniform bool uUseLighting;

uniform int uAmbientLightCount;
uniform vec3 uAmbientColor[5];

uniform mat3 uCameraRotation;
uniform int uDirectionalLightCount;
uniform vec3 uLightingDirection[5];
uniform vec3 uDirectionalDiffuseColors[5];
Expand Down Expand Up @@ -112,7 +112,7 @@ vec2 mapTextureToNormal( vec3 v ){
vec3 calculateImageDiffuse( vec3 vNormal, vec3 vViewPosition ){
// make 2 seperate builds
vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0); // hardcoded world camera position
vec3 worldNormal = normalize(vNormal);
vec3 worldNormal = normalize(vNormal * uCameraRotation);
vec2 newTexCoor = mapTextureToNormal( worldNormal );
vec4 texture = TEXTURE( environmentMapDiffused, newTexCoor );
// this is to make the darker sections more dark
Expand All @@ -124,7 +124,7 @@ vec3 calculateImageSpecular( vec3 vNormal, vec3 vViewPosition ){
vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0);
vec3 worldNormal = normalize(vNormal);
vec3 lightDirection = normalize( vViewPosition - worldCameraPosition );
vec3 R = reflect(lightDirection, worldNormal);
vec3 R = reflect(lightDirection, worldNormal) * uCameraRotation;
vec2 newTexCoor = mapTextureToNormal( R );
#ifdef WEBGL2
vec4 outColor = textureLod(environmentMapSpecular, newTexCoor, levelOfDetail);
Expand Down

0 comments on commit 832612b

Please sign in to comment.