-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6808 from perminder-17/sphere-Mapping
Added a Method (`panorama(img)`) which adds a sphereMapped Background.
- Loading branch information
Showing
3 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#define PI 3.141592 | ||
|
||
precision highp float; | ||
|
||
uniform sampler2D uSampler; | ||
uniform mat3 uNewNormalMatrix; | ||
uniform float uFovY; | ||
uniform float uAspect; | ||
|
||
varying vec2 vTexCoord; | ||
|
||
void main() { | ||
float uFovX = uFovY * uAspect; | ||
vec4 newTexColor = texture2D(uSampler, vTexCoord); | ||
float angleY = mix(uFovY/2.0, -uFovY/2.0, vTexCoord.y); | ||
float angleX = mix(uFovX/2.0, -uFovX/2.0, vTexCoord.x); | ||
vec3 rotatedNormal = vec3( angleX, angleY, 1.0 ); | ||
rotatedNormal = uNewNormalMatrix * normalize(rotatedNormal); | ||
vec2 suv; | ||
suv.y = 0.5 + 0.5 * (-rotatedNormal.y); | ||
suv.x = atan(rotatedNormal.z, rotatedNormal.x) / (2.0 * PI) + 0.5; | ||
newTexColor = texture2D(uSampler, suv.xy); | ||
gl_FragColor = newTexColor; | ||
} |