summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/transparency-qml-scene3d/phongalpha.frag
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-07-08 12:51:59 +0200
committerSean Harmer <sean.harmer@kdab.com>2015-07-12 19:14:20 +0000
commit008b1218476ada691eec9bb4e181b2415fc1f0f4 (patch)
tree3442e3fe9a8d1f2ba00768a85eb666e6390ed702 /examples/qt3d/transparency-qml-scene3d/phongalpha.frag
parente12a0f0276521608dbbfdb03dfd0c089cd27eae2 (diff)
Add transparency-qml-scene3d
Does the same thing as transparency-qml, allows to verify there's nothing wrong with QtQuick 2 premultiplied alpha Change-Id: Ia85a9759eace636e13d2e1b4a0e7f65fb96171e1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/transparency-qml-scene3d/phongalpha.frag')
-rw-r--r--examples/qt3d/transparency-qml-scene3d/phongalpha.frag43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/qt3d/transparency-qml-scene3d/phongalpha.frag b/examples/qt3d/transparency-qml-scene3d/phongalpha.frag
new file mode 100644
index 000000000..b6b21fae4
--- /dev/null
+++ b/examples/qt3d/transparency-qml-scene3d/phongalpha.frag
@@ -0,0 +1,43 @@
+#define FP highp
+
+uniform FP vec4 lightPosition;
+uniform FP vec3 lightIntensity;
+
+// TODO: Replace with a struct
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP vec3 kd; // Diffuse reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP float shininess; // Specular shininess factor
+uniform float alpha;
+
+varying FP vec3 position;
+varying FP vec3 normal;
+
+FP vec3 adsModel( const FP vec3 pos, const FP vec3 n )
+{
+ // Calculate the vector from the light to the fragment
+ FP 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)
+ FP vec3 v = normalize( -pos );
+
+ // Reflect the light beam using the normal at this fragment
+ FP vec3 r = reflect( -s, n );
+
+ // Calculate the diffuse component
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ // Calculate the specular component
+ FP 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()
+{
+ gl_FragColor = vec4( adsModel( position, normalize( normal ) ), alpha );
+}