polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 8e16948af4beb3b3f381d0d8e644915ff532777c
parent bbc32c2710ea83011c69100784d8dc284554270a
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  2 Nov 2018 02:04:12 -0700

non crashing tessellation shader

Diffstat:
Metc/shaders/terrain.g.glsl | 13+++++++------
Metc/shaders/terrain.te.glsl | 2+-
Metc/shaders/terrain.v.glsl | 16+++++-----------
Msrc/render.c | 14+++++++-------
Msrc/shader.c | 2+-
5 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/etc/shaders/terrain.g.glsl b/etc/shaders/terrain.g.glsl @@ -3,7 +3,7 @@ layout (triangles) in; layout (triangle_strip, max_vertices = 3) out; -layout(location = 10) in v_data { +in shader_data { #include shadervars.glsl } vertices[]; @@ -23,12 +23,13 @@ void main() { vertex.color = vertices[i].color; vertex.color_smooth = vertices[i].color_smooth; vertex.normal = vertices[i].normal; - // vertex.shadow_coord = depth_mvp * v4_pos; - // vertex.frag_pos = (world * v4_pos).xyz; - vertex.shadow_coord = vertices[i].shadow_coord; - vertex.frag_pos = vertices[i].frag_pos; + vertex.shadow_coord = depth_mvp * v4_pos; + vertex.frag_pos = (world * v4_pos).xyz; + // vertex.shadow_coord = vertices[i].shadow_coord; + // vertex.frag_pos = vertices[i].frag_pos; - gl_Position = gl_in[i].gl_Position; + gl_Position = mvp * gl_in[i].gl_Position; + vertex.position = gl_Position.xyz; // gl_Position = vec4(vertices[i].position, 1.0); EmitVertex(); diff --git a/etc/shaders/terrain.te.glsl b/etc/shaders/terrain.te.glsl @@ -27,6 +27,6 @@ void main() vec4 p2 = gl_TessCoord.z * gl_in[2].gl_Position; // tePatchDistance = gl_TessCoord; vec4 te_position = normalize(p0 + p1 + p2); - vertex.position = te_position.xyz; gl_Position = te_position; + vertex.position = gl_Position.xyz; } diff --git a/etc/shaders/terrain.v.glsl b/etc/shaders/terrain.v.glsl @@ -7,9 +7,9 @@ in vec3 normal; #include uniforms.glsl -layout(location = 10) out v_data { +out shader_data { #include shadervars.glsl -} vertices; +} vertex; void main() @@ -39,14 +39,8 @@ void main() // v_color = vec3(position.z, position.z, position.z) * 0.005; -// #include standard_vtxos.glsl - vec4 v4_pos = vec4(position, 1.0); - vertices.normal = normal; - vertices.color_smooth = vertices.color = color; - vertices.shadow_coord = depth_mvp * v4_pos; - vertices.position = v4_pos.xyz; - vertices.frag_pos = (world * v4_pos).xyz; +#include standard_vtxos.glsl - gl_Position = mvp * v4_pos; - vertices.position = gl_Position.xyz; + gl_Position = v4_pos; + vertex.position = gl_Position.xyz; } diff --git a/src/render.c b/src/render.c @@ -102,12 +102,12 @@ init_gl(struct resources *resources, int width, int height) { resources->proj_persp); /* Shader program */ - /* struct shader *terrain_shaders[] = */ - /* { &terrain_vertex, &fragment, &terrain_tc, &terrain_teval, */ - /* &terrain_geom }; */ - struct shader *terrain_shaders[] = - { &terrain_vertex, &fragment, &terrain_geom }; + { &terrain_vertex, &fragment, &terrain_tc, &terrain_teval, + &terrain_geom }; + + /* struct shader *terrain_shaders[] = */ + /* { &terrain_vertex, &fragment, &terrain_geom }; */ /* struct shader *terrain_shaders[] = */ /* { &terrain_vertex, &fragment }; */ @@ -324,11 +324,11 @@ void render (struct game *game, struct render_config *config) { check_gl(); } else { - /* glPatchParameteri(GL_PATCH_VERTICES, 3); */ + glPatchParameteri(GL_PATCH_VERTICES, 3); check_gl(); bind_geometry(&entity->model.geom, &res->attributes); check_gl(); - glDrawElements(GL_TRIANGLES, + glDrawElements(GL_PATCHES, entity->model.geom.num_indices, GL_UNSIGNED_INT, 0); check_gl(); diff --git a/src/shader.c b/src/shader.c @@ -52,7 +52,7 @@ static char **resolve_imports(char *contents, int *nlines) { line_buff[*nlines] = line; line_lens[*nlines] = line_len; (*nlines)++; - printf("%d %.*s", *nlines, line_len, line); + /* printf("%d %.*s", *nlines, line_len, line); */ } }