New example, loading glTF scenes instead of individual OBJ. Showing simple path tracing and how to make it 3x faster.
This commit is contained in:
parent
813f392fdf
commit
2eb9b6e522
25 changed files with 4410 additions and 2 deletions
60
ray_tracing_gltf/shaders/gltf.glsl
Normal file
60
ray_tracing_gltf/shaders/gltf.glsl
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
struct GltfMaterial
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
struct PrimMeshInfo
|
||||
{
|
||||
uint indexOffset;
|
||||
uint vertexOffset;
|
||||
int materialIndex;
|
||||
};
|
||||
|
||||
|
||||
vec3 computeDiffuse(GltfMaterial 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)
|
||||
{
|
||||
// Compute specular only if not in shadow
|
||||
const float kPi = 3.14159265;
|
||||
const float kShininess = 60.0;
|
||||
|
||||
// Specular
|
||||
const float kEnergyConservation = (2.0 + kShininess) / (2.0 * kPi);
|
||||
vec3 V = normalize(-viewDir);
|
||||
vec3 R = reflect(-lightDir, normal);
|
||||
float specular = kEnergyConservation * pow(max(dot(V, R), 0.0), kShininess);
|
||||
|
||||
return vec3(specular);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue