Add back support for normal textures in material compiler
This commit is contained in:
parent
a4f852f9c8
commit
840a1e861f
1 changed files with 22 additions and 3 deletions
|
@ -215,7 +215,13 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
|
|||
|
||||
src += "layout(binding = " + std::to_string(sampler_index++) + ") uniform sampler2D colorTexture;\n";
|
||||
}
|
||||
|
||||
|
||||
if(material.normalProperty.type == DataType::AssetTexture) {
|
||||
material.bound_textures[sampler_index] = material.normalProperty.value_tex;
|
||||
|
||||
src += "layout(binding = " + std::to_string(sampler_index++) + ") uniform sampler2D normalTexture;\n";
|
||||
}
|
||||
|
||||
if(use_ibl) {
|
||||
src += "vec3 get_reflect(int i, vec3 final_normal) {\n \
|
||||
const vec3 direction = normalize(in_frag_pos - scene.camPos.xyz);\n \
|
||||
|
@ -292,7 +298,16 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
|
|||
src += "vec3 final_diffuse_color = from_srgb_to_linear(Color);\n";
|
||||
src += "float final_roughness = scene.materials[inMaterialIndex].info.y;\n";
|
||||
src += "float final_metallic = scene.materials[inMaterialIndex].info.x;\n";
|
||||
src += "vec3 final_normal = in_normal;\n";
|
||||
|
||||
if(material.normalProperty.type == DataType::AssetTexture) {
|
||||
prism::log("enabling normal mapping on material..");
|
||||
|
||||
src += "vec3 final_normal = texture(normalTexture, in_uv).rgb;\n";
|
||||
src += "final_normal = final_normal * 2.0 - 1.0;\n";
|
||||
src += "final_normal = in_tbn * final_normal;\n";
|
||||
} else {
|
||||
src += "vec3 final_normal = in_normal;\n";
|
||||
}
|
||||
|
||||
src +=
|
||||
"ComputedSurfaceInfo surface_info = compute_surface(final_diffuse_color.rgb, final_normal, final_metallic, final_roughness);\n \
|
||||
|
@ -312,7 +327,11 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
|
|||
break;\n \
|
||||
}\n \
|
||||
SurfaceBRDF surface_brdf = brdf(light_info.direction, surface_info);\n";
|
||||
|
||||
|
||||
if(render_options.enable_normal_mapping && material.normalProperty.type == DataType::AssetTexture && render_options.enable_normal_shadowing) {
|
||||
src += std::string("light_info.radiance *= calculate_normal_lighting(normalTexture, final_normal, light_info.direction);\n");
|
||||
}
|
||||
|
||||
src += "Lo += ((surface_brdf.specular + surface_brdf.diffuse) * light_info.radiance * surface_brdf.NdotL) * scene.lights[i].colorSize.rgb;\n \
|
||||
}\n";
|
||||
|
||||
|
|
Reference in a new issue