diff options
author | Robert Brock <robert.brock@kdab.com> | 2016-05-06 10:47:51 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-15 13:44:24 +0000 |
commit | 2bcf2fb62b90b08bf9e0b531a125a7d44ed3ad13 (patch) | |
tree | 942a3d88a0519a68a2499e79e6ce23d872c99881 /tests/manual/bigscene-instanced-qml/instanced.frag | |
parent | ca1492cb1fa22e0e6f95b88ba68f5b3b80969c33 (diff) |
Moved bigscene-instanced-qml example to manual test
Part of an examples cleanup
Change-Id: If90e4d1aa004f62b9ef62937b8c8ac0b871a6cd1
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/manual/bigscene-instanced-qml/instanced.frag')
-rw-r--r-- | tests/manual/bigscene-instanced-qml/instanced.frag | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/manual/bigscene-instanced-qml/instanced.frag b/tests/manual/bigscene-instanced-qml/instanced.frag new file mode 100644 index 000000000..0efd52b32 --- /dev/null +++ b/tests/manual/bigscene-instanced-qml/instanced.frag @@ -0,0 +1,43 @@ +#version 150 core + +uniform vec4 lightPosition = vec4(1.0, 1.0, 0.0, 1.0); +uniform vec3 lightIntensity = vec3(1.0, 1.0, 1.0); + +uniform vec3 ka; // Ambient reflectivity +uniform vec3 ks = vec3(1.0, 1.0, 1.0); // Specular reflectivity +uniform float shininess = 150.0; // Specular shininess factor + +in vec3 kd; // Diffuse reflectivity +in vec3 position; +in vec3 normal; + +out vec4 fragColor; + +vec3 adsModel( const in vec3 pos, const in vec3 n ) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize( vec3( lightPosition ) - pos ); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize( -pos ); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect( -s, n ); + + // Calculate the diffuse component + float diffuse = max( dot( s, n ), 0.0 ); + + // Calculate the specular component + float specular = 0.0; + if ( dot( s, n ) > 0.0 ) + specular = pow( max( dot( r, v ), 0.0 ), shininess ); + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ( ka + kd * diffuse + ks * specular ); +} + +void main() +{ + fragColor = vec4( adsModel( position, normalize( normal ) ), 1.0 ); +} |