summaryrefslogtreecommitdiffstats
path: root/shaders
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-10-06 12:52:40 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-10-06 12:53:07 +0200
commitaf64f953d4f01a7c7bd3415ff5edfff8d4f7c48d (patch)
treeee6060a549c311ffa02b4a604bd9059f0465b237 /shaders
downloadMultimedia-af64f953d4f01a7c7bd3415ff5edfff8d4f7c48d.tar.gz
Multimedia-af64f953d4f01a7c7bd3415ff5edfff8d4f7c48d.zip
Initial commit
Diffstat (limited to 'shaders')
-rw-r--r--shaders/fshader.fsh30
-rw-r--r--shaders/vshader.vsh56
2 files changed, 86 insertions, 0 deletions
diff --git a/shaders/fshader.fsh b/shaders/fshader.fsh
new file mode 100644
index 0000000..f67bbfc
--- /dev/null
+++ b/shaders/fshader.fsh
@@ -0,0 +1,30 @@
+//precision highp float;
+uniform mediump vec4 color;
+varying highp vec4 v_AmbientAndDiffuseColor;
+varying highp vec4 v_SpecularColor;
+varying highp float v_AmbientLightBrightness;
+varying highp float v_DiffuseBrightness;
+varying highp float v_SpecularBrightness;
+varying highp vec2 v_TexCoord;
+uniform highp vec2 u_viewPortCenter;
+uniform highp float u_diameterSquare;
+
+uniform bool u_TextureEnabled;
+uniform sampler2D s_Texture;
+
+//highp vec2 centerVec;
+
+
+void main(void)
+{
+// centerVec = gl_FragCoord.xy - u_viewPortCenter;
+// if(dot(centerVec, centerVec) > u_diameterSquare)
+// discard;
+
+ if(u_TextureEnabled)
+ gl_FragColor = texture2D(s_Texture, v_TexCoord) * (v_AmbientLightBrightness + v_DiffuseBrightness)
+ + v_SpecularBrightness * v_SpecularColor;
+ else
+ gl_FragColor = v_AmbientAndDiffuseColor * (v_AmbientLightBrightness + v_DiffuseBrightness)
+ + v_SpecularBrightness * v_SpecularColor;
+}
diff --git a/shaders/vshader.vsh b/shaders/vshader.vsh
new file mode 100644
index 0000000..e592d0b
--- /dev/null
+++ b/shaders/vshader.vsh
@@ -0,0 +1,56 @@
+attribute highp vec4 a_Vertex;
+attribute highp vec4 a_Color;
+attribute highp vec3 a_Normal;
+attribute highp vec2 a_TexCoord;
+
+uniform bool u_LightingEnabled;
+uniform bool u_ColorArrayEnabled;
+uniform highp mat4 u_MvpMatrix;
+uniform highp mat3 u_NormalMatrix;
+uniform highp vec3 u_LightDirection;
+uniform highp vec3 u_HalfPlaneVector;
+uniform highp vec4 u_AmbientAndDiffuseColor;
+uniform highp float u_AmbientLightBrightness;
+uniform highp vec4 u_SpecularColor;
+uniform highp float u_Shininess;
+uniform int u_PointSize;
+
+varying highp vec2 v_TexCoord;
+varying highp vec4 v_AmbientAndDiffuseColor;
+varying highp vec4 v_SpecularColor;
+varying highp float v_AmbientLightBrightness;
+varying highp float v_DiffuseBrightness;
+varying highp float v_SpecularBrightness;
+
+const highp float c_Zero = 0.0;
+highp vec3 eyeSpaceNormal;
+
+highp float calculateDiffuseBrightness()
+{
+ if(u_LightingEnabled)
+ return max(c_Zero, dot(eyeSpaceNormal, u_LightDirection));
+ else return 1.0;
+}
+
+highp float calculateSpecularBrightness()
+{
+ highp float nDotHp = max(c_Zero, dot(eyeSpaceNormal, u_HalfPlaneVector));
+ if(u_LightingEnabled && nDotHp > c_Zero)
+ return pow(nDotHp, u_Shininess);
+ else return 0.0;
+}
+
+void main(void)
+{
+ gl_Position = u_MvpMatrix * a_Vertex;
+ if(u_LightingEnabled)
+ eyeSpaceNormal = normalize(u_NormalMatrix * a_Normal);
+ v_TexCoord = a_TexCoord;
+ if(u_ColorArrayEnabled)
+ v_AmbientAndDiffuseColor = a_Color;
+ else v_AmbientAndDiffuseColor = u_AmbientAndDiffuseColor;
+ v_AmbientLightBrightness = u_AmbientLightBrightness;
+ v_DiffuseBrightness = calculateDiffuseBrightness();
+ v_SpecularColor = u_SpecularColor;
+ v_SpecularBrightness = calculateSpecularBrightness();
+}