PbrShaderBuilder¶
from acron.shading import PbrShaderBuilder
- class PbrShaderBuilder¶
Bases:
Bases:
ReferenceCountTurns a
RenderStateinto 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 theShaderAttribthat carries it with its inputs (make_attrib).PbrShaderGeneratorruns it for the GSG; tests and tools use it directly.The state’s material is its PbrMaterialAttrib’s; without one, a
PbrMaterialderived from itsMaterialAttrib(one per Material); without either, a defaultPbrMaterial.Inputs the generated
ShaderAttribcarries, unless the state’s ownShaderAttrib(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 (seePhysicalCamera.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
ShaderAttribhas auto shadows on, as set_shader_auto() does) each get an input pbr_shadow_2d_<k> or pbr_shadow_cube_<k> (the light’sNodePath, 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. ALightingContexton 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.
- 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
ShaderAttribfor a state: the state’s ownShaderAttrib(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_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.