Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for double sided materials in PBR shader
  • Loading branch information
ziriax committed Aug 19, 2018
1 parent 9e73cf5 commit e59a7a0
Show file tree
Hide file tree
Showing 7 changed files with 729 additions and 6 deletions.
16 changes: 13 additions & 3 deletions maya/renderData/shaders/glTF_PBR.ogsfx
Expand Up @@ -312,9 +312,15 @@ uniform bool u_UseMeshTangents
<
string UIName = "Use mesh tangents?";
string UIGroup = "PBR Advanced";
int UIOrder = 3000;
int UIOrder = 3001;
> = false;

uniform bool u_IsDoubleSided
<
string UIName = "Double sided material?";
string UIGroup = "PBR Advanced";
int UIOrder = 3000;
> = false;

// Encapsulate the various inputs used by the various functions in the shading equation
// We store values in this struct to simplify the integration of alternative implementations
Expand Down Expand Up @@ -546,6 +552,12 @@ GLSLShader PS

void main()
{
vec3 n = getNormal(); // normal at surface point
vec3 v = normalize(v_CameraPos - v_Position); // Vector from surface point to camera

if (!u_IsDoubleSided && dot(n,v) <= 0)
discard;

// Metallic and Roughness material properties are packed together
// In glTF, these factors can be specified by fixed scalar values
// or from a metallic-roughness map
Expand Down Expand Up @@ -585,8 +597,6 @@ GLSLShader PS
vec3 specularEnvironmentR0 = specularColor.rgb;
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;

vec3 n = getNormal(); // normal at surface point
vec3 v = normalize(v_CameraPos - v_Position); // Vector from surface point to camera
#ifdef USE_LIGHT_BINDING
// Vector from surface point to light
vec3 l = normalize(-u_LightDir);
Expand Down
700 changes: 700 additions & 0 deletions maya/scenes/DoubleSidedTest1.ma

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion maya/scripts/maya2glTF_UI.mel
Expand Up @@ -251,7 +251,7 @@ global proc maya2glTF_UI()
global string $gMainProgressBar;

// This is auto-updated by msbuild
string $maya2glTF_version = "V0.9.7-BETA 9added8";
string $maya2glTF_version = "V0.9.7-BETA 9e73cf5";

if (`window -exists maya2glTF_exporter_window`)
deleteUI maya2glTF_exporter_window;
Expand Down
12 changes: 12 additions & 0 deletions src/ExportableMaterial.cpp
Expand Up @@ -47,6 +47,11 @@ bool ExportableMaterial::getScalar(const MObject& obj, const char* attributeName
return DagHelper::getPlugValue(obj, attributeName, scalar);
}

bool ExportableMaterial::getBoolean(const MObject& obj, const char* attributeName, bool& result)
{
return DagHelper::getPlugValue(obj, attributeName, result);
}

bool ExportableMaterial::getString(const MObject& obj, const char* attributeName, MString& string)
{
return DagHelper::getPlugValue(obj, attributeName, string);
Expand Down Expand Up @@ -183,10 +188,17 @@ void ExportableMaterialPBR::loadPBR(ExportableResources& resources, const MFnDep
Float4 customBaseColor = m_glBaseColorFactor;
float customBaseAlpha = m_glBaseColorFactor[3];
MString technique = "solid";
bool isDoubleSided = false;

const auto hasCustomColor = getColor(shaderObject, "u_BaseColorFactorRGB", customBaseColor);
const auto hasCustomAlpha = getScalar(shaderObject, "u_BaseColorFactorA", customBaseAlpha);
const auto hasTechnique = getString(shaderObject, "technique", technique);
const auto hasDoubleSided = getBoolean(shaderObject, "u_IsDoubleSided", isDoubleSided);

if (hasDoubleSided)
{
m_glMaterial.doubleSided = isDoubleSided;
}

if (hasCustomColor | hasCustomAlpha)
{
Expand Down
1 change: 1 addition & 0 deletions src/ExportableMaterial.h
Expand Up @@ -25,6 +25,7 @@ class ExportableMaterial
static bool getScalar(const MObject& shaderObject, const char* attributeName, float& scalar);
static bool getColor(const MObject& shaderObject, const char* attributeName, Float4& color);
static bool getString(const MObject& shaderObject, const char* attributeName, MString& string);
static bool getBoolean(const MObject& shaderObject, const char* attributeName, bool& result);

private:
DISALLOW_COPY_MOVE_ASSIGN(ExportableMaterial);
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
@@ -1,3 +1,3 @@
#include "externals.h"

const char* version = "V0.9.7-BETA 9added8";
const char* version = "V0.9.7-BETA 9e73cf5";

0 comments on commit e59a7a0

Please sign in to comment.