XML3D Standard Surface Shader Documentation

Matte Shader

This shader colors the surface of an object using a single color Le, which can be defined using the emissiveColor parameter:

Lc = Le = emissiveColor

Example:

                <shader id="flat" script="urn:xml3d:shader:matte">
                  <float3 name="emissiveColor">1.0 0.0 0.0</float3>
                </shader>

Parameters

Name Type Default Value Description
emissiveColor <float3> 1 1 1 Defines the emissive color of the surface.

Diffuse Shader

The Diffuse Shader extends the Flat Shader by Lambertian reflectance:

Lc(p) = Le + Ld(p)

The shading depends on the incident radiance and the angle between the light source and the surface normal. The diffuse term Ld(p) models the perfect diffuse response of a Lambertian surface:

Ld(p) =   

Ω(p)
kd(p) Li(p; ωi) cosθii


where

kd(p) = diffuseColor *  ( useVertexColor ? va("color") :  diffuseTexture ? sample(diffuseTexture, va("texcoord")) : 1.0 )

A possible alpha value in the diffuseTexture sample is ignored.

Example:

                <shader id="flat" script="urn:xml3d:shader:diffuse">
                  <float3 name="diffuseColor">1.0 0.0 0.0</float3>
                  <texture name="diffuseTexture"><img src="logo.png"/></texture>
                </shader>

Parameters

Name Type Default Value Description
emissiveColor <float3> 0 0 0 Defines the emissive color of the surface.
diffuseColor <float3> 1 1 1 Defines the base color of the surface.
diffuseTexture <texture> - Defines the texture to sample the diffuse color from.
useVertexColor <bool> false Turns on/off usage of the vertex attribute "color" as diffuseColor.

Phong Shader

The Phong Shader extends the Diffuse Shader by a glossy term for specular highlights, perfect reflection and simple transparency.

Glossy term

The glossy term Lg, simulates the specular highlights due to microfacets on the surface. The result depends on the surface location p and view direction w:

Lp(p,w) = Le + Ld(p) + Lg(p,w)

Lgis calculated using the specular highlight term of the Phong reflection model:

Lg(p,ωi) =   

Ω(p)
ks (cosθv)n Li(p; ωi) cosθii

where

Perfect reflection

The term Lr(p,w) describes the irradiance coming from the direction of the perfect reflection:

Lr(p,ωi) = kr L(p',ωi')


where


This is typically done shooting secondary rays in direction of the perfect reflection or by rendering a dynamic reflection map.

Transparency

The transparency is a simple blending operation and thus differs from real refraction calculation. The result is a weighted mix of Lp(p,w) with the underlying fragment color Lc(p',w) (typically in the frame buffer for z-sorted rasterization and the result of a refractive ray in the same direction as the incoming ray for ray tracing):

Lc(p,w) =  (1-t(p)) * Lp(p,w)  + t(p) * Lc(p',w)

where t is the transparency of the surface at point p. If diffuseTexture is defined and has an alpha channel, t is 1 - alpha value at the sample defined by vertex attribute "texcoord". Otherwise the transparency parameter is used.

Example:

                <shader id="myPhong" script="urn:xml3d:shader:phong">
                </shader>

Parameters

Name Type Default Value Description
emissionColor <float3> 0 0 0 Defines the self-emission of the surface.
ambientColor <float3> 0 0 0 Defines the ambient color of the surface.
diffuseColor <float3> 1 1 1 Defines the diffuse color of the surface.
diffuseTexture <texture> - Defines the texture to sample the diffuse color from.
specularColor <float3> 0 0 0 Defines the specular value of the surface
shininess <float> 0.2 Shininess of the surface (values in [0,1])
reflectionColor <float3> 0 0 0 Factor to scale the contribution from the perfect reflection.
transparency <float> 0 0 0 Factor to scale the contribution from the perfect reflection.
castShadow <int> ≥1 Turns on/off shadow cast. Specify 0 to activate shadow cast and a value ≥1 otherwise.