Archived
1
Fork 0

Add parameters for metallic and roughness back

This also makes them modifiable in the debug menu at runtime
This commit is contained in:
Joshua Goins 2022-02-08 08:50:10 -05:00
parent c6ccedb970
commit 2c75d51278
5 changed files with 30 additions and 5 deletions

View file

@ -43,6 +43,9 @@ class Material : public Asset {
public: public:
MaterialProperty colorProperty; MaterialProperty colorProperty;
float metallic = 0.0f;
float roughness = 0.5f;
GFXPipeline* static_pipeline = nullptr; GFXPipeline* static_pipeline = nullptr;
GFXPipeline* skinned_pipeline = nullptr; GFXPipeline* skinned_pipeline = nullptr;
GFXPipeline* capture_pipeline = nullptr; GFXPipeline* capture_pipeline = nullptr;

View file

@ -91,6 +91,22 @@ void draw_lighting() {
ImGui::Separator(); ImGui::Separator();
} }
ImGui::Text("Materials");
ImGui::Separator();
for(auto& material : assetm->get_all<Material>()) {
ImGui::PushID(material);
ImGui::TextDisabled("%s", material->path.c_str());
ImGui::DragFloat("Metallic", &material->metallic, 0.1f, 0.0f, 1.0f);
ImGui::DragFloat("Roughness", &material->roughness, 0.1f, 0.0f, 1.0f);
ImGui::PopID();
ImGui::Separator();
}
if(ImGui::Button("Reload shadows")) { if(ImGui::Button("Reload shadows")) {
engine->get_scene()->reset_shadows(); engine->get_scene()->reset_shadows();
} }

View file

@ -201,6 +201,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
src += "layout(location = 4) in vec4 fragPosLightSpace;\n"; src += "layout(location = 4) in vec4 fragPosLightSpace;\n";
src += "layout(location = 5) in mat3 in_tbn;\n"; src += "layout(location = 5) in mat3 in_tbn;\n";
src += "layout(location = 14) in vec4 fragPostSpotLightSpace[max_spot_lights];\n"; src += "layout(location = 14) in vec4 fragPostSpotLightSpace[max_spot_lights];\n";
src += "layout(location = 13) in flat int inMaterialIndex;\n";
src += "#include \"common.glsl\"\n"; src += "#include \"common.glsl\"\n";
src += "#include \"rendering.glsl\"\n"; src += "#include \"rendering.glsl\"\n";
@ -289,8 +290,8 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
} }
src += "vec3 final_diffuse_color = from_srgb_to_linear(Color);\n"; src += "vec3 final_diffuse_color = from_srgb_to_linear(Color);\n";
src += "float final_roughness = 0.5;\n"; src += "float final_roughness = scene.materials[inMaterialIndex].info.y;\n";
src += "float final_metallic = 0.0;\n"; src += "float final_metallic = scene.materials[inMaterialIndex].info.x;\n";
src += "vec3 final_normal = in_normal;\n"; src += "vec3 final_normal = in_normal;\n";
src += src +=

View file

@ -422,6 +422,9 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
create_mesh_pipeline(*material.handle); create_mesh_pipeline(*material.handle);
if(!material_indices.count(material.handle)) { if(!material_indices.count(material.handle)) {
sceneInfo.materials[numMaterialsInBuffer].info.x = material->metallic;
sceneInfo.materials[numMaterialsInBuffer].info.y = material->roughness;
material_indices[material.handle] = numMaterialsInBuffer++; material_indices[material.handle] = numMaterialsInBuffer++;
} }
} }
@ -479,7 +482,7 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
command_buffer->bind_texture(texture_to_bind, index); command_buffer->bind_texture(texture_to_bind, index);
} }
command_buffer->draw_indexed(part.index_count, part.index_offset, part.vertex_offset, 0); command_buffer->draw_indexed(part.index_count, part.index_offset, part.vertex_offset, material_indices.at(*mesh.materials[material_index]));
} }
} }

View file

@ -20,6 +20,7 @@ layout (location = 2) out vec2 outUV;
layout (location = 4) out vec4 fragPosLightSpace; layout (location = 4) out vec4 fragPosLightSpace;
layout (location = 5) out mat3 outTBN; layout (location = 5) out mat3 outTBN;
layout (location = 14) out vec4 fragPostSpotLightSpace[max_spot_lights]; layout (location = 14) out vec4 fragPostSpotLightSpace[max_spot_lights];
layout (location = 13) out flat int outMaterialIndex;
struct Material { struct Material {
vec4 color, info; vec4 color, info;
@ -120,4 +121,5 @@ void main() {
#endif #endif
#endif #endif
outTBN = TBN; outTBN = TBN;
outMaterialIndex = gl_BaseInstance;
} }