LightingContext

class LightingContext

Bases: ParamValueBase, Namable

What lights a PBR surface besides Acron’s lights: the code behind the fixed contract pbr.frag calls (ctx_begin, ctx_key_light, ctx_irradiance, ctx_radiance, ctx_ambient_visibility, ctx_finish, ctx_write_outputs; see the module manual), the defines and named sources it is compiled with, and the shader inputs it reads. Put it on a subtree with apply(), which sets it as the shader input pbr_lighting_context: like any input it is inherited, and a lower node’s own replaces it. The generator compiles the states below with the context, one permutation per context and revision. (An input, not a RenderAttrib: Acron’s 32 attribute slots are taken. As with every shader input, the binding is not written to Bam files; the context itself is, see write_datagram.)

The contract is implemented by the source named pbr_context.glsl: the library’s own is the default context (Acron’s ambient light and the pbr_env_* image-based light, exposed by pbr_exposure). A context that sets its own pbr_context.glsl replaces it; one that does not only adds its defines, sources and inputs to the default. Sources set here win over the ShaderLibrary’s of the same name, for this context’s shaders only. They are included in the fragment stage.

A context may stand for one of Acron’s lights (set_key_light): its own ctx_key_light then lights the surface, and the light loop skips that light on every state that has it on.

Every change bumps the revision and makes the generator re-specialise the states (a new shader for defines and sources; new inputs otherwise). Make the changes together, not every frame.

Inheritance diagram

digraph inheritance4a4649b788 { 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=""]; "LightingContext" [URL="acron.shading.LightingContext.html#acron.shading.LightingContext",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "ParamValueBase" -> "LightingContext" [arrowsize=0.75,style=""]; "Namable" -> "LightingContext" [arrowsize=0.75,style=""]; "Namable" [URL="acron.core.Namable.html#acron.core.Namable",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" -> "Namable" [arrowsize=0.75,style=""]; "ParamValueBase" [URL="acron.core.ParamValueBase.html#acron.core.ParamValueBase",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedWritableReferenceCount" -> "ParamValueBase" [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=""]; "TypedObject" [URL="acron.core.TypedObject.html#acron.core.TypedObject",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" -> "TypedObject" [arrowsize=0.75,style=""]; "TypedWritable" [URL="acron.core.TypedWritable.html#acron.core.TypedWritable",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedObject" -> "TypedWritable" [arrowsize=0.75,style=""]; "TypedWritableReferenceCount" [URL="acron.core.TypedWritableReferenceCount.html#acron.core.TypedWritableReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedWritable" -> "TypedWritableReferenceCount" [arrowsize=0.75,style=""]; "ReferenceCount" -> "TypedWritableReferenceCount" [arrowsize=0.75,style=""]; }
LightingContext.__init__()

An empty context: the default context’s behaviour, until it gets its own defines, sources or inputs.

A copy with the same defines, sources, inputs and key light (and its own revision count).

LightingContext.apply()

Lights node_path and everything below it with this context (sets the shader input pbr_lighting_context; priority as for set_shader_input).

static LightingContext.clear()

Removes the context node_path itself carries (an inherited one stays; to give a subtree the default context below another, apply an empty LightingContext there).

LightingContext.clear_define()

Removes the macro; returns true if it was defined.

LightingContext.clear_defines()
LightingContext.clear_key_light()
LightingContext.clear_shader_input()
LightingContext.clear_source()
LightingContext.clear_sources()
LightingContext.get_acron_ambient()

Whether the states below read Acron’s AmbientLights (default: true). A context whose ctx_irradiance is the ambient light turns it off.

static LightingContext.get_class_type()
static LightingContext.get_contract_source_name()

The name of the source that implements the contract pbr.frag calls (pbr_context.glsl). The ShaderLibrary’s is the default context.

LightingContext.get_define()

The macro’s value (empty for a bare define or none).

LightingContext.get_define_name()

The nth macro’s name, in alphabetical order.

LightingContext.get_defines()

The #define lines of the context: PBR_CONTEXT, PBR_GBUFFER and PBR_SKIP_LIGHT for its switches, then its own defines.

static LightingContext.get_from_state()

The context a state is lit with: its ShaderAttrib’s pbr_lighting_context, or nullptr for the default context.

LightingContext.get_gbuffer()

Whether the shaders write the G-buffer outputs at locations 1 and 2 (default: false): the view-space normal and the motion vector.

LightingContext.get_image_light()

Whether the states below read the pbr_env_* image-based light when they have it (default: true). The default context’s ctx_irradiance and ctx_radiance are that light; a context with its own turns it off.

static LightingContext.get_input_name()

The shader input that carries the context (pbr_lighting_context).

LightingContext.get_key_light()

The Acron light this context’s ctx_key_light stands for (the light loop skips it), or an empty NodePath.

LightingContext.get_num_defines()
LightingContext.get_num_samplers()

The samplers the context’s sources read in the fragment stage, as the context’s maker counted them; the generator budgets them with the material’s.

LightingContext.get_num_shader_inputs()
LightingContext.get_num_sources()
LightingContext.get_revision()

Bumped by every change. The generator’s feature keys carry it, so that a changed context gets new shaders.

LightingContext.get_shader_input()

The input of that name, or a blank one.

LightingContext.get_shader_input_n()

The nth input, in the order of their names.

LightingContext.get_source()

The context’s own source of that name (empty if it has none).

LightingContext.get_source_name()
LightingContext.has_define()
LightingContext.has_key_light()
LightingContext.has_shader_input()
LightingContext.has_source()
LightingContext.output()
LightingContext.set_acron_ambient()
LightingContext.set_define()

Defines the macro for the context’s shaders: #define name value (an empty value defines the bare name).

LightingContext.set_gbuffer()
LightingContext.set_image_light()
LightingContext.set_key_light()

Says that the context’s ctx_key_light is this light (a DirectionalLight the scene also carries for shaders that read only Acron’s lights): the PBR light loop skips it wherever it is on.

LightingContext.set_num_samplers()
LightingContext.set_shader_input()

An input the context’s shaders read. The generator adds it to the states below that do not have an input of the same name already (an input set on a node wins, as with pbr_exposure).

LightingContext.set_source()

Registers a source under the name an #include uses. Within this context’s shaders it wins over the ShaderLibrary’s source of that name; get_contract_source_name()’s replaces the default context.