Skip to content

Commit

Permalink
Add EsslShaderGenerator and Three.js based sample app (JsMaterialXVie…
Browse files Browse the repository at this point in the history
…w) (#1244)

* Rough GLES generator setup.

* Fix incorrect target inheritance.

* fixed copying of library folder

* initial materialx web viewer implementation with dummy shader (#1207)

* Adapt ESSLShaderGenerator for WebGL2 (#1211)

* Minimize required code changes between Glsl and Essl shadergen by exposing more `emit` functions
* Get correct vertex prefix for Essl in the node implementations.
* Update three js sample to render standard_surface_default material

Co-authored-by: dunkels <sebastian.dunkel@autodesk.com>
Co-authored-by: kohakukun <aura.munoz@autodesk.com>

* fix: Cleanup essl context for new documents (#1226)

Co-authored-by: kohakukun <aura.munoz@autodesk.com>

* fix: Add explicit casting for switch statement (#1227)

Co-authored-by: kohakukun <aura.munoz@autodesk.com>

* clean up, add entry for Essl shader generation option to Viewer.md (#1228)

* fix: stdlib explicit cast for essl compatibility (#1229)

* add precission to vertex shader

* fix: Add explicit cast for ess compatibility

* address comments

* quick fix

Co-authored-by: kohakukun <aura.munoz@autodesk.com>

* Enable mipmap generation for JsMaterialXView (#1242)

* Throw if EsslShaderGenerator has access to a resource binding context (#1230)

* clean up (#1247)

* clean up pass 2

Co-authored-by: bernardkwok <bernard.kwok@autodesk.com>
Co-authored-by: dunkels <sebastian.dunkel@autodesk.com>
Co-authored-by: Sebastian Dunkel <sdunkel@users.noreply.github.com>
Co-authored-by: kohakukun <aura.munoz@autodesk.com>
Co-authored-by: Aura Munoz <paraprogramar@gmail.com>
  • Loading branch information
6 people committed Jul 1, 2021
1 parent e6c8c39 commit f21a4db
Show file tree
Hide file tree
Showing 55 changed files with 2,456 additions and 185 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ option(MATERIALX_BUILD_CONTRIB "Build contribution folder." ON)
option(MATERIALX_BUILD_CROSS "Build MaterialXCross folder." OFF)
option(MATERIALX_BUILD_GEN_OGSXML "Build the OGSXML shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_OGSFX "Build the OGSFX shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_ESSL "Build the ESSL shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_ARNOLD "Build the Arnold OSL shader generator back-end." ON)
option(MATERIALX_BUILD_RUNTIME "Build the MaterialX Runtime data model library." OFF)

Expand All @@ -142,18 +143,23 @@ if (MATERIALX_BUILD_GEN_OGSFX)
set(MATERIALX_BUILD_GEN_GLSL ON)
endif()

if (MATERIALX_BUILD_GEN_ESSL)
set(MATERIALX_BUILD_GEN_GLSL ON)
endif()

if (MATERIALX_BUILD_GEN_OGSXML)
set(MATERIALX_BUILD_GEN_GLSL ON)
endif()

if (MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_OGSXML OR MATERIALX_BUILD_GEN_OGSFX OR MATERIALX_BUILD_GEN_ARNOLD)
if (MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_OGSXML OR MATERIALX_BUILD_GEN_OGSFX OR MATERIALX_BUILD_GEN_ESSL OR MATERIALX_BUILD_GEN_ARNOLD)
set(MATERIALX_BUILD_GEN ON)
else()
set(MATERIALX_BUILD_GEN OFF)
endif()

mark_as_advanced(MATERIALX_BUILD_GEN_OGSXML)
mark_as_advanced(MATERIALX_BUILD_GEN_OGSFX)
mark_as_advanced(MATERIALX_BUILD_GEN_ESSL)
mark_as_advanced(MATERIALX_BUILD_GEN_ARNOLD)
mark_as_advanced(MATERIALX_BUILD_CROSS)
mark_as_advanced(MATERIALX_BUILD_GEN)
Expand Down Expand Up @@ -291,6 +297,10 @@ if (MATERIALX_BUILD_GEN)
add_definitions(-DMATERIALX_BUILD_GEN_OGSFX)
add_subdirectory(source/MaterialXGenOgsFx)
endif()
if (MATERIALX_BUILD_GEN_ESSL)
add_definitions(-DMATERIALX_BUILD_GEN_ESSL)
add_subdirectory(source/MaterialXGenEssl)
endif()
if (MATERIALX_BUILD_GEN_ARNOLD)
add_definitions(-DMATERIALX_BUILD_GEN_ARNOLD)
add_subdirectory(source/MaterialXGenArnold)
Expand Down
1 change: 1 addition & 0 deletions documents/DeveloperGuide/Viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ By default, the MaterialX viewer loads and saves image files using `stb_image`,

- `R`: Reload the current material from file. Hold `SHIFT` to reload all standard libraries as well.
- `G`: Save the current GLSL shader source to file.
- `E`: Save the current ESSL (OpenGL ES 3.0) shader source to file.
- `O`: Save the current OSL shader source to file.
- `M`: Save the current MDL shader source to file.
- `L`: Load GLSL shader source from file. Editing the source files before loading provides a way to debug and experiment with shader source code.
Expand Down
4 changes: 2 additions & 2 deletions libraries/pbrlib/genglsl/lib/mx_environment_fis.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ float mx_latlong_compute_lod(vec3 dir, float pdf, float maxMipLevel, int envSamp
const float MIP_LEVEL_OFFSET = 1.5;
float effectiveMaxMipLevel = maxMipLevel - MIP_LEVEL_OFFSET;
float distortion = sqrt(1.0 - mx_square(dir.y));
return max(effectiveMaxMipLevel - 0.5 * log2(envSamples * pdf * distortion), 0.0);
return max(effectiveMaxMipLevel - 0.5 * log2(float(envSamples) * pdf * distortion), 0.0);
}

vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 roughness, int distribution, FresnelData fd)
Expand Down Expand Up @@ -43,7 +43,7 @@ vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 roughness, int distrib

// Sample the environment light from the given direction.
float pdf = mx_ggx_PDF(X, Y, H, NdotH, LdotH, roughness.x, roughness.y);
float lod = mx_latlong_compute_lod(L, pdf, $envRadianceMips - 1, envRadianceSamples);
float lod = mx_latlong_compute_lod(L, pdf, float($envRadianceMips - 1), envRadianceSamples);
vec3 sampleColor = mx_latlong_map_lookup(L, $envMatrix, lod, $envRadiance);

// Compute the Fresnel term.
Expand Down
2 changes: 1 addition & 1 deletion libraries/pbrlib/genglsl/lib/mx_environment_prefilter.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ float mx_latlong_compute_lod(float roughness)
{
// Select a mip level based on input roughness.
float lodBias = roughness < 0.25 ? sqrt(roughness) : 0.5*roughness + 0.375;
return lodBias * $envRadianceMips;
return lodBias * float($envRadianceMips);
}

vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 roughness, int distribution, FresnelData fd)
Expand Down
6 changes: 3 additions & 3 deletions libraries/pbrlib/genglsl/lib/mx_microfacet_diffuse.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ float mx_burley_diffuse(vec3 L, vec3 V, vec3 N, float NdotL, float roughness)
float mx_burley_diffuse_directional_albedo(float NdotV, float roughness)
{
float x = NdotV;
float fit0 = 0.97619 - 0.488095 * mx_pow5(1 - x);
float fit0 = 0.97619 - 0.488095 * mx_pow5(1.0 - x);
float fit1 = 1.55754 + (-2.02221 + (2.56283 - 1.06244 * x) * x) * x;
return mix(fit0, fit1, roughness);
}
Expand Down Expand Up @@ -63,10 +63,10 @@ vec3 mx_integrate_burley_diffusion(vec3 N, vec3 L, float radius, vec3 mfp)
vec3 sumD = vec3(0.0);
vec3 sumR = vec3(0.0);
const int SAMPLE_COUNT = 32;
const float SAMPLE_WIDTH = (2.0 * M_PI) / SAMPLE_COUNT;
const float SAMPLE_WIDTH = (2.0 * M_PI) / float(SAMPLE_COUNT);
for (int i = 0; i < SAMPLE_COUNT; i++)
{
float x = -M_PI + (i + 0.5) * SAMPLE_WIDTH;
float x = -M_PI + (float(i) + 0.5) * SAMPLE_WIDTH;
float dist = radius * abs(2.0 * sin(x * 0.5));
vec3 R = mx_burley_diffusion_profile(dist, shape);
sumD += R * max(cos(theta + x), 0.0);
Expand Down
8 changes: 4 additions & 4 deletions libraries/pbrlib/genglsl/lib/mx_microfacet_sheen.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const float u_sheenAlbedo[SHEEN_ALBEDO_TABLE_SIZE*SHEEN_ALBEDO_TABLE_SIZE] = flo

float mx_imageworks_sheen_directional_albedo(float cosTheta, float roughness)
{
float x = cosTheta * (SHEEN_ALBEDO_TABLE_SIZE - 1);
float y = roughness * (SHEEN_ALBEDO_TABLE_SIZE - 1);
float x = cosTheta * float(SHEEN_ALBEDO_TABLE_SIZE - 1);
float y = roughness * float(SHEEN_ALBEDO_TABLE_SIZE - 1);
int ix = int(x);
int iy = int(y);
int ix2 = clamp(ix + 1, 0, SHEEN_ALBEDO_TABLE_SIZE - 1);
int iy2 = clamp(iy + 1, 0, SHEEN_ALBEDO_TABLE_SIZE - 1);
float fx = x - ix;
float fy = y - iy;
float fx = x - float(ix);
float fy = y - float(iy);

// Bi-linear interpolation of the LUT values
float v1 = mix(u_sheenAlbedo[iy * SHEEN_ALBEDO_TABLE_SIZE + ix], u_sheenAlbedo[iy * SHEEN_ALBEDO_TABLE_SIZE + ix2], fx);
Expand Down
34 changes: 17 additions & 17 deletions libraries/pbrlib/genglsl/lib/mx_microfacet_specular.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ vec3 mx_ggx_directional_albedo_importance_sample(float NdotV, float roughness, v
float Gvis = mx_ggx_smith_G(NdotL, NdotV, roughness) * VdotH / (NdotH * NdotV);

// Add the contribution of this sample.
AB += vec2(Gvis * (1 - Fc), Gvis * Fc);
AB += vec2(Gvis * (1.0 - Fc), Gvis * Fc);
}

// Normalize integrated terms.
AB /= SAMPLE_COUNT;
AB /= float(SAMPLE_COUNT);

// Return the final directional albedo.
return F0 * AB.x + F90 * AB.y;
Expand Down Expand Up @@ -184,7 +184,7 @@ void mx_fresnel_dielectric_polarized(float cosTheta, float n1, float n2, out vec
return;
}

float cosTheta_t = sqrt(1 - eta2 * st2);
float cosTheta_t = sqrt(1.0 - eta2 * st2);
vec2 r = vec2((n2*cosTheta - n1*cosTheta_t) / (n2*cosTheta + n1*cosTheta_t),
(n1*cosTheta - n2*cosTheta_t) / (n1*cosTheta + n2*cosTheta_t));
F = mx_square(r);
Expand All @@ -196,7 +196,7 @@ void mx_fresnel_dielectric_polarized(float cosTheta, float n1, float n2, out vec
// TODO: Optimize this functions and support wavelength dependent complex refraction index.
void mx_fresnel_conductor_polarized(float cosTheta, float n1, float n2, float k, out vec2 F, out vec2 phi)
{
if (k == 0)
if (k == 0.0)
{
// Use dielectric formula to avoid numerical issues
mx_fresnel_dielectric_polarized(cosTheta, n1, n2, F, phi);
Expand All @@ -213,7 +213,7 @@ void mx_fresnel_conductor_polarized(float cosTheta, float n1, float n2, float k,

F.x = (mx_square(mx_square(n2) * (1.0 - mx_square(k)) * cosTheta - n1*U) + mx_square(2.0 * mx_square(n2) * k * cosTheta - n1*V)) /
(mx_square(mx_square(n2) * (1.0 - mx_square(k)) * cosTheta + n1*U) + mx_square(2.0 * mx_square(n2) * k * cosTheta + n1*V));
phi.x = atan(2.0 * n1 * mx_square(n2) * cosTheta * (2*k*U - (1.0 - mx_square(k)) * V), mx_square(mx_square(n2) * (1.0 + mx_square(k)) * cosTheta) - mx_square(n1) * (mx_square(U) + mx_square(V)));
phi.x = atan(2.0 * n1 * mx_square(n2) * cosTheta * (2.0*k*U - (1.0 - mx_square(k)) * V), mx_square(mx_square(n2) * (1.0 + mx_square(k)) * cosTheta) - mx_square(n1) * (mx_square(U) + mx_square(V)));
}

// XYZ to CIE 1931 RGB color space (using neutral E illuminant)
Expand All @@ -233,12 +233,12 @@ vec3 mx_depolarize(vec3 s, vec3 p)
vec3 mx_eval_sensitivity(float opd, float shift)
{
// Use Gaussian fits, given by 3 parameters: val, pos and var
float phase = 2*M_PI * opd;
float phase = 2.0*M_PI * opd;
vec3 val = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);
vec3 pos = vec3(1.6810e+06, 1.7953e+06, 2.2084e+06);
vec3 var = vec3(4.3278e+09, 9.3046e+09, 6.6121e+09);
vec3 xyz = val * sqrt(2*M_PI * var) * cos(pos * phase + shift) * exp(- var * phase*phase);
xyz.x += 9.7470e-14 * sqrt(2*M_PI * 4.5282e+09) * cos(2.2399e+06 * phase + shift) * exp(- 4.5282e+09 * phase*phase);
vec3 xyz = val * sqrt(2.0*M_PI * var) * cos(pos * phase + shift) * exp(- var * phase*phase);
xyz.x += 9.7470e-14 * sqrt(2.0*M_PI * 4.5282e+09) * cos(2.2399e+06 * phase + shift) * exp(- 4.5282e+09 * phase*phase);
return xyz / 1.0685e-7;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ vec3 mx_fresnel_airy(float cosTheta, vec3 ior, vec3 extinction, float tf_thickne
vec3 R = vec3(0.0);
vec2 R123 = R12*R23;
vec2 r123 = sqrt(R123);
vec2 Rs = mx_square(T121)*R23 / (1-R123);
vec2 Rs = mx_square(T121)*R23 / (1.0-R123);

// Reflectance term for m=0 (DC term amplitude)
vec2 C0 = R12 + Rs;
Expand All @@ -287,8 +287,8 @@ vec3 mx_fresnel_airy(float cosTheta, vec3 ior, vec3 extinction, float tf_thickne
for (int m=1; m<=3; ++m)
{
Cm *= r123;
vec3 SmS = 2.0 * mx_eval_sensitivity(m*D, m*phi2.x);
vec3 SmP = 2.0 * mx_eval_sensitivity(m*D, m*phi2.y);
vec3 SmS = 2.0 * mx_eval_sensitivity(float(m)*D, float(m)*phi2.x);
vec3 SmP = 2.0 * mx_eval_sensitivity(float(m)*D, float(m)*phi2.y);
R += mx_depolarize(Cm.x*SmS, Cm.y*SmP);
}

Expand All @@ -311,7 +311,7 @@ struct FresnelData

FresnelData mx_init_fresnel_dielectric(float ior)
{
FresnelData fd = FresnelData(vec3(0), vec3(0), 0, 0, 0, -1);
FresnelData fd = FresnelData(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, -1);
fd.model = 0;
fd.ior = vec3(ior);
fd.tf_thickness = 0.0f;
Expand All @@ -320,7 +320,7 @@ FresnelData mx_init_fresnel_dielectric(float ior)

FresnelData mx_init_fresnel_conductor(vec3 ior, vec3 extinction)
{
FresnelData fd = FresnelData(vec3(0), vec3(0), 0, 0, 0, -1);
FresnelData fd = FresnelData(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, -1);
fd.model = 1;
fd.ior = ior;
fd.extinction = extinction;
Expand All @@ -330,7 +330,7 @@ FresnelData mx_init_fresnel_conductor(vec3 ior, vec3 extinction)

FresnelData mx_init_fresnel_schlick(vec3 F0)
{
FresnelData fd = FresnelData(vec3(0), vec3(0), 0, 0, 0, -1);
FresnelData fd = FresnelData(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, -1);
fd.model = 2;
fd.ior = F0;
fd.extinction = vec3(1.0);
Expand All @@ -341,7 +341,7 @@ FresnelData mx_init_fresnel_schlick(vec3 F0)

FresnelData mx_init_fresnel_schlick(vec3 F0, vec3 F90, float exponent)
{
FresnelData fd = FresnelData(vec3(0), vec3(0), 0, 0, 0, -1);
FresnelData fd = FresnelData(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, -1);
fd.model = 2;
fd.ior = F0;
fd.extinction = F90;
Expand All @@ -352,7 +352,7 @@ FresnelData mx_init_fresnel_schlick(vec3 F0, vec3 F90, float exponent)

FresnelData mx_init_fresnel_dielectric_airy(float ior, float tf_thickness, float tf_ior)
{
FresnelData fd = FresnelData(vec3(0), vec3(0), 0, 0, 0, -1);
FresnelData fd = FresnelData(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, -1);
fd.model = 3;
fd.ior = vec3(ior);
fd.extinction = vec3(0.0);
Expand All @@ -363,7 +363,7 @@ FresnelData mx_init_fresnel_dielectric_airy(float ior, float tf_thickness, float

FresnelData mx_init_fresnel_conductor_airy(vec3 ior, vec3 extinction, float tf_thickness, float tf_ior)
{
FresnelData fd = FresnelData(vec3(0), vec3(0), 0, 0, 0, -1);
FresnelData fd = FresnelData(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, -1);
fd.model = 3;
fd.ior = ior;
fd.extinction = extinction;
Expand Down
16 changes: 13 additions & 3 deletions libraries/pbrlib/genglsl/mx_conductor_bsdf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ void mx_conductor_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, float
float NdotH = clamp(dot(N, H), M_FLOAT_EPS, 1.0);
float VdotH = clamp(dot(V, H), M_FLOAT_EPS, 1.0);

FresnelData fd = tf.thickness > 0.0 ? mx_init_fresnel_conductor_airy(ior_n, ior_k, tf.thickness, tf.ior) : mx_init_fresnel_conductor(ior_n, ior_k);
FresnelData fd;
if (tf.thickness > 0.0)
fd = mx_init_fresnel_conductor_airy(ior_n, ior_k, tf.thickness, tf.ior);
else
fd = mx_init_fresnel_conductor(ior_n, ior_k);

vec3 F = mx_compute_fresnel(VdotH, fd);

float avgRoughness = mx_average_roughness(roughness);
Expand All @@ -28,7 +33,7 @@ void mx_conductor_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, float
vec3 comp = mx_ggx_energy_compensation(NdotV, avgRoughness, F);

// Note: NdotL is cancelled out
result = D * F * G * comp * occlusion * weight / (4 * NdotV);
result = D * F * G * comp * occlusion * weight / (4.0 * NdotV);
}

void mx_conductor_bsdf_indirect(vec3 V, float weight, vec3 ior_n, vec3 ior_k, vec2 roughness, vec3 N, vec3 X, int distribution, thinfilm tf, out BSDF result)
Expand All @@ -43,7 +48,12 @@ void mx_conductor_bsdf_indirect(vec3 V, float weight, vec3 ior_n, vec3 ior_k, ve

float NdotV = clamp(dot(N, V), M_FLOAT_EPS, 1.0);

FresnelData fd = tf.thickness > 0.0 ? mx_init_fresnel_conductor_airy(ior_n, ior_k, tf.thickness, tf.ior) : mx_init_fresnel_conductor(ior_n, ior_k);
FresnelData fd;
if (tf.thickness > 0.0)
fd = mx_init_fresnel_conductor_airy(ior_n, ior_k, tf.thickness, tf.ior);
else
fd = mx_init_fresnel_conductor(ior_n, ior_k);

vec3 F = mx_compute_fresnel(NdotV, fd);

vec3 Li = mx_environment_radiance(N, V, X, roughness, distribution, fd);
Expand Down
23 changes: 19 additions & 4 deletions libraries/pbrlib/genglsl/mx_dielectric_bsdf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ void mx_dielectric_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, floa

float avgRoughness = mx_average_roughness(roughness);

FresnelData fd = tf.thickness > 0.0 ? mx_init_fresnel_dielectric_airy(ior, tf.thickness, tf.ior) : mx_init_fresnel_dielectric(ior);
FresnelData fd;
if (tf.thickness > 0.0)
fd = mx_init_fresnel_dielectric_airy(ior, tf.thickness, tf.ior);
else
fd = mx_init_fresnel_dielectric(ior);

vec3 F = mx_compute_fresnel(VdotH, fd);
float D = mx_ggx_NDF(X, Y, H, NdotH, roughness.x, roughness.y);
float G = mx_ggx_smith_G(NdotL, NdotV, avgRoughness);
Expand All @@ -30,7 +35,7 @@ void mx_dielectric_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, floa
vec3 dirAlbedo = mx_ggx_directional_albedo(NdotV, avgRoughness, F0, 1.0) * comp;

// Note: NdotL is cancelled out
result = D * F * G * comp * tint * occlusion * weight / (4 * NdotV) // Top layer reflection
result = D * F * G * comp * tint * occlusion * weight / (4.0 * NdotV) // Top layer reflection
+ base * (1.0 - dirAlbedo * weight); // Base layer reflection attenuated by top layer
}

Expand Down Expand Up @@ -58,7 +63,12 @@ void mx_dielectric_bsdf_transmission(vec3 V, float weight, vec3 tint, float ior,
N = mx_forward_facing_normal(N, V);
float NdotV = clamp(dot(N, V), M_FLOAT_EPS, 1.0);

FresnelData fd = tf.thickness > 0.0 ? mx_init_fresnel_dielectric_airy(ior, tf.thickness, tf.ior) : mx_init_fresnel_dielectric(ior);
FresnelData fd;
if (tf.thickness > 0.0)
fd = mx_init_fresnel_dielectric_airy(ior, tf.thickness, tf.ior);
else
fd = mx_init_fresnel_dielectric(ior);

vec3 F = mx_compute_fresnel(NdotV, fd);

float avgRoughness = mx_average_roughness(roughness);
Expand All @@ -81,7 +91,12 @@ void mx_dielectric_bsdf_indirect(vec3 V, float weight, vec3 tint, float ior, vec

float NdotV = clamp(dot(N, V), M_FLOAT_EPS, 1.0);

FresnelData fd = tf.thickness > 0.0 ? mx_init_fresnel_dielectric_airy(ior, tf.thickness, tf.ior) : mx_init_fresnel_dielectric(ior);
FresnelData fd;
if (tf.thickness > 0.0)
fd = mx_init_fresnel_dielectric_airy(ior, tf.thickness, tf.ior);
else
fd = mx_init_fresnel_dielectric(ior);

vec3 F = mx_compute_fresnel(NdotV, fd);

float avgRoughness = mx_average_roughness(roughness);
Expand Down
2 changes: 1 addition & 1 deletion libraries/pbrlib/genglsl/mx_generalized_schlick_bsdf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void mx_generalized_schlick_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlus
float avgDirAlbedo = dot(dirAlbedo, vec3(1.0 / 3.0));

// Note: NdotL is cancelled out
result = D * F * G * comp * occlusion * weight / (4 * NdotV) // Top layer reflection
result = D * F * G * comp * occlusion * weight / (4.0 * NdotV) // Top layer reflection
+ base * (1.0 - avgDirAlbedo * weight); // Base layer reflection attenuated by top layer
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/stdlib/genglsl/lib/mx_noise.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int mx_floor(float x)
float mx_floorfrac(float x, out int i)
{
i = mx_floor(x);
return x - i;
return x - float(i);
}

float mx_bilerp(float v0, float v1, float v2, float v3, float s, float t)
Expand Down
4 changes: 2 additions & 2 deletions libraries/stdlib/genglsl/mx_disjointover_color4.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ void mx_disjointover_color4(vec4 fg, vec4 bg, float mixval, out vec4 result)
{
float summedAlpha = fg.w + bg.w;

if (summedAlpha <= 1)
if (summedAlpha <= 1.0)
{
result.xyz = fg.xyz + bg.xyz;
}
Expand All @@ -14,7 +14,7 @@ void mx_disjointover_color4(vec4 fg, vec4 bg, float mixval, out vec4 result)
}
else
{
float x = (1 - fg.w) / bg.w;
float x = (1.0 - fg.w) / bg.w;
result.xyz = fg.xyz + bg.xyz * x;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/stdlib/genglsl/mx_fractal3d_vector4.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
void mx_fractal3d_vector4(vec4 amplitude, int octaves, float lacunarity, float diminish, vec3 position, out vec4 result)
{
vec3 xyz = mx_fractal_noise_vec3(position, octaves, lacunarity, diminish);
float w = mx_fractal_noise_float(position + vec3(19, 193, 17), octaves, lacunarity, diminish);
float w = mx_fractal_noise_float(position + vec3(19.0, 193.0, 17.0), octaves, lacunarity, diminish);
result = vec4(xyz,w) * amplitude;
}
2 changes: 1 addition & 1 deletion libraries/stdlib/genglsl/mx_overlay.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
float mx_overlay(float fg, float bg)
{
return (fg < 0.5) ? (2 * fg * bg) : (1 - (1 - fg) * (1 - bg));
return (fg < 0.5) ? (2.0 * fg * bg) : (1.0 - (1.0 - fg) * (1.0 - bg));
}

vec2 mx_overlay(vec2 fg, vec2 bg)
Expand Down
2 changes: 1 addition & 1 deletion libraries/stdlib/genglsl/mx_overlay_color3.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

void mx_overlay_color3(vec3 fg, vec3 bg, float mix, out vec3 result)
{
result = mix * mx_overlay(fg, bg) + (1-mix) * bg;
result = mix * mx_overlay(fg, bg) + (1.0-mix) * bg;
}
Loading

0 comments on commit f21a4db

Please sign in to comment.