-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Placed all of the shader code into a conditional define to allow diff…
…erent shaders in mac and other OSs
- Loading branch information
1 parent
3a20870
commit e292e8f
Showing
7 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
SPIERSview/resources/lightingFragmentShaderTextured_mac.fsh
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,31 @@ | ||
#version 330 | ||
|
||
uniform float ambientReflection; | ||
uniform float diffuseReflection; | ||
uniform float specularReflection; | ||
uniform float shininess; | ||
uniform float alpha; | ||
|
||
in vec3 varyingNormal; | ||
in vec3 varyingLightDirection; | ||
in vec3 varyingViewerDirection; | ||
in vec4 varyingColour; | ||
|
||
out vec4 fragColor; | ||
|
||
void main(void) | ||
{ | ||
vec4 specularColor=varyingColour; | ||
vec4 diffuseColor=varyingColour/1.5; | ||
vec4 ambientColor=varyingColour/4.0; | ||
|
||
vec3 normal = normalize(varyingNormal); | ||
if (!gl_FrontFacing) normal=-normal; | ||
vec3 lightDirection = normalize(varyingLightDirection); | ||
vec3 viewerDirection = normalize(varyingViewerDirection); | ||
vec4 ambientIllumination = ambientReflection * ambientColor; | ||
vec4 diffuseIllumination = diffuseReflection * max(0.0, dot(lightDirection, normal)) * diffuseColor; | ||
vec4 specularIllumination = specularReflection * pow(max(0.0, dot(-reflect(lightDirection, normal), viewerDirection)), shininess) * specularColor; | ||
fragColor=ambientIllumination + diffuseIllumination + specularIllumination; | ||
fragColor[3]=alpha; | ||
} |
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,31 @@ | ||
#version 130 | ||
|
||
uniform vec4 ambientColor; | ||
uniform vec4 diffuseColor; | ||
uniform vec4 specularColor; | ||
uniform float ambientReflection; | ||
uniform float diffuseReflection; | ||
uniform float specularReflection; | ||
uniform float shininess; | ||
uniform float alpha; | ||
|
||
in vec3 varyingNormal; | ||
in vec3 varyingLightDirection; | ||
in vec3 varyingViewerDirection; | ||
|
||
out vec4 fragColor; | ||
|
||
void main(void) | ||
{ | ||
|
||
vec3 normal = normalize(varyingNormal); | ||
if (!gl_FrontFacing) normal=-normal; | ||
|
||
vec3 lightDirection = normalize(varyingLightDirection); | ||
vec3 viewerDirection = normalize(varyingViewerDirection); | ||
vec4 ambientIllumination = ambientReflection * ambientColor; | ||
vec4 diffuseIllumination = diffuseReflection * max(0.0, dot(lightDirection, normal)) * diffuseColor; | ||
vec4 specularIllumination = specularReflection * pow(max(0.0, dot(-reflect(lightDirection, normal), viewerDirection)), shininess) * specularColor; | ||
fragColor=ambientIllumination + diffuseIllumination + specularIllumination; | ||
fragColor[3]=alpha; | ||
} |
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,26 @@ | ||
#version 130 | ||
|
||
uniform mat4 mvpMatrix; | ||
uniform mat4 mvMatrix; | ||
uniform mat3 normalMatrix; | ||
uniform vec3 lightPosition; | ||
|
||
in vec4 vertex; | ||
in vec3 normal; | ||
in vec4 colour; | ||
|
||
out vec3 varyingNormal; | ||
out vec3 varyingLightDirection; | ||
out vec3 varyingViewerDirection; | ||
out vec4 varyingColour; | ||
|
||
void main(void) | ||
{ | ||
varyingColour=colour; | ||
vec4 eyeVertex = mvMatrix * vertex; | ||
eyeVertex /= eyeVertex.w; | ||
varyingNormal = normalMatrix * normal; | ||
varyingLightDirection = lightPosition - eyeVertex.xyz; | ||
varyingViewerDirection = -eyeVertex.xyz; | ||
gl_Position = mvpMatrix * vertex; | ||
} |
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,25 @@ | ||
#version 130 | ||
|
||
uniform mat4 mvpMatrix; | ||
uniform mat4 mvMatrix; | ||
uniform mat3 normalMatrix; | ||
uniform vec3 lightPosition; | ||
|
||
in vec4 vertex; | ||
in vec3 normal; | ||
|
||
out vec3 varyingNormal; | ||
out vec3 varyingLightDirection; | ||
out vec3 varyingViewerDirection; | ||
|
||
void main(void) | ||
{ | ||
|
||
|
||
vec4 eyeVertex = mvMatrix * vertex; | ||
eyeVertex /= eyeVertex.w; | ||
varyingNormal = normalMatrix * normal; | ||
varyingLightDirection = lightPosition - eyeVertex.xyz; | ||
varyingViewerDirection = -eyeVertex.xyz; | ||
gl_Position = mvpMatrix * vertex; | ||
} |
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