openGL work and other parts
@@ -4,13 +4,17 @@ precision mediump int;
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec3 lightWorldPos;
|
||||
uniform vec4 color;
|
||||
|
||||
// interpolated values
|
||||
varying vec3 v_WorldPos;
|
||||
varying vec3 v_normal;
|
||||
varying vec2 v_texcoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
|
||||
// Set fragment color from texture
|
||||
gl_FragColor = texture2D(texture, v_texcoord);
|
||||
gl_FragColor = vec4(1,1,1,1);
|
||||
gl_FragColor = color;
|
||||
|
||||
}
|
||||
76
res/gl/fragmentTex.glsl
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifdef GL_ES
|
||||
// Set default precision to medium
|
||||
precision mediump int;
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec3 eyeWorldPos;
|
||||
uniform vec3 lightWorldPos;
|
||||
|
||||
uniform sampler2D texDiffuse;
|
||||
uniform sampler2D texNormalMap;
|
||||
|
||||
// interpolated values
|
||||
varying vec3 v_WorldPos;
|
||||
varying vec3 v_CamPos;
|
||||
varying vec3 v_normal;
|
||||
varying vec2 v_texcoord;
|
||||
varying mat3 normalMat;
|
||||
|
||||
void main() {
|
||||
|
||||
// diffuse fragment color
|
||||
|
||||
vec4 ambient = texture2D(texDiffuse, v_texcoord);
|
||||
vec4 diffuse = ambient * vec4(0.8, 0.6, 0.35, 1.0);
|
||||
vec4 specular = vec4(1,1,1,1);
|
||||
|
||||
// get the normal from the normal map
|
||||
//vec3 normal = vec3(0,0,1);
|
||||
vec3 normal = normalize(texture2D(texNormalMap, v_texcoord).rgb - 0.5) * 2.0;
|
||||
// and convert from texture's normal-space into the object's normal-space using the normal-matrix
|
||||
normal = normalize(normalMat * normal);
|
||||
|
||||
|
||||
// direction from fragment towards the light
|
||||
vec3 lightDir = normalize(lightWorldPos - v_WorldPos);
|
||||
|
||||
// direction from fragment towards the eye
|
||||
vec3 eyeDir = normalize(eyeWorldPos - v_WorldPos);
|
||||
|
||||
|
||||
// diffuse lighting
|
||||
float diffuseIntensity = max(dot(lightDir, normal), 0.0);
|
||||
|
||||
// specular lighting
|
||||
// vec3 h = normalize(lightDir + eyeDir);
|
||||
// float intSpec = max(dot(h, normal), 0.0);
|
||||
// float specularIntensity = pow(intSpec, 2.0);
|
||||
float specularIntensity = pow(max(0.0, dot(eyeDir, reflect(-lightDir, normal))), 16);
|
||||
|
||||
|
||||
// distance between fragment and light (in meter)
|
||||
float distToLight_m = length(lightWorldPos - v_WorldPos);
|
||||
float lightInt = clamp(1.0 / (distToLight_m / 10.0), 0.0, 1.0);
|
||||
|
||||
// Set fragment color from texture
|
||||
vec4 finalColor =
|
||||
ambient * 0.05 +
|
||||
diffuse * 0.95 * diffuseIntensity * lightInt +
|
||||
clamp(specular * specularIntensity, 0.0, 1.0) * 1.0;
|
||||
|
||||
gl_FragColor = clamp(finalColor, 0.0, 1.0);
|
||||
|
||||
// FOG
|
||||
//float mixing = pow((1.0 - v_CamPos.z * 3.0), 2);
|
||||
//gl_FragColor = mix(gl_FragColor, vec4(0.5, 0.5, 0.5, 1.0), 1.0-mixing);
|
||||
|
||||
//gl_FragColor = gl_FragColor * 1;
|
||||
|
||||
// gl_FragColor =
|
||||
// ambient * 0.001 +
|
||||
// diffuse * 0.009 * diffuseIntensity +
|
||||
// specular * 0.6 * specularIntensity;
|
||||
|
||||
|
||||
}
|
||||
25
res/gl/fragmentTexSimple.glsl
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifdef GL_ES
|
||||
// Set default precision to medium
|
||||
precision mediump int;
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
//uniform vec3 eyeWorldPos;
|
||||
//uniform vec3 lightWorldPos;
|
||||
|
||||
uniform sampler2D texDiffuse;
|
||||
|
||||
// interpolated values
|
||||
//varying vec3 v_WorldPos;
|
||||
//varying vec3 v_normal;
|
||||
varying vec2 v_texcoord;
|
||||
|
||||
void main() {
|
||||
|
||||
// fragment color
|
||||
vec4 ambient = texture2D(texDiffuse, v_texcoord);
|
||||
|
||||
// set
|
||||
gl_FragColor = ambient;
|
||||
|
||||
}
|
||||
BIN
res/gl/tex/arrows.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
res/gl/tex/door1.jpg
Normal file
|
After Width: | Height: | Size: 255 KiB |
BIN
res/gl/tex/door2.jpg
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
res/gl/tex/door2_normal.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
res/gl/tex/floor1.jpg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
res/gl/tex/floor2.jpg
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
res/gl/tex/floor2_normal.jpg
Normal file
|
After Width: | Height: | Size: 90 KiB |
BIN
res/gl/tex/floor3.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
res/gl/tex/floor3_normal.jpg
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
res/gl/tex/floor4.jpg
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
res/gl/tex/floor4_normal.jpg
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
res/gl/tex/granite1.jpg
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
res/gl/tex/granite1_normal.jpg
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
res/gl/tex/wall1.jpg
Normal file
|
After Width: | Height: | Size: 218 KiB |
BIN
res/gl/tex/wall2_normal.jpg
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
res/gl/tex/wood1.jpg
Normal file
|
After Width: | Height: | Size: 181 KiB |
@@ -4,19 +4,39 @@ precision mediump int;
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform mat4 m_matrix;
|
||||
uniform mat4 mv_matrix;
|
||||
uniform mat4 mvp_matrix;
|
||||
|
||||
attribute vec4 a_position;
|
||||
attribute vec3 a_position;
|
||||
attribute vec3 a_normal;
|
||||
attribute vec2 a_texcoord;
|
||||
attribute vec3 a_tangent;
|
||||
|
||||
varying vec3 v_WorldPos;
|
||||
varying vec3 v_CamPos;
|
||||
|
||||
varying vec3 v_normal;
|
||||
varying vec2 v_texcoord;
|
||||
varying mat3 normalMat;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate vertex position in screen space
|
||||
gl_Position = mvp_matrix * a_position;
|
||||
void main() {
|
||||
|
||||
// Pass texture coordinate to fragment shader
|
||||
// Value will be automatically interpolated to fragments inside polygon faces
|
||||
|
||||
|
||||
// interpolation:
|
||||
v_WorldPos = vec3(m_matrix * vec4(a_position, 1.0));
|
||||
v_CamPos = vec3(mv_matrix * vec4(a_position, 1.0));
|
||||
v_normal = a_normal;//normalize(vec3(mv_matrix * vec4(a_normal, 0.0)));
|
||||
v_texcoord = a_texcoord;
|
||||
|
||||
|
||||
|
||||
// http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/
|
||||
vec3 bitangent = cross(a_normal, a_tangent);
|
||||
normalMat = mat3(a_tangent, bitangent, a_normal);
|
||||
|
||||
// 2D position for the vertex
|
||||
gl_Position = mvp_matrix * vec4(a_position, 1.0);
|
||||
|
||||
}
|
||||
|
||||