// // Copyright 2019 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in // compliance with the Apache License and the following modification to it: // Section 6. Trademarks. is deleted and replaced with: // // 6. Trademarks. This License does not grant permission to use the trade // names, trademarks, service marks, or product names of the Licensor // and its affiliates, except as required to comply with Section 4(c) of // the License and to reproduce the content of the NOTICE file. // // You may obtain a copy of the Apache License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the Apache License with the above modification is // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the Apache License for the specific // language governing permissions and limitations under the Apache License. // shader UsdPreviewSurfaceParameters ( // Inputs color diffuseColor = color(0.18, 0.18, 0.18), color emissiveColor = color(0.0, 0.0, 0.0), int useSpecularWorkflow = 0, color specularColor = color(0.0, 0.0, 0.0), float metallic = 0.0, float roughness = 0.5, float clearcoat = 0.0, float clearcoatRoughness = 0.01, float opacity = 1.0, float ior = 1.5, vector normalIn = vector(0.0, 0.0, 1.0), float occlusion = 1.0, // Diffuse outputs output float diffuseGainOut = 0.0 [[ string widget = "null" ]], output color diffuseColorOut = color(0.0,0.0,0.0) [[ string widget = "null" ]], // Specular outputs output color specularFaceColorOut = color(0.0,0.0,0.0) [[ string widget = "null" ]], output color specularEdgeColorOut = color(0.0,0.0,0.0) [[ string widget = "null" ]], output float specularRoughnessOut = 0.0 [[ string widget = "null" ]], output color specularIorOut = color(0.0) [[ string widget = "null" ]], // Clearcoat outputs output color clearcoatFaceColorOut = color(0.0,0.0,0.0) [[ string widget = "null" ]], output color clearcoatEdgeColorOut = color(0.0,0.0,0.0) [[ string widget = "null" ]], output float clearcoatRoughnessOut = 0.0 [[ string widget = "null" ]], // Emissive outputs output float glowGainOut = 0.0 [[ string widget = "null" ]], output color glowColorOut = color(0.0,0.0,0.0) [[ string widget = "null" ]], // Normal outputs output normal bumpNormalOut = normal(0.0,0.0,0.0) [[ string widget = "null" ]], // Opacity output float refractionGainOut = 0.0 [[ string widget = "null" ]], output float glassIorOut= 0.0 [[ string widget = "null" ]], ) { // Diffuse if (diffuseColor[0] > 0.0 || diffuseColor[1] > 0.0 || diffuseColor[2] > 0.0) { diffuseGainOut = 1.0; diffuseColorOut = diffuseColor; } // Opacity if (opacity < 1.0) { glassIorOut = ior; refractionGainOut = 1.0 - opacity; diffuseGainOut *= opacity; } // Specular // Assumes "Physical" for both Specular and Rough Specular if (useSpecularWorkflow) { specularFaceColorOut = specularColor; specularEdgeColorOut = color(1.0,1.0,1.0); } else { float metal = clamp(metallic, 0.0, 1.0); color spec = mix(color(1.0,1.0,1.0), diffuseColor, metal); float r = (1.0 - ior) / (1.0 + ior); specularFaceColorOut = r * r * spec; specularEdgeColorOut = spec; diffuseGainOut *= 1.0 - metal; } specularIorOut = color(ior); specularRoughnessOut = roughness; // Clearcoat if (clearcoat > 0.0) { clearcoatFaceColorOut = clearcoat * color(1.0, 1.0, 1.0); clearcoatRoughnessOut = clearcoatRoughness; } // Emissive if (emissiveColor[0] > 0.0 || emissiveColor[1] > 0.0 || emissiveColor[2] > 0.0) { glowGainOut = 1.0; glowColorOut = emissiveColor; } // Normal map // Convert tangent space normalIn to bumpNormalOut { vector Tn = vector (1.0,0.0,0.0); getattribute("builtin", "Tn", Tn); vector Bn = normalize(cross(N, Tn)); // Convert from tangent-space normal to current space bumpNormalOut = -Tn * normalIn[0] + -Bn * normalIn[1] + N * normalIn[2]; bumpNormalOut = normalize(bumpNormalOut); normal Ngn = N; getattribute("builtin", "Ngn", Ngn); // Is it backwards from the geometric normal if (dot(Ngn, bumpNormalOut) < 0.0) { bumpNormalOut = -bumpNormalOut; } } }