diff --git a/data/material3DTextured.frag b/data/material3DTextured.frag new file mode 100644 index 0000000..f37bf8e --- /dev/null +++ b/data/material3DTextured.frag @@ -0,0 +1,55 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif +struct DirectionalLight { + vec3 direction; + vec3 halfplane; + vec4 ambientColor; + vec4 diffuseColor; + vec4 specularColor; +}; + +struct Material { + vec4 ambientFactor; + vec4 diffuseFactor; + vec4 specularFactor; + float shininess; +}; + +// Light +uniform DirectionalLight EW_directionalLight; +// Material +uniform Material EW_material; + +// Input : +uniform sampler2D EW_texID; + +varying vec2 f_texcoord; +varying vec3 v_ecNormal; + +void main(void) { + vec4 tmpElementColor = texture2D(EW_texID, f_texcoord); + + // Normalize v_ecNormal + vec3 ecNormal = v_ecNormal / length(v_ecNormal); + + float ecNormalDotLightDirection = max(0.0, dot(ecNormal, EW_directionalLight.direction)); + float ecNormalDotLightHalfplane = max(0.0, dot(ecNormal, EW_directionalLight.halfplane)); + + // Calculate ambient light + vec4 ambientLight = EW_directionalLight.ambientColor * EW_material.ambientFactor; + + // Calculate diffuse light + vec4 diffuseLight = ecNormalDotLightDirection * EW_directionalLight.diffuseColor * EW_material.diffuseFactor; + + // Calculate specular light + vec4 specularLight = vec4(0.0); + + if (ecNormalDotLightHalfplane > 0.0) { + specularLight = pow(ecNormalDotLightHalfplane, EW_material.shininess) * EW_directionalLight.specularColor * EW_material.specularFactor; + specularLight = EW_directionalLight.specularColor * EW_material.specularFactor; + } + vec4 light = ambientLight + diffuseLight + specularLight; + gl_FragColor = tmpElementColor;// * light; +} diff --git a/data/material3DTextured.vert b/data/material3DTextured.vert new file mode 100644 index 0000000..69ddada --- /dev/null +++ b/data/material3DTextured.vert @@ -0,0 +1,25 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif +// Input : +attribute vec3 EW_coord3d; +attribute vec2 EW_texture2d; +attribute vec3 EW_normal; +uniform mat4 EW_MatrixTransformation; +uniform mat4 EW_MatrixPosition; + +// output : +varying vec2 f_texcoord; +varying vec3 v_ecNormal; + +void main(void) { + gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0); + // set texture output coord + f_texcoord = EW_texture2d; + mat4 MatrixPosition = EW_MatrixPosition; + MatrixPosition[3][0] = 0.0; + MatrixPosition[3][1] = 0.0; + MatrixPosition[3][2] = 0.0; + v_ecNormal = vec3(MatrixPosition * vec4(EW_normal, 1.0) ); +}