S&box Wiki

Revision Difference

MaterialAPI#547907

<cat>Code.Shader</cat>⤶ <cat>Material.ShaderBasic</cat>⤶ <title>Material API</title> # What is the Material API The Material API is a collection of helper methods & texture inputs to describe the surface of your material. The main purpose of the Material API is to prepare your data and pass it to a <page>ShadingModel</page>. The Material API is automatically used when you add the `common/pixel.hlsl` include to your pixel shader. ``` PS { #include "common/pixel.hlsl" float4 MainPs( PixelInput i ) : SV_Target0 { // Gather our texture inputs and convert them to the material struct Material m = GatherMaterial( i ); // Force our object to be metallic m.Metalness = 1.3f; // Shade our surface with lighting return FinalizePixelMaterial( i, m ); } } ``` # Texture Inputs By default, the Material API provides a set of texture inputs. These texture inputs can be used to automatically populate the Material struct for you. To populate your Material object, simply call `GatherMaterial` using your `PixelInput` as the argument. GatherMaterial will automatically transform your normal map to be within object space, set up texture compression & pack different textures into one texture to reduce memory. ``` Material m = GatherMaterial( i ); ``` <upload src="653cb/8daa5101c74c705.png" size="77533" name="image.png" /> # Material ``` // Defined in common/pixel.material.structs.hlsl // Included automatically by common/pixel.hlsl struct Material { float3 Albedo; // default: float3(1.0, 1.0, 1.0) float3 Emission; // default: float3(0.0, 0.0, 0.0) float Opacity; // default: 1.0 float TintMask; // default: 1.0 float3 Normal; // default: float3(0.0, 0.0, 1.0), note: this is in world space float Roughness; // default: 1.0 float Metalness; // default: 0.0, float3 AmbientOcclusion; // default: 1.0, can be normal AO or bent normal AO // Everything below here is not used in the standard shading model at the time of writing float3 Sheen; // default: float3(0.0) float SheenRoughness; // default: 0.0 float Clearcoat; // default: 0.0 float ClearcoatRoughness; // default: 0.03 float3 ClearcoatNormal; // default: float3(0.0, 0.0, 1.0) float Anisotropy; // default: 0.0 float3 AnisotropyRotation; // default: float3(1.0, 0.0, 0.0) // only available when the shading model is subsurface (skin, etc) float Thickness; // default: 0.5 float SubsurfacePower; // default: 12.234 // only available when the shading model is cloth float3 SheenColor; // default: sqrt(baseColor) // only available when the shading model is cloth/subsurface float3 SubsurfaceColor; // default: float3(0.0) // only available when the shading model is refraction float3 Transmission; // default: 1.0 float3 Absorption; // default float3(0.0, 0.0, 0.0) float IndexOfRefraction; // default: 1.5 float MicroThickness; // default: 0.0 }; ```