mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Introducing the TextureTable in the gpu shader system
This commit is contained in:
parent
ea23d8283f
commit
536ada3973
3 changed files with 90 additions and 5 deletions
|
@ -50,6 +50,12 @@ static const std::string stereoVersion {
|
|||
#endif
|
||||
};
|
||||
|
||||
// TextureTable specific defines
|
||||
static const std::string textureTableVersion {
|
||||
"#extension GL_ARB_bindless_texture : require\n#define GPU_TEXTURE_TABLE_BINDLESS\n"
|
||||
};
|
||||
|
||||
|
||||
// Versions specific of the shader
|
||||
static const std::array<std::string, GLShader::NumVersions> VERSION_DEFINES { {
|
||||
"",
|
||||
|
@ -64,10 +70,15 @@ GLShader* GLBackend::compileBackendShader(const Shader& shader, const Shader::Co
|
|||
Shader::CompilationLogs compilationLogs(GLShader::NumVersions);
|
||||
shader.incrementCompilationAttempt();
|
||||
|
||||
bool supportTextureTableBindless = true;
|
||||
|
||||
for (int version = 0; version < GLShader::NumVersions; version++) {
|
||||
auto& shaderObject = shaderObjects[version];
|
||||
|
||||
std::string shaderDefines = getBackendShaderHeader() + "\n" + DOMAIN_DEFINES[shader.getType()] + "\n" + VERSION_DEFINES[version];
|
||||
std::string shaderDefines = getBackendShaderHeader() + "\n"
|
||||
+ (supportTextureTableBindless ? textureTableVersion : "\n")
|
||||
+ DOMAIN_DEFINES[shader.getType()] + "\n"
|
||||
+ VERSION_DEFINES[version];
|
||||
if (handler) {
|
||||
bool retest = true;
|
||||
std::string currentSrc = shaderSource;
|
||||
|
@ -89,7 +100,7 @@ GLShader* GLBackend::compileBackendShader(const Shader& shader, const Shader::Co
|
|||
compilationLogs[version].compiled = ::gl::compileShader(shaderDomain, shaderSource, shaderDefines, shaderObject.glshader, compilationLogs[version].message);
|
||||
}
|
||||
|
||||
if (!compilationLogs[version].compiled) {
|
||||
if (!compilationLogs[version].compiled) {
|
||||
qCWarning(gpugllogging) << "GLBackend::compileBackendProgram - Shader didn't compile:\n" << compilationLogs[version].message.c_str();
|
||||
shader.setCompilationLogs(compilationLogs);
|
||||
return nullptr;
|
||||
|
|
|
@ -13,11 +13,13 @@
|
|||
#ifdef GPU_TEXTURE_TABLE_BINDLESS
|
||||
#define GPU_TEXTURE_TABLE_MAX_NUM_TEXTURES 8
|
||||
|
||||
struct TextureTable {
|
||||
uvec4 _textures[GPU_TEXTURE_TABLE_MAX_NUM_TEXTURES];
|
||||
struct GPUTextureTable {
|
||||
uvec2 _textures[GPU_TEXTURE_TABLE_MAX_NUM_TEXTURES];
|
||||
};
|
||||
|
||||
#define TextureTable(index) layout (std140) uniform gpu_textureTableBuffer##index { TextureTable _table##index; };
|
||||
#define TextureTable(index, name) layout (std140) uniform gpu_textureTableBuffer { GPUTextureTable name; }
|
||||
|
||||
#define tableTex(name, slot) sampler2D(name._textures[slot])
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -48,6 +48,76 @@ TexMapArray getTexMapArray() {
|
|||
|
||||
<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion, withScattering)@>
|
||||
|
||||
|
||||
|
||||
<@include gpu/TextureTable.slh@>
|
||||
|
||||
TextureTable(0, matTex);
|
||||
<!
|
||||
EMISSIVE_MAP = 0,
|
||||
ALBEDO_MAP,
|
||||
METALLIC_MAP,
|
||||
ROUGHNESS_MAP,
|
||||
NORMAL_MAP,
|
||||
OCCLUSION_MAP,
|
||||
LIGHTMAP_MAP,
|
||||
SCATTERING_MAP,
|
||||
!>
|
||||
|
||||
<@if withAlbedo@>
|
||||
#define albedoMap 1
|
||||
vec4 fetchAlbedoMap(vec2 uv) {
|
||||
return texture(tableTex(matTex, albedoMap), uv);
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withRoughness@>
|
||||
#define roughnessMap 3
|
||||
float fetchRoughnessMap(vec2 uv) {
|
||||
return (texture(tableTex(matTex, roughnessMap), uv).r);
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withNormal@>
|
||||
#define normalMap 4
|
||||
vec3 fetchNormalMap(vec2 uv) {
|
||||
return texture(tableTex(matTex, normalMap), uv).xyz;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withMetallic@>
|
||||
#define metallicMap 2
|
||||
float fetchMetallicMap(vec2 uv) {
|
||||
return (texture(tableTex(matTex, metallicMap), uv).r);
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withEmissive@>
|
||||
#define emissiveMap 0
|
||||
vec3 fetchEmissiveMap(vec2 uv) {
|
||||
return texture(tableTex(matTex, emissiveMap), uv).rgb;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withOcclusion@>
|
||||
#define occlusionMap 5
|
||||
float fetchOcclusionMap(vec2 uv) {
|
||||
return texture(tableTex(matTex, occlusionMap), uv).r;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<@if withScattering@>
|
||||
#define scatteringMap 7
|
||||
float fetchScatteringMap(vec2 uv) {
|
||||
float scattering = texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now
|
||||
return max(((scattering - 0.1) / 0.9), 0.0);
|
||||
return texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
<!
|
||||
<@else@>
|
||||
|
||||
<@if withAlbedo@>
|
||||
uniform sampler2D albedoMap;
|
||||
vec4 fetchAlbedoMap(vec2 uv) {
|
||||
|
@ -101,6 +171,8 @@ float fetchScatteringMap(vec2 uv) {
|
|||
return texture(scatteringMap, uv).r; // boolean scattering for now
|
||||
}
|
||||
<@endif@>
|
||||
<@endif@>
|
||||
!>
|
||||
|
||||
<@endfunc@>
|
||||
|
||||
|
|
Loading…
Reference in a new issue