Last active
September 9, 2017 16:56
-
-
Save onslauth/ea2f96fce97b8c1d7e0359499b7b3dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Draw the North, East, South, West labels | |
label = CoreLabel( text = "North", font_size = '20sp', bold = True, color = ( 1, 1, 1, 1 ) ) | |
label.refresh( ) | |
texture = label.texture | |
Mesh( vertices = ( 0, 0, 0, 0, 1, 1, 1, 0, 1, | |
2, 0, 0, 0, 1, 1, 1, 1, 1, | |
2, 2, 0, 0, 1, 1, 1, 1, 0, | |
0, 2, 0, 0, 1, 1, 1, 0, 0 ), | |
indices = [ 0, 1, 2, 0, 2, 3 ], | |
fmt = self.vertex_format, | |
texture = texture, | |
mode = "triangles" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* simple.glsl | |
simple diffuse lighting based on laberts cosine law; see e.g.: | |
http://en.wikipedia.org/wiki/Lambertian_reflectance | |
http://en.wikipedia.org/wiki/Lambert%27s_cosine_law | |
*/ | |
---VERTEX SHADER------------------------------------------------------- | |
#ifdef GL_ES | |
precision highp float; | |
#endif | |
attribute vec3 v_pos; | |
attribute vec3 v_normal; | |
attribute vec4 v_color; | |
attribute vec2 v_tc0; | |
uniform mat4 modelview_mat; | |
uniform mat4 projection_mat; | |
uniform float Tr; | |
varying vec4 normal_vec; | |
varying vec4 vertex_pos; | |
varying vec4 color_vec; | |
varying vec2 tc0_vec; | |
void main (void) { | |
//compute vertex position in eye_sapce and normalize normal vector | |
vec4 pos = modelview_mat * vec4(v_pos,1.0); | |
vertex_pos = pos; | |
normal_vec = vec4(v_normal,0.0); | |
color_vec = v_color; | |
tc0_vec = v_tc0; | |
gl_Position = projection_mat * pos; | |
} | |
---FRAGMENT SHADER----------------------------------------------------- | |
#ifdef GL_ES | |
precision highp float; | |
#endif | |
varying vec4 normal_vec; | |
varying vec4 vertex_pos; | |
varying vec4 color_vec; | |
varying vec2 tc0_vec; | |
uniform sampler2D texture0; | |
uniform mat4 normal_mat; | |
uniform vec3 Kd; | |
uniform vec3 Ka; | |
uniform vec3 Ks; | |
uniform float Tr; | |
uniform float Ns; | |
uniform float intensity; | |
void main (void){ | |
//correct normal, and compute light vector (assume light at the eye) | |
vec4 v_normal = normalize( normal_mat * normal_vec ); | |
vec4 v_light = normalize( vec4(0,0,0,1) - vertex_pos ); | |
//reflectance based on lamberts law of cosine | |
vec3 Ia = intensity*Kd; | |
vec3 Id = intensity*Ka * max(dot(v_light, v_normal), 0.0); | |
vec3 Is = intensity*Ks * pow(max(dot(v_light, v_normal), 0.0), Ns); | |
//gl_FragColor = vec4(Ia + Id + Is, Tr); | |
vec4 t = texture2D( texture0, tc0_vec ); | |
gl_FragColor = t * color_vec; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment