Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom support for gltf2.0 file format #1061

Open
wants to merge 27 commits into
base: release-candidate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
36f387a
[core] add gltf material asset management
MathiasPaulin Jul 19, 2023
f692e1a
[engine] add gltf material support
MathiasPaulin Jul 19, 2023
fd8553f
[shaders] add gltf material support
MathiasPaulin Jul 19, 2023
9d3cee7
[script] update IO filelist generator to manage gltf loader/writer ex…
MathiasPaulin Jul 19, 2023
f1d3de3
[IO] add gltf 2.0 custom file loader and writer
MathiasPaulin Jul 19, 2023
c1969ca
[gui] add gltf 2.0 custom file loader support
MathiasPaulin Jul 19, 2023
8d8c397
[example] use gltf 2.0 custom file writer if enable
MathiasPaulin Jul 19, 2023
987def4
[io] fix precompile header problem other language than C++
MathiasPaulin Jul 19, 2023
59fd39a
[radium] add GLTF status in the configure summary
MathiasPaulin Jul 19, 2023
b4a2c48
[doc] add GLTF 2.0 support status in the documentation
MathiasPaulin Jul 19, 2023
78349ba
[io] fix codacy on gltf internals
MathiasPaulin Jul 20, 2023
7dc07cf
[io] fix codacy on gltf internals
MathiasPaulin Jul 20, 2023
385a6a2
[io] fix codacy on gltf internals
MathiasPaulin Jul 20, 2023
e2a7a36
[io] gltf loader now loads 2 texture coordinateSet (but still transmi…
MathiasPaulin Jul 25, 2023
47ae2f1
[engine] add support for KHR_unlit material extension
MathiasPaulin Jul 25, 2023
e61bc3c
[doc] add notes on extensions
MathiasPaulin Jul 25, 2023
a22c360
[io] decode uri from gltf json
MathiasPaulin Jul 25, 2023
8a84290
[engine] simplify gltf files
MathiasPaulin Jul 25, 2023
ebf2f25
[io] fix material extension howto
MathiasPaulin Jul 25, 2023
d4b9e82
[io] loads interleaved buffers
MathiasPaulin Jul 25, 2023
d445224
[engine] allows pervertex color for any materials (missing code)
MathiasPaulin Jul 26, 2023
6d6e56d
[io] loads gltf color buffer (only one as requested by the spec)
MathiasPaulin Jul 26, 2023
984340d
[engine] gltf material support pervertex color
MathiasPaulin Jul 26, 2023
d85e9a9
[io] remove reinterpret_cast when loading gltf
MathiasPaulin Jul 26, 2023
6a4274a
[core] improve doc
MathiasPaulin Aug 1, 2023
ea48c90
[io] remove warnings in gltf mikktspace.c
MathiasPaulin Aug 29, 2023
0d5abb8
[engine] fix culling when material is singleSided
MathiasPaulin Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ if(NOT ${RADIUM_MISSING_COMPONENTS} STREQUAL "")
message_info(" -- Missing components: ${COMPONENTS_LIST} (see log to find why)")
endif()
message_setting("RADIUM_IO_ASSIMP")
message_setting("RADIUM_IO_GLTF")
message_setting("RADIUM_IO_GLTF_WRITER")
message_setting("RADIUM_IO_TINYPLY")
message_setting("RADIUM_IO_VOLUMES")
message_setting("RADIUM_IO_DEPRECATED")
Expand Down
Binary file added Shaders/Materials/GLTF/BSDF_LUTs/lut_charlie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shaders/Materials/GLTF/BSDF_LUTs/lut_ggx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shaders/Materials/GLTF/BSDF_LUTs/lut_sheen_E.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions Shaders/Materials/GLTF/Materials/MetallicRoughness.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef METALLICROUGHNESS_GLSL
#define METALLICROUGHNESS_GLSL
#include "baseGLTFMaterial.glsl"

struct Material {
GLTFBaseMaterial baseMaterial;
vec4 baseColorFactor;
float metallicFactor;
float roughnessFactor;
#ifdef TEXTURE_BASECOLOR
sampler2D baseColor;
# ifdef TEXTURE_COORD_TRANSFORM_BASECOLOR
mat3 baseTransform;
# endif
#endif
#ifdef TEXTURE_METALLICROUGHNESS
sampler2D metallicRoughness;
# ifdef TEXTURE_COORD_TRANSFORM_METALLICROUGHNESS
mat3 metallicRoughnessTransform;
# endif
#endif
};

bool toDiscard( Material material, vec4 color ) {
return toDiscardBase( material.baseMaterial, color );
}

vec3 getEmissiveColor( Material material, vec3 textCoord ) {
return getEmissiveColorBase( material.baseMaterial, textCoord );
}

vec4 getBaseColor( Material material, vec3 texCoord ) {
vec4 basecolor = material.baseColorFactor;

#ifdef TEXTURE_BASECOLOR
vec2 tc = texCoord.xy;
# ifdef TEXTURE_COORD_TRANSFORM_BASECOLOR
tc = ( material.baseTransform * vec3( tc, 1 ) ).xy;
# endif
basecolor *= texture( material.baseColor, tc );
#endif
#ifdef HAS_PERVERTEX_COLOR
basecolor *= getPerVertexBaseColor();
#endif
if ( material.baseMaterial.alphaMode == 1 && basecolor.a < material.baseMaterial.alphaCutoff ) {
basecolor.a = 0;
}
return basecolor;
}

// Metallic and roughness are packed scalars
// Following GLTF specification, Roughness is stored in the 'g' channel, metallic is stored in the
// 'b' channel. The 'r' channel is ignored for MetallicRougness by gltf, we use it to store the
// alphaRoughness
vec3 getMetallicRoughnessFactors( Material material, vec2 tc ) {
vec3 mr = vec3( 0, material.roughnessFactor, material.metallicFactor );
#ifdef TEXTURE_METALLICROUGHNESS
# ifdef TEXTURE_COORD_TRANSFORM_METALLICROUGHNESS
vec2 ct = ( material.metallicRoughnessTransform * vec3( tc, 1 ) ).xy;
# else
vec2 ct = tc;
# endif
vec3 mrsample = texture( material.metallicRoughness, ct ).rgb;
mr = mr * mrsample;
#endif
clamp( mr, vec3( 0, c_MinRoughness, 0 ), vec3( 0, 1, 1 ) );
mr.r = mr.g * mr.g;
return mr;
}

int extractBSDFParameters( Material material, vec3 tc, NormalInfo N, inout MaterialInfo params ) {
params.basecolor = getBaseColor( material, tc ).rgb;
params.f0 = vec3( dielectricSpecular( material.baseMaterial.ior ) );
params.f90 = vec3( 1 ); // f90( wich color to use ?)
params.RoughnessMetalness = getMetallicRoughnessFactors( material, tc.xy );
params.diffusebase = mix( params.basecolor, vec3( 0 ), params.RoughnessMetalness.b );
params.f0 = mix( params.f0, params.basecolor, params.RoughnessMetalness.b );
// In case an extension want to modify the material data ...
return extractBSDFParametersBase( material.baseMaterial, tc, N, params );
}

int getSeparateBSDFComponent( Material material,
vec3 tc,
vec3 V,
NormalInfo N,
inout MaterialInfo params,
out BsdfInfo layers ) {
if ( extractBSDFParameters( material, tc, N, params ) == 1 )
{
return getSeparateBSDFComponentBase(
material.baseMaterial, params, N, V, layers );
}
else
{ return 0; }
}

BsdfInfo evaluateBSDF( Material material,
MaterialInfo bsdf_params,
NormalInfo N,
vec3 wi,
vec3 wo,
vec3 light_intensity ) {
return evaluateBSDFBase( material.baseMaterial, bsdf_params, N, wi, wo, light_intensity );
}

uniform Material material;

#endif // METALLICROUGHNESS_GLSL
104 changes: 104 additions & 0 deletions Shaders/Materials/GLTF/Materials/SpecularGlossiness.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#ifndef SPECULARGLOSSINESS_GLSL
#define SPECULARGLOSSINESS_GLSL
#include "baseGLTFMaterial.glsl"

struct Material {
GLTFBaseMaterial baseMaterial;
vec4 diffuseFactor;
vec4 specularFactor;
float glossinessFactor;
#ifdef TEXTURE_DIFFUSE
sampler2D diffuse;
# ifdef TEXTURE_COORD_TRANSFORM_DIFFUSE
mat3 diffuseTransform;
# endif
#endif
#ifdef TEXTURE_SPECULARGLOSSINESS
sampler2D specularGlossiness;
# ifdef TEXTURE_COORD_TRANSFORM_SPECULARGLOSSINESS
mat3 specularGlossinessTransform;
# endif
#endif
};

bool toDiscard( Material material, vec4 color ) {
return toDiscardBase( material.baseMaterial, color );
}

vec3 getEmissiveColor( Material material, vec3 textCoord ) {
return getEmissiveColorBase( material.baseMaterial, textCoord );
}

vec4 getBaseColor( Material material, vec3 texCoord ) {
vec4 basecolor = material.diffuseFactor;
#ifdef TEXTURE_DIFFUSE
# ifdef TEXTURE_COORD_TRANSFORM_DIFFUSE
vec2 ct = ( material.diffuseTransform * vec3( texCoord.xy, 1 ) ).xy;
# else
vec2 ct = texCoord.xy;
# endif
basecolor *= texture( material.diffuse, ct );
#endif
#ifdef HAS_PERVERTEX_COLOR
return basecolor * getPerVertexBaseColor();
#else
return basecolor;
#endif
}

// Specular and glossiness are packed scalars
// Following GLTF specification, Specular is stored in the 'rgb' channel, glossiness is stored in
// the 'a' channel. The 'a' channel of the returned color is the computed alphaRoughness of the BSDF
// model
vec4 getSpecularGlossinessFactor( Material material, vec2 tc ) {
vec4 specGloss = vec4( material.specularFactor.rgb, material.glossinessFactor );
#ifdef TEXTURE_SPECULARGLOSSINESS
# ifdef TEXTURE_COORD_TRANSFORM_SPECULARGLOSSINESS
vec2 ct = ( material.specularGlossinessTransform * vec3( tc, 1 ) ).xy;
# else
vec2 ct = tc;
# endif
specGloss *= texture( material.specularGlossiness, ct );
#endif
// convert glossinesss to the alpha roughness (alpha = (1-glossiness)^2
specGloss.a = ( 1 - specGloss.a );
clamp( specGloss.a, c_MinRoughness, 1 );
return specGloss;
}

int extractBSDFParameters( Material material, vec3 tc, NormalInfo N, inout MaterialInfo params ) {
params.basecolor = getBaseColor( material, tc ).rgb;
vec4 spec_gloss = getSpecularGlossinessFactor( material, tc.xy );
params.f0 = spec_gloss.rgb;
params.f90 = vec3( 1 ); // f90( wich color to use ?)
params.RoughnessMetalness = vec3( spec_gloss.a * spec_gloss.a, spec_gloss.a, 0. );
params.diffusebase =
params.basecolor * ( 1. - max( max( params.f0.r, params.f0.g ), params.f0.b ) );
// In case an extension want to modify the material data ...
return extractBSDFParametersBase( material.baseMaterial, tc, N, params );
}

int getSeparateBSDFComponent( Material material,
vec3 tc,
vec3 V,
NormalInfo N,
inout MaterialInfo params,
out BsdfInfo layers ) {
if ( extractBSDFParameters( material, tc, N, params ) == 1 )
{ return getSeparateBSDFComponentBase( material.baseMaterial, params, N, V, layers ); }
else
{ return 0; }
}

BsdfInfo evaluateBSDF( Material material,
MaterialInfo bsdf_params,
NormalInfo N,
vec3 wi,
vec3 wo,
vec3 light_intensity ) {
return evaluateBSDFBase( material.baseMaterial, bsdf_params, N, wi, wo, light_intensity );
}

uniform Material material;

#endif // SPECULARGLOSSINESS_GLSL
Loading