SCNShaderModifierEntryPointSurface

Static SCNShaderModifierEntryPointSurface 

Source
pub unsafe static SCNShaderModifierEntryPointSurface: &'static SCNShaderModifierEntryPoint
Available on crate feature SCNShadable only.
Expand description

This is the entry point to alter the surface representation of the material, before the lighting has taken place.

Structures available from the SCNShaderModifierEntryPointSurface entry point:

| struct SCNShaderSurface { | float3 view; // Direction from the point on the surface toward the camera (V) | float3 position; // Position of the fragment | float3 normal; // Normal of the fragment (N) | float3 geometryNormal; // Geometric normal of the fragment (normal map is ignored) | float3 tangent; // Tangent of the fragment | float3 bitangent; // Bitangent of the fragment | float4 ambient; // Ambient property of the fragment | float2 ambientTexcoord; // Ambient texture coordinates | float4 diffuse; // Diffuse property of the fragment. Alpha contains the opacity. | float2 diffuseTexcoord; // Diffuse texture coordinates | float4 specular; // Specular property of the fragment | float2 specularTexcoord; // Specular texture coordinates | float4 emission; // Emission property of the fragment | float2 emissionTexcoord; // Emission texture coordinates | float4 multiply; // Multiply property of the fragment | float2 multiplyTexcoord; // Multiply texture coordinates | float4 transparent; // Transparent property of the fragment | float2 transparentTexcoord; // Transparent texture coordinates | float4 reflective; // Reflective property of the fragment | float metalness; // Metalness property of the fragment | float2 metalnessTexcoord; // Metalness texture coordinates | float roughness; // Roughness property of the fragment | float2 roughnessTexcoord; // Roughness texture coordinates | float clearCoat; // Clear Coat property of the fragment. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6. | float2 clearCoatTexcoord; // Clear Coat texture coordinates. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6. | float clearCoatRoughness; // Clear Coat Roughness property of the fragment. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6. | float2 clearCoatRoughnessTexcoord; // Clear Coat Roughness texture coordinates. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6. | float3 clearCoatNormal; // Clear Coat Normal property of the fragment. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6. | float2 clearCoatNormalTexcoord; // Clear Coat Normnal texture coordinates. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6. | float4 selfIllumination; // Self Illumination property of the fragment. Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as emission in previous versions. | float2 selfIlluminationTexcoord; // Self Illumination texture coordinates. Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as emissionTexcoord in previous versions. | float ambientOcclusion; // Ambient Occlusion property of the fragment. Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as multiply in previous versions. | float2 ambientOcclusionTexcoord; // Ambient Occlusion texture coordinates. Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as multiplyTexcoord in previous versions. | float shininess; // Shininess property of the fragment | float fresnel; // Fresnel property of the fragment | } _surface; | | Access: ReadWrite | Stages: Fragment shader only

All geometric fields are in view space. All the other properties will be colors (texture have already been sampled at this stage) or floats. You can however do an extra sampling of standard textures if you want. In this case the naming pattern is u_ <property

Texture. For example u_diffuseTexture or u_reflectiveTexture. Note that you have to be sure that the material do have a texture set for this property, otherwise you’ll trigger a shader compilation error.

Example: Procedural black and white stripes

GLSL | uniform float Scale = 12.0; | uniform float Width = 0.25; | uniform float Blend = 0.3; | | vec2 position = fract(_surface.diffuseTexcoord * Scale); | float f1 = clamp(position.y / Blend, 0.0, 1.0); | float f2 = clamp((position.y - Width) / Blend, 0.0, 1.0); | f1 = f1 * (1.0 - f2); | f1 = f1 * f1 * 2.0 * (3. * 2. * f1); | _surface.diffuse = mix(vec4(1.0), vec4(0.0), f1);

Metal Shading Language | #pragma arguments | float Scale; | float Width; | float Blend; | | float2 position = fract(_surface.diffuseTexcoord * Scale); | float f1 = clamp(position.y / Blend, 0.0, 1.0); | float f2 = clamp((position.y - Width) / Blend, 0.0, 1.0); | f1 = f1 * (1.0 - f2); | f1 = f1 * f1 * 2.0 * (3. * 2. * f1); | _surface.diffuse = mix(float4(1.0), float4(0.0), f1);

See also Apple’s documentation