Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed P shader for imaginary square root value; Added SP shaders; The…
… whole think totally, like, works now
- Loading branch information
Igor Zablotchi
committed
Dec 15, 2011
1 parent
9b1de81
commit 4bfa8b6
Showing
4 changed files
with
77 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Cube map | ||
uniform samplerCube env; | ||
|
||
// Reflected and refracted vectors | ||
varying vec3 reflectedVector, refractedVector; | ||
|
||
// Reflection factor based on fresnel equation | ||
varying float refFactor; | ||
|
||
void main() | ||
{ | ||
// Read cube map | ||
vec4 reflectedColor = textureCube(env, reflectedVector); | ||
vec4 refractedColor = textureCube(env, refractedVector); | ||
|
||
// Mix reflected and refracted colors | ||
vec4 color = mix(refractedColor, reflectedColor, refFactor); | ||
color.a = 1.0; | ||
gl_FragColor = color; | ||
} |
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,47 @@ | ||
// Position of the view eye in world space | ||
uniform vec3 eyePos; | ||
|
||
// Ratio of indices of refraction | ||
uniform float etaRatio; | ||
|
||
// Reflected and refracted vectors | ||
varying vec3 reflectedVector, refractedVector; | ||
|
||
// Reflection factor based on fresnel equation | ||
varying float refFactor; | ||
|
||
void main() | ||
{ | ||
// Create incident and normal vectors | ||
vec3 I = normalize(gl_Vertex.xyz - eyePos.xyz); | ||
vec3 N = normalize(gl_Normal); | ||
|
||
// Calculate reflected and refracted vectors | ||
reflectedVector = reflect(I, N); | ||
refractedVector = refract(I, N, etaRatio); | ||
|
||
|
||
// Compute cos(incident angle) for the fresnel equations | ||
float cosThetaI = dot(-I,N); | ||
|
||
// Real fresnel equation | ||
float squareRoot = 1.0 - (1.0 - cosThetaI * cosThetaI)*etaRatio*etaRatio; | ||
squareRoot = (squareRoot < 0.0) ? 0.0 : squareRoot; | ||
|
||
float RS; | ||
RS = etaRatio * cosThetaI - sqrt(squareRoot); | ||
RS = RS/(etaRatio * cosThetaI + sqrt(squareRoot)); | ||
RS = RS * RS; | ||
|
||
float RP; | ||
RP = (etaRatio * sqrt(squareRoot) - cosThetaI); | ||
RP = RP/(etaRatio * sqrt(squareRoot) + cosThetaI); | ||
RP = RP * RP; | ||
|
||
refFactor = (RS + RP)/2.0; | ||
|
||
|
||
// Transform vertex | ||
gl_TexCoord[0] = gl_MultiTexCoord0; | ||
gl_Position = ftransform(); | ||
} |
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