//Opaqe deffered pass ogle_bind_framebuffer(s,opaque_id); //NOTE(Ray):Since bind framebuffer changes the render pipeline we need to do use program and all that after it. //Its a small quirk. ogle_use_program(s,DefferedRenderer::diffuse_program); ogle_enable_depth_test(s); ogle_depth_func(s,compare_func_less); for (int i = 0;i < AssetSystem::render_asset_cache.anythings.count;++i) { ModelAsset* model = (ModelAsset*)AssetSystem::render_asset_cache.anythings.base + i; for(int j = 0;j < model->meshes.count;++j) { MeshAsset* mesh = (MeshAsset*)model->meshes.base + j; RenderMaterial material = mesh->r_material; Uniforms* vuniforms = (Uniforms*)ogle_vert_set_uniform_(s,sizeof(Uniforms),3); vuniforms->world_mat = m_matrix; vuniforms->pcm_mat = mul(Camera::main.matrix,m_matrix); vuniforms->pcm_mat = mul(Camera::main.projection_matrix,vuniforms->pcm_mat); vuniforms->inputs.base_color = material.inputs.base_color; vuniforms->inputs.metallic_factor = material.inputs.metallic_factor; vuniforms->inputs.roughness_factor = material.inputs.roughness_factor; Uniforms* funiforms = (Uniforms*)ogle_frag_set_uniform_(s,sizeof(Uniforms),3); funiforms->view_p = float4(Camera::main.ot.p,1); GPUBuffer uv_buffer; for(int i = 0;i < material.texture_count;++i) { ShaderTextureSlot slot = material.shader.texture_slots[i]; ogle_bind_texture_frag(s,material.gl_tex_slots[i],i); if(slot.texcoord_index == 0) { uv_buffer = mesh->mesh_resource.uv_buff; } else if(slot.texcoord_index == 1) { uv_buffer = mesh->mesh_resource.uv2_buff; } else { Assert(false); } ogle_bind_buffer_raw(s,uv_buffer.id,2,0); } ogle_bind_buffer_raw(s,mesh->mesh_resource.vertex_buff.id,0,0); ogle_bind_buffer_raw(s,mesh->mesh_resource.normal_buff.id,1,0); //TODO(Ray):The use of the index16count here is silly need to fix this. ogle_draw_elements(s,mesh->index16_count, mesh->mesh_resource.element_buff.index_type,mesh->mesh_resource.element_buff.id,0); } } ogle_bind_framebuffer(s,0); //shadow depth pass ogle_bind_framebuffer(s,shadow_fb_id); ogle_use_program(s,shadow_map_program); ogle_enable_stencil_test(s); ogle_stencil_func(s,compare_func_always,(u32)0xFF,(u32)0xFF); ogle_stencil_op_sep(s,1,stencil_op_keep,stencil_op_incrementClamp,stencil_op_keep); //for each frustum of each light in the light buffer, //render distance to shadow map texture as color red.(r32 format). //GPU: //Each vertex outputs world space of fragment position which is interpolated arcross the pixels. //convertes the world space of the vertex to the position of the vertex from light view. //Each rendered pixel than subtracks from the fragment world position and the cam view pos to get distance //of pixel to the camera(used for shadow map calculations)TODO(Ray):Should just use depth buffer. bool is_render_all = true; // for(int l = 0;l < light_buffer_cache.anythings.count;++l) { // Light* light = (Light*)light_buffer_cache.anythings.base + l; // if((!light->is_entry && light->is_dirty) || !is_render_all)continue; // if(light->Type == LightType_Point) { for(int frustrum_index = 0;frustrum_index < 6;++frustrum_index) { for (int i = 0;i < AssetSystem::render_asset_cache.anythings.count;++i) { ModelAsset* model = (ModelAsset*)AssetSystem::render_asset_cache.anythings.base + i; for(int j = 0;j < model->meshes.count;++j) { MeshAsset* mesh = (MeshAsset*)model->meshes.base + j; RenderMaterial material = mesh->r_material; Uniforms* vuniforms = (Uniforms*)ogle_vert_set_uniform_(s,sizeof(Uniforms),3); vuniforms->world_mat = m_matrix; vuniforms->pcm_mat = mul(Camera::main.matrix,m_matrix); vuniforms->pcm_mat = mul(Camera::main.projection_matrix,vuniforms->pcm_mat); // vuniforms->light_view_matrix = light->view_matrices[frustrum_index]; Uniforms* funiforms = (Uniforms*)ogle_frag_set_uniform_(s,sizeof(Uniforms),3); funiforms->view_p = float4(Camera::main.ot.p,1); //Set Light buffer parameter GPUBuffer uv_buffer; for(int i = 0;i < material.texture_count;++i) { ShaderTextureSlot slot = material.shader.texture_slots[i]; ogle_bind_texture_frag(s,material.gl_tex_slots[i],i); if(slot.texcoord_index == 0) { uv_buffer = mesh->mesh_resource.uv_buff; } else if(slot.texcoord_index == 1) { uv_buffer = mesh->mesh_resource.uv2_buff; } else { Assert(false); } ogle_bind_buffer_raw(s,uv_buffer.id,2,0); } // ogle_bind_buffer_raw(s,mesh->light_buffer_id,7,0); ogle_bind_buffer_raw(s,mesh->mesh_resource.vertex_buff.id,0,0); ogle_bind_buffer_raw(s,mesh->mesh_resource.normal_buff.id,1,0); ogle_draw_elements(s,mesh->index16_count, mesh->mesh_resource.element_buff.index_type,mesh->mesh_resource.element_buff.id,0); } } } } } ogle_disable_stencil_test(s); //composite pass ogle_bind_framebuffer(s,0); ogle_use_program(s,composite_pass_shader); ogle_disable_depth_test(s); ogle_bind_buffer_raw(s,composite_buff.id,0,0); ogle_bind_texture_frag(s,diffuse_render_texture,0); ogle_draw_arrays(s,6,0);