#ifndef MATERIAL_GLSL #define MATERIAL_GLSL // You have to enable GL_ARB_bindless_texture extension if you're importing this struct Material { vec4 albedo; sampler2D albedo_map; vec2 albedo_map_uv_scale; sampler2D normal_map; vec2 normal_map_uv_scale; float metallic; sampler2D metallic_map; vec2 metallic_map_uv_scale; float roughness; sampler2D roughness_map; vec2 roughness_map_uv_scale; vec3 emission; sampler2D emission_map; vec2 emission_map_uv_scale; }; layout(std430, binding = 2) readonly buffer Materials { uint materials_count; Material materials[]; }; vec4 getAlbedo(int materialIdx) { return textureSize(materials[materialIdx].albedo_map, 0) == ivec2(0) ? vec4(pow(materials[materialIdx].albedo.rgb, vec3(2.2)), materials[materialIdx].albedo.a) : texture(materials[materialIdx].albedo_map, VertexOut.uv * materials[materialIdx].albedo_map_uv_scale); } float getRoughness(int materialIdx) { return max(0.01, textureSize(materials[materialIdx].roughness_map, 0) == ivec2(0) ? materials[materialIdx].roughness : texture(materials[materialIdx].roughness_map, VertexOut.uv * materials[materialIdx].roughness_map_uv_scale).g); } float getMetallic(int materialIdx) { return textureSize(materials[materialIdx].metallic_map, 0) == ivec2(0) ? materials[materialIdx].metallic : texture(materials[materialIdx].metallic_map, VertexOut.uv * materials[materialIdx].metallic_map_uv_scale).b; } vec3 getEmission(int materialIdx) { return textureSize(materials[materialIdx].emission_map, 0) == ivec2(0) ? materials[materialIdx].emission : texture(materials[materialIdx].emission_map, VertexOut.uv * materials[materialIdx].emission_map_uv_scale).rgb; } #endif // MATERIAL_GLSL