Using local Gltf structure
This commit is contained in:
parent
c9428a281e
commit
1abee6e84c
5 changed files with 29 additions and 40 deletions
|
|
@ -48,6 +48,8 @@ extern std::vector<std::string> defaultSearchPaths;
|
|||
|
||||
#include "nvh/alignment.hpp"
|
||||
#include "shaders/binding.glsl"
|
||||
#include "shaders/gltf.glsl"
|
||||
|
||||
|
||||
// Holding the camera matrices
|
||||
struct CameraMatrices
|
||||
|
|
@ -237,11 +239,19 @@ void HelloVulkan::loadScene(const std::string& filename)
|
|||
m_alloc.createBuffer(cmdBuf, m_gltfScene.m_indices,
|
||||
vkBU::eIndexBuffer | vkBU::eStorageBuffer | vkBU::eShaderDeviceAddress
|
||||
| vkBU::eAccelerationStructureBuildInputReadOnlyKHR);
|
||||
m_normalBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_normals,
|
||||
m_normalBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_normals,
|
||||
vkBU::eVertexBuffer | vkBU::eStorageBuffer);
|
||||
m_uvBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_texcoords0,
|
||||
m_uvBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_texcoords0,
|
||||
vkBU::eVertexBuffer | vkBU::eStorageBuffer);
|
||||
m_materialBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_materials, vkBU::eStorageBuffer);
|
||||
|
||||
// Copying all materials, only the elements we need
|
||||
std::vector<GltfShadeMaterial> shadeMaterials;
|
||||
for(auto& m : m_gltfScene.m_materials)
|
||||
{
|
||||
shadeMaterials.emplace_back(
|
||||
GltfShadeMaterial{m.pbrBaseColorFactor, m.pbrBaseColorTexture, m.emissiveFactor});
|
||||
}
|
||||
m_materialBuffer = m_alloc.createBuffer(cmdBuf, shadeMaterials, vkBU::eStorageBuffer);
|
||||
|
||||
// Instance Matrices used by rasterizer
|
||||
std::vector<nvmath::mat4f> nodeMatrices;
|
||||
|
|
@ -844,7 +854,7 @@ void HelloVulkan::createRtShaderBindingTable()
|
|||
auto result = m_device.getRayTracingShaderGroupHandlesKHR(m_rtPipeline, 0, groupCount, sbtSize,
|
||||
shaderHandleStorage.data());
|
||||
if(result != vk::Result::eSuccess)
|
||||
LOGE("Fail getRayTracingShaderGroupHandlesKHR: %s", vk::to_string(result));
|
||||
LOGE("Fail getRayTracingShaderGroupHandlesKHR: %s", vk::to_string(result).c_str());
|
||||
|
||||
// Write the handles in the SBT
|
||||
m_rtSBTBuffer = m_alloc.createBuffer(
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ layout(location = 4) in vec3 worldPos;
|
|||
// Outgoing
|
||||
layout(location = 0) out vec4 outColor;
|
||||
// Buffers
|
||||
layout(set = 0, binding = B_MATERIALS) buffer _GltfMaterial { GltfMaterial materials[]; };
|
||||
layout(set = 0, binding = B_MATERIALS) buffer _GltfMaterial { GltfShadeMaterial materials[]; };
|
||||
layout(set = 0, binding = B_TEXTURES) uniform sampler2D[] textureSamplers;
|
||||
|
||||
// clang-format on
|
||||
|
|
@ -37,7 +37,7 @@ layout(set = 0, binding = B_TEXTURES) uniform sampler2D[] textureSamplers;
|
|||
void main()
|
||||
{
|
||||
// Material of the object
|
||||
GltfMaterial mat = materials[nonuniformEXT(pushC.matetrialId)];
|
||||
GltfShadeMaterial mat = materials[nonuniformEXT(pushC.matetrialId)];
|
||||
|
||||
vec3 N = normalize(fragNormal);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,12 @@
|
|||
|
||||
struct GltfMaterial
|
||||
struct GltfShadeMaterial
|
||||
{
|
||||
int shadingModel; // 0: metallic-roughness, 1: specular-glossiness
|
||||
|
||||
// PbrMetallicRoughness
|
||||
vec4 pbrBaseColorFactor;
|
||||
int pbrBaseColorTexture;
|
||||
float pbrMetallicFactor;
|
||||
float pbrRoughnessFactor;
|
||||
int pbrMetallicRoughnessTexture;
|
||||
|
||||
// KHR_materials_pbrSpecularGlossiness
|
||||
vec4 khrDiffuseFactor;
|
||||
int khrDiffuseTexture;
|
||||
vec3 khrSpecularFactor;
|
||||
float khrGlossinessFactor;
|
||||
int khrSpecularGlossinessTexture;
|
||||
|
||||
int emissiveTexture;
|
||||
vec3 emissiveFactor;
|
||||
int alphaMode;
|
||||
float alphaCutoff;
|
||||
bool doubleSided;
|
||||
|
||||
int normalTexture;
|
||||
float normalTextureScale;
|
||||
int occlusionTexture;
|
||||
float occlusionTextureStrength;
|
||||
vec4 pbrBaseColorFactor;
|
||||
int pbrBaseColorTexture;
|
||||
vec3 emissiveFactor;
|
||||
};
|
||||
|
||||
#ifndef __cplusplus
|
||||
struct PrimMeshInfo
|
||||
{
|
||||
uint indexOffset;
|
||||
|
|
@ -37,14 +15,14 @@ struct PrimMeshInfo
|
|||
};
|
||||
|
||||
|
||||
vec3 computeDiffuse(GltfMaterial mat, vec3 lightDir, vec3 normal)
|
||||
vec3 computeDiffuse(GltfShadeMaterial mat, vec3 lightDir, vec3 normal)
|
||||
{
|
||||
// Lambertian
|
||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||
return mat.pbrBaseColorFactor.xyz * dotNL;
|
||||
}
|
||||
|
||||
vec3 computeSpecular(GltfMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||
vec3 computeSpecular(GltfShadeMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||
{
|
||||
// Compute specular only if not in shadow
|
||||
const float kPi = 3.14159265;
|
||||
|
|
@ -58,3 +36,4 @@ vec3 computeSpecular(GltfMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
|||
|
||||
return vec3(specular);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ layout(set = 1, binding = B_VERTICES) readonly buffer _VertexBuf {float vertices
|
|||
layout(set = 1, binding = B_INDICES) readonly buffer _Indices {uint indices[];};
|
||||
layout(set = 1, binding = B_NORMALS) readonly buffer _NormalBuf {float normals[];};
|
||||
layout(set = 1, binding = B_TEXCOORDS) readonly buffer _TexCoordBuf {float texcoord0[];};
|
||||
layout(set = 1, binding = B_MATERIALS) readonly buffer _MaterialBuffer {GltfMaterial materials[];};
|
||||
layout(set = 1, binding = B_MATERIALS) readonly buffer _MaterialBuffer {GltfShadeMaterial materials[];};
|
||||
layout(set = 1, binding = B_TEXTURES) uniform sampler2D texturesMap[]; // all textures
|
||||
|
||||
|
||||
|
|
@ -107,8 +107,8 @@ void main()
|
|||
|
||||
// https://en.wikipedia.org/wiki/Path_tracing
|
||||
// Material of the object
|
||||
GltfMaterial mat = materials[nonuniformEXT(matIndex)];
|
||||
vec3 emittance = mat.emissiveFactor;
|
||||
GltfShadeMaterial mat = materials[nonuniformEXT(matIndex)];
|
||||
vec3 emittance = mat.emissiveFactor;
|
||||
|
||||
// Pick a random direction from here and keep going.
|
||||
vec3 tangent, bitangent;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ layout(set = 1, binding = B_VERTICES) readonly buffer _VertexBuf {float vertices
|
|||
layout(set = 1, binding = B_INDICES) readonly buffer _Indices {uint indices[];};
|
||||
layout(set = 1, binding = B_NORMALS) readonly buffer _NormalBuf {float normals[];};
|
||||
layout(set = 1, binding = B_TEXCOORDS) readonly buffer _TexCoordBuf {float texcoord0[];};
|
||||
layout(set = 1, binding = B_MATERIALS) readonly buffer _MaterialBuffer {GltfMaterial materials[];};
|
||||
layout(set = 1, binding = B_MATERIALS) readonly buffer _MaterialBuffer {GltfShadeMaterial materials[];};
|
||||
layout(set = 1, binding = B_TEXTURES) uniform sampler2D texturesMap[]; // all textures
|
||||
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ void main()
|
|||
}
|
||||
|
||||
// Material of the object
|
||||
GltfMaterial mat = materials[nonuniformEXT(matIndex)];
|
||||
GltfShadeMaterial mat = materials[nonuniformEXT(matIndex)];
|
||||
|
||||
// Diffuse
|
||||
vec3 diffuse = computeDiffuse(mat, L, world_normal);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue