Layer shader now uses own attribute for line dimensions instead of misusing uvs.

This commit is contained in:
Jack Ha 2016-12-28 15:20:14 +01:00
parent 8d2b3654a4
commit 0f2fb86cd9
6 changed files with 22 additions and 40 deletions

View file

@ -10,13 +10,14 @@ vertex =
attribute highp vec4 a_vertex;
attribute lowp vec4 a_color;
attribute highp vec4 a_normal;
attribute highp vec2 a_uvs; // misused here for width and height
attribute highp vec2 a_line_dim; // line width and thickness
varying lowp vec4 v_color;
varying highp vec3 v_vertex;
varying highp vec3 v_normal;
varying lowp vec2 v_uvs;
//varying lowp vec2 v_uvs;
varying lowp vec2 v_line_dim;
varying lowp vec4 f_color;
varying highp vec3 f_vertex;
@ -25,7 +26,7 @@ vertex =
void main()
{
vec4 v1_vertex = a_vertex;
v1_vertex.y -= a_uvs.y / 2; // half layer down
v1_vertex.y -= a_line_dim.y / 2; // half layer down
vec4 world_space_vert = u_modelMatrix * v1_vertex;
// gl_Position = u_viewProjectionMatrix * world_space_vert;
gl_Position = world_space_vert;
@ -36,7 +37,7 @@ vertex =
v_vertex = world_space_vert.xyz;
v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
v_uvs = a_uvs;
v_line_dim = a_line_dim;
// for testing without geometry shader
f_color = v_color;
@ -47,9 +48,7 @@ vertex =
geometry =
#version 410
//uniform highp mat4 u_modelMatrix;
uniform highp mat4 u_viewProjectionMatrix;
//uniform highp mat4 u_modelViewProjectionMatrix;
layout(lines) in;
layout(triangle_strip, max_vertices = 26) out;
@ -57,7 +56,7 @@ geometry =
in vec4 v_color[];
in vec3 v_vertex[];
in vec3 v_normal[];
in vec2 v_uvs[];
in vec2 v_line_dim[];
out vec4 f_color;
out vec3 f_normal;
@ -65,10 +64,6 @@ geometry =
void main()
{
//int i;
//vec3 g_normal;
//vec3 g_offset;
vec4 g_vertex_delta;
vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers
vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position
@ -77,8 +72,8 @@ geometry =
vec3 g_vertex_normal_horz_head;
vec4 g_vertex_offset_horz_head;
float size_x = v_uvs[0].x / 2 + 0.01; // radius, and make it nicely overlapping
float size_y = v_uvs[0].y / 2 + 0.01;
float size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping
float size_y = v_line_dim[0].y / 2 + 0.01;
//g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x);
g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position;
@ -89,7 +84,6 @@ geometry =
g_vertex_offset_horz = vec4(g_vertex_normal_horz * size_x, 0.0); //size * g_vertex_normal_horz;
g_vertex_normal_vert = vec3(0.0, 1.0, 0.0);
//g_vertex_offset_vert = vec3(g_vertex_normal_vert.x * 0.5f, g_vertex_normal_vert.y * 0.5f, g_vertex_normal_vert.z * 0.5f); //size * g_vertex_normal_vert;
g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0);
f_vertex = v_vertex[0];
@ -243,10 +237,6 @@ geometry =
EmitVertex();
EndPrimitive();
}
fragment =
@ -327,4 +317,4 @@ u_lightPosition = light_0_position
a_vertex = vertex
a_color = color
a_normal = normal
a_uvs = uv0
a_line_dim = line_dim