PbrShaderBuilder

from acron.shading import PbrShaderBuilder
class PbrShaderBuilder

Bases:

Bases: ReferenceCount

Turns a RenderState into a PBR shader, without GL: the analysis (make_key), the GLSL (get_vertex_source, get_fragment_source()), the Shader (make_shader: Acron compiles GLSL to SPIR-V on the CPU) and the ShaderAttrib that carries it with its inputs (make_attrib). PbrShaderGenerator runs it for the GSG; tests and tools use it directly.

The state’s material is its PbrMaterialAttrib’s; without one, a PbrMaterial derived from its MaterialAttrib (one per Material); without either, a default PbrMaterial.

Inputs the generated ShaderAttrib carries, unless the state’s own ShaderAttrib (from set_shader_input on a node) already has them: pbr_material the material’s live uniform rows; pbr_dfg_lut BrdfLuts::get_default()’s texture; pbr_exposure (1, 0, 0, 0): no exposure (see PhysicalCamera.apply). Image-based light is on for states that have the input pbr_env_radiance (with pbr_env_sh and pbr_env_params; see pbr_ibl.glsl).

Shadows: the shadow-casting lights among those the shader evaluates (at most shading-max-shadows, on states whose ShaderAttrib has auto shadows on, as set_shader_auto() does) each get an input pbr_shadow_2d_<k> or pbr_shadow_cube_<k> (the light’s NodePath, from which Acron binds its shadow map), and pbr_shadow_index_2d / _cube say which light each is. States that write no colour (a LightLensNode’s shadow camera, or a depth pre-pass) get the depth-only shader, which only discards the cut-out texels of masked and blended materials. A LightingContext on the state (the input pbr_lighting_context) goes into the key (its defines and sources into the fragment stage), its inputs into the attrib, and pbr_skip_light: the index of its key light among the state’s lights, which the light loop skips.

Sampler budget: a key whose fragment stage would read more than max_samplers samplers (PbrFeatureKey::get_num_samplers, the context’s included) loses its least important maps, with a warning.

Inheritance diagram

digraph inheritancecfc760fbf5 { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "PbrShaderBuilder" [URL="acron.shading.PbrShaderBuilder.html#acron.shading.PbrShaderBuilder",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "ReferenceCount" -> "PbrShaderBuilder" [arrowsize=0.75,style=""]; "ReferenceCount" [URL="acron.core.ReferenceCount.html#acron.core.ReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ReferenceCount" [arrowsize=0.75,style=""]; }
__init__()
static get_context()

The state’s LightingContext, or nullptr for the default context.

get_defines()

The key’s defines plus the build’s and the configuration’s.

get_fragment_source()

The complete fragment shader for a key.

get_glsl_version()
static get_light_max_distance_supported()

True if this build’s shaders read each light’s max_distance (the maxDistance member of acron_LightSource, which needs a core that binds it). Without it, every point light and spotlight gets its automatic range.

get_material()

The material the state is shaded with.

get_max_lights()
get_max_samplers()
get_multiscatter()
get_shadow_taps()
get_spec_aa()
get_vertex_source()

The complete vertex shader for a key.

property glsl_version → int

Getter Setter

The #version of the generated GLSL: 450 or 410.

static has_configured_shadow_taps()

True when the configuration sets shading-shadow-taps: then it wins over a quality preset’s taps.

make_attrib()

The ShaderAttrib for a state: the state’s own ShaderAttrib (keeping its inputs, e.g. pbr_exposure and the environment set on render) with the shader, plus the inputs the shader needs that the state lacks.

Skinning is the GL back end’s: it injects the joint blend into the shader’s vertex stage (positions, normals, tangents) for vertex data animated in hardware, unless the attrib has F_hardware_skinning, which says the shader blends itself. This shader doesn’t, so the flag (which a state may carry to ask the stock generator for skinning) is cleared.

make_key()

The permutation a state needs.

make_shader()

Compiles the key’s shader (to SPIR-V, on the CPU: no GL needed). Returns nullptr, with the compiler’s errors in the log, on failure.

property max_lights → int

Getter Setter

The largest light bucket (default: shading-max-lights).

property max_samplers → int

Getter Setter

The samplers one fragment shader may read (default: shading-max-fragment-samplers). make_key() drops maps beyond it.

property multiscatter → bool

Getter Setter

Multiple-scattering energy compensation (default: shading-multiscatter).

set_glsl_version()

The #version of the generated GLSL: 450 or 410.

set_max_lights()

The largest light bucket (default: shading-max-lights).

set_max_samplers()

The samplers one fragment shader may read (default: shading-max-fragment-samplers). make_key() drops maps beyond it.

set_multiscatter()

Multiple-scattering energy compensation (default: shading-multiscatter).

set_shadow_taps()

The hardware-compared taps on a Vogel disc that the shader reads per shadow map and pixel, 1 to 32 (default: shading-shadow-taps, 4). A quality preset sets it unless the configuration does (has_configured_shadow_taps). Part of the key: states synthesised afterwards get shaders with the new count.

set_spec_aa()

Geometric specular antialiasing (default: shading-spec-aa).

property shadow_taps → int

Getter Setter

The hardware-compared taps on a Vogel disc that the shader reads per shadow map and pixel, 1 to 32 (default: shading-shadow-taps, 4). A quality preset sets it unless the configuration does (has_configured_shadow_taps). Part of the key: states synthesised afterwards get shaders with the new count.

property spec_aa → bool

Getter Setter

Geometric specular antialiasing (default: shading-spec-aa).