Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const GLchar vsh[] =
- "#version 330\n"
- ""
- "layout(location = 0) in vec2 a_position;"
- ""
- "uniform mat4 u_mv;"
- "uniform mat4 u_mvp;"
- ""
- "out vec3 v_p;"
- "out vec3 v_normal;"
- ""
- "void main()"
- "{"
- " vec4 pos = vec4(a_position[0], 3*log(a_position[0])+sin(a_position[1]), a_position[1], 1.0);"
- " gl_Position = u_mvp*pos;"
- " v_p = (u_mv*pos).xyz;"
- " v_normal = normalize(transpose(inverse(mat3(u_mv)))*vec3(3/a_position[0] , 1.0, cos(a_position[1]) ));" //нормаль
- "}"
- ;
- const GLchar fsh[] =
- "#version 330\n"
- ""
- "in vec3 v_p;"
- "in vec3 v_normal;"
- ""
- "layout(location = 0) out vec4 o_color;"
- ""
- "void main()"
- "{"
- " vec3 u_l = vec3(5.0, 10.0, 0.0);" //Положение источника света
- " vec3 n = normalize(v_normal);" //нормировка нормали
- " vec3 l = normalize(v_p-u_l);"
- " vec3 e = normalize(-v_p);"
- " float d = max(dot(l, n), 0.1);" //диффузное освещение
- " vec3 r = normalize(reflect(l, e));" //вектор отражения
- " float s = pow(max(dot(r, n), 0.0), 5.0);" //компонент зеркального блика
- " o_color = vec4(d*vec3(1.0, 0.0, 0.0)+ vec3(s), 1.0);" //цвет поверхности
- "}"
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement