Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
HDR skyboxes implementation
- Loading branch information
1 parent
45bc2d7
commit db75d88
Showing
6 changed files
with
149 additions
and
2 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
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,34 @@ | ||
#version 330 | ||
|
||
in vec3 texCoord0; | ||
out vec4 fragColor; | ||
uniform sampler2D skyboxTexture; | ||
|
||
// Gamma correction | ||
uniform float gamma = 2.2; | ||
|
||
uniform float gammaStrength; | ||
|
||
vec3 gammaCorrect(const in vec3 color) | ||
{ | ||
return pow(color, vec3(1.0 / gamma)); | ||
} | ||
|
||
const vec2 invAtan = vec2(0.1591f, 0.3183f); | ||
vec2 SampleSphericalMap(vec3 v) | ||
{ | ||
vec2 uv = vec2(atan(v.z, v.x), asin(v.y)); | ||
uv *= invAtan; | ||
uv += 0.5; | ||
return uv; | ||
} | ||
|
||
void main() | ||
{ | ||
vec2 texCoords = SampleSphericalMap( normalize( texCoord0 ) ); | ||
vec4 baseColor = texture(skyboxTexture, texCoords); | ||
vec4 gammaColor = vec4(gammaCorrect(baseColor.rgb), 1.0); | ||
// This is an odd way to enable or not gamma correction, | ||
// but this is a way to avoid branching until we can generate shaders | ||
fragColor = mix(baseColor, gammaColor, gammaStrength); | ||
} |
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,16 @@ | ||
#version 330 | ||
|
||
in vec3 vertexPosition; | ||
out vec3 texCoord0; | ||
|
||
uniform mat4 modelMatrix; | ||
uniform mat4 viewMatrix; | ||
uniform mat4 projectionMatrix; | ||
|
||
void main() | ||
{ | ||
texCoord0 = vertexPosition.xyz; | ||
// Converting the viewMatrix to a mat3, then back to a mat4 | ||
// removes the translation component from it | ||
gl_Position = vec4(projectionMatrix * mat4(mat3(viewMatrix)) * modelMatrix * vec4(vertexPosition, 1.0)).xyww; | ||
} |