PreprocessorShaderMaterial

Inherits: ShaderMaterial

A ShaderMaterial that generates its Shader using a list of defines and includes. Useful for shaders that you want to be highly-configurable, but optimized, by using preprocessors.

Description

The PreprocessorShaderMaterial is primarily intended for automatic handling of preprocessor defines within a ShaderMaterial. The bulk of your shader code is expected to be written in ShaderIncludes.

A new Shader resource is created when any preprocessors (flags, constants, includes) are modified in the inspector, in order to force Godot to recompile the shader. You can also manually rebuild the shader with the build_shader() method..

Generated shaders are laid out in this order: Shader Type, Defined Constants (sorted alphabetically), Defined Flags (sorted alphabetically), Prelude, Includes (using the provided order).

Properties

bool

_initialized

false

Variant

_build_shader

build_shader

Shader.Mode

shader_type

0

String

prelude

""

Array[ShaderInclude]

includes

[]

PackedStringArray

flags_available

PackedStringArray()

Dictionary[String, Variant]

constants

{}

PackedStringArray

flags_enabled

PackedStringArray()

Variant

_fetch_defines

_update_flags_available

Methods

void

_update_flags_available()

bool

set_flag(flag: String, enabled: bool)

void

set_constant(constant: String, value: Variant)

bool

remove_constant(constant: String)

Array[Dictionary]

_get_property_list()

void

_get(property: StringName)

Variant

_set(property: StringName, value: Variant)

String

shader_type_string(st: Shader.Mode) static

void

_init()

void

_postinit()

void

build_shader()

PackedStringArray

fetch_available_defines()


Signals

rebuilt() 🔗

Emitted when the shader is initially built or rebuilt.


Constants

_FLAG_PREFIX = "flag_" 🔗

There is currently no description for this constant. Please help us by contributing one!

_STRUCTURE = "shader_type {shader_type};\n// Constants\n{constants}\n// Flags\n{defines}\n// Prelude\n{prelude}\n//Includes\n{includes}\n" 🔗

There is currently no description for this constant. Please help us by contributing one!


Property Descriptions

bool _initialized = false 🔗

There is currently no description for this property. Please help us by contributing one!


Variant _build_shader = build_shader 🔗

There is currently no description for this property. Please help us by contributing one!


Shader.Mode shader_type = 0 🔗

  • void @shader_type_setter(value: Shader.Mode)

The shader type to generate.


String prelude = "" 🔗

  • void @prelude_setter(value: String)

Any code you want to include in the shader before the list of includes. Placed after the defines.


Array[ShaderInclude] includes = [] 🔗

  • void @includes_setter(value: Array[ShaderInclude])

An ordered list of shader includes to include in the shader, after defines.


PackedStringArray flags_available = PackedStringArray() 🔗

  • void @flags_available_setter(value: PackedStringArray)

A list of shader defines that can be toggled under the Flags group.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


Dictionary[String, Variant] constants = {} 🔗

  • void @constants_setter(value: Dictionary[String, Variant])

Constant values to be used as defines in the shader.

Currently only int, float, bool, and String types are supported.


PackedStringArray flags_enabled = PackedStringArray() 🔗

A list of all defines that should be enabled in the shader.

If changed from code, remember to call build_shader() to rebuild the shader.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


Variant _fetch_defines = _update_flags_available 🔗

There is currently no description for this property. Please help us by contributing one!


Method Descriptions

void _update_flags_available() 🔗

There is currently no description for this method. Please help us by contributing one!


bool set_flag(flag: String, enabled: bool) 🔗

Sets the given flag as enabled or disabled. Returns true if the preprocessor list changed.

Call build_shader() afterward to force a recompile.


void set_constant(constant: String, value: Variant) 🔗

Sets the named constant to the given value.

Call build_shader() afterward to force a recompile.


bool remove_constant(constant: String) 🔗

Removes the named constant. Returns true if the given constant existed in the dictionary.

Call build_shader() afterward to force a recompile.


Array[Dictionary] _get_property_list() 🔗

There is currently no description for this method. Please help us by contributing one!


void _get(property: StringName) 🔗

There is currently no description for this method. Please help us by contributing one!


Variant _set(property: StringName, value: Variant) 🔗

There is currently no description for this method. Please help us by contributing one!


String shader_type_string(st: Shader.Mode) static 🔗

Returns a string for the given shader type.


void _init() 🔗

There is currently no description for this method. Please help us by contributing one!


void _postinit() 🔗

There is currently no description for this method. Please help us by contributing one!


void build_shader() 🔗

Rebuilds the shader from scratch. In order for Godot to recompile the shader code, a new Shader is created.

Frequently rebuilding the shader can have a negative impact on performance, so only call this when necessary.


PackedStringArray fetch_available_defines() 🔗

Searches through all provided shader includes, and returns a list of toggleable shader defines.