summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/maths/primitives.c11
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c27
-rw-r--r--src/renderer/builtin_materials.h11
3 files changed, 31 insertions, 18 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index 86855db..5d9c70f 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -159,7 +159,7 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we
// Top point
vertex top = { .static_3d = { .position = vec3(0, radius, 0),
- .normal = vec3(0, radius, 0),
+ .normal = vec3_normalise(vec3(0, radius, 0)),
.tex_coords = vec2(0, 0) } };
vertex_darray_push(vertices, top);
@@ -173,13 +173,13 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we
// theta should range from 0 to 2PI
f32 theta = TAU * ((f32)j / (f32)north_south_lines);
vec3 position = spherical_to_cartesian_coords(radius, theta, phi);
- f32 d = vec3_len(position);
+ // f32 d = vec3_len(position);
// print_vec3(position);
// printf("Phi %f Theta %f d %d\n", phi, theta, d);
// assert(d == radius); // all points on the sphere should be 'radius' away from the origin
vertex v = { .static_3d = {
.position = position,
- .normal = position, // normal vector on sphere is same as position
+ .normal = vec3_normalise(position), // normal vector on sphere is same as position
.tex_coords = vec2(0, 0) // TODO
} };
vertex_darray_push(vertices, v);
@@ -188,7 +188,7 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we
// Bottom point
vertex bot = { .static_3d = { .position = vec3(0, -radius, 0),
- .normal = vec3(0, -radius, 0),
+ .normal = vec3_normalise(vec3(0, -radius, 0)),
.tex_coords = vec2(0, 0) } };
vertex_darray_push(vertices, bot);
@@ -235,8 +235,7 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we
}
for (int i = 0; i < vertices->len; i++) {
-
- print_vec3(vertices->data[i].static_3d.normal);
+ // print_vec3(vertices->data[i].static_3d.normal);
}
geometry_data geo = {
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index eb9ad83..18e7d2a 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -97,11 +97,11 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
gpu_buffer* ubo_buf = BUFFER_GET(ubo_handle);
i32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, binding.label);
- /* printf("Block index for Matrices: %d", blockIndex); */
+ printf("Block index for Matrices: %d", blockIndex);
if (blockIndex < 0) {
WARN("Couldn't retrieve block index for uniform block '%s'", binding.label);
} else {
- DEBUG("Retrived block index %d for %s", blockIndex, binding.label);
+ // DEBUG("Retrived block index %d for %s", blockIndex, binding.label);
}
u32 blocksize;
glGetActiveUniformBlockiv(pipeline->shader_id, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE,
@@ -111,7 +111,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, binding_j, ubo_buf->id.ubo);
if (blockIndex != GL_INVALID_INDEX) {
- glUniformBlockBinding(pipeline->shader_id, blockIndex, 0);
+ glUniformBlockBinding(pipeline->shader_id, blockIndex, binding_j);
}
// Now we want to store a handle associated with the shader for this
@@ -185,25 +185,36 @@ void encode_bind_pipeline(gpu_cmd_encoder* encoder, pipeline_kind kind, gpu_pipe
}
void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* data) {
shader_data_layout sdl = data->shader_data_get_layout(data->data);
- printf("Binding %s shader data\n", sdl.name);
+ // printf("Binding %s shader data\n", sdl.name);
for (u32 i = 0; i < sdl.bindings_count; i++) {
shader_binding binding = sdl.bindings[i];
- print_shader_binding(binding);
+ // print_shader_binding(binding);
if (binding.type == SHADER_BINDING_BYTES) {
buffer_handle b = encoder->pipeline->uniform_bindings[i];
gpu_buffer* ubo_buf = BUFFER_GET(b);
+
+ i32 blockIndex = glGetUniformBlockIndex(encoder->pipeline->shader_id, binding.label);
+ if (blockIndex < 0) {
+ WARN("Couldn't retrieve block index for uniform block '%s'", binding.label);
+ } else {
+ // DEBUG("Retrived block index %d for %s", blockIndex, binding.label);
+ }
+
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
+ glBindBufferBase(GL_UNIFORM_BUFFER, i, ubo_buf->id.ubo);
if (i == 2) {
- vec3* v = binding.data.bytes.data;
- print_vec3(*v);
+ pbr_params_light_uniforms* u = binding.data.bytes.data;
+ vec4* v = &u->viewPos;
(*v).x = 0.0;
(*v).y = 0.0;
(*v).z = 1.0;
+ // print_vec3(*v);
}
-
+ // glBindBufferBase(GL_UNIFORM_BUFFER, i, ubo_buf->id.ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, binding.data.bytes.data);
+
} else if (binding.type == SHADER_BINDING_TEXTURE) {
gpu_texture* tex = TEXTURE_GET(binding.data.texture.handle);
glActiveTexture(GL_TEXTURE0);
diff --git a/src/renderer/builtin_materials.h b/src/renderer/builtin_materials.h
index 8d84e53..7748599 100644
--- a/src/renderer/builtin_materials.h
+++ b/src/renderer/builtin_materials.h
@@ -44,16 +44,19 @@ typedef struct pbr_params_material_uniforms {
f32 metallic;
f32 roughness;
f32 ao;
+ f32 pad[2];
} pbr_params_material_uniforms;
typedef struct pbr_point_light {
vec3 pos;
+ f32 pad;
vec3 color;
+ f32 pad2;
} pbr_point_light;
typedef struct pbr_params_light_uniforms {
- vec3 viewPos;
- /* pbr_point_light pointLights[4]; */
+ pbr_point_light pointLights[4];
+ vec4 viewPos;
} pbr_params_light_uniforms;
typedef struct pbr_params_bindgroup {
@@ -81,13 +84,13 @@ static shader_data_layout pbr_params_shader_layout(void* data) {
.stores_data = has_data,
.data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } };
- printf("Size %d \n", b3.data.bytes.size);
if (has_data) {
+ // printf("Size %d \n", b3.data.bytes.size);
b1.data.bytes.data = &d->mvp_matrices;
b2.data.bytes.data = &d->material;
/* d->lights.viewPos = vec3(0, 1, 0); */
b3.data.bytes.data = &d->lights;
- print_vec3(d->lights.viewPos);
+ // print_vec3(d->lights.viewPos);
}
return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3 }, .bindings_count = 3