// // 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. // // // Note: This shader needs to stay in sync with usdImaging's usdShaders as // defined by the shaderDefs.usda file. Thus, we must work precisely in this // part of the shader space to ensure that properties defined here have the // same types as their usd definition. Use of special metadata like 'role' is // necessary to make some of the types match. Please see Sdr overview // documentation for more information about different metadata tags that are // used to inform property type translation. // shader UsdUVTexture [[ string category="generator" ]] ( // Details : Image source string file = "" [[ string widget = "assetIdInput" ]], // Details : Texture coordinates float st[2] = {0.0, 0.0}, // Details : [options] useMetadata, black, clamp, repeat, mirror. string wrapS = "useMetadata" [[ string options = "useMetadata|black|clamp|repeat|mirror" ]], string wrapT = "useMetadata" [[ string options = "useMetadata|black|clamp|repeat|mirror" ]], // Details : Fallback value used when no texture is connected. float fallback[4] = {0.0, 0.0, 0.0, 1.0}, // Details : Scale to be applied to all components of the texture. // value * scale + bias float scale[4] = {1.0, 1.0, 1.0, 1.0}, // Details : Bias to be applied to all components of the texture. // value * scale + bias float bias[4] = {0.0, 0.0, 0.0, 0.0}, // Details : [options] r, g, b, a, rgb, rgba output color rgb = color(0.0, 0.0 ,0.0) [[ string widget = "null", string role = "none" ]], output float r = 0.0 [[ string widget = "null" ]], output float g = 0.0 [[ string widget = "null" ]], output float b = 0.0 [[ string widget = "null" ]], output float a = 0.0 [[ string widget = "null" ]], ) { // Create a 'color' type version of each float[4] input. We will use the // 'color' type versions to perform computations. color fallbackColor = color(fallback[0], fallback[1], fallback[2]); float fallbackAlpha = fallback[3]; color scaleColor = color(scale[0], scale[1], scale[2]); float scaleAlpha = scale[3]; color biasColor = color(bias[0], bias[1], bias[2]); float biasAlpha = bias[3]; // Wrap mode conversion string swrap = wrapS; string twrap = wrapT; if (swrap == "repeat") { swrap = "periodic"; } if (twrap == "repeat") { twrap = "periodic"; } if (swrap == "useMetadata") { swrap = "default"; } if (twrap == "useMetadata") { twrap = "default"; } // Read the texture color resultColor = texture( file, st[0], st[1], "swrap", swrap, "twrap", twrap, "missingcolor", fallbackColor); float resultAlpha = texture( file, st[0], st[1], "swrap", swrap, "twrap", twrap, "firstchannel", 3, "missingcolor", color(fallbackAlpha), "fill", fallbackAlpha); // Apply scale and bias resultColor = resultColor * scaleColor + biasColor; resultAlpha = resultAlpha * scaleAlpha + biasAlpha; // Output the colors rgb = resultColor; r = resultColor[0]; g = resultColor[1]; b = resultColor[2]; a = resultAlpha; }