Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CShader Class Reference

Represents a programmable shader, including uniforms, UI, resources, instancing and platform-specific options. More...

#include <Material/Shader/CShader.h>

Inheritance diagram for Skylicht::CShader:
Skylicht::CBaseShaderCallback irr::video::IShaderConstantSetCallBack irr::IReferenceCounted

Classes

struct  SUniformUI
 Structure for describing a UI element for a uniform. Used for editor integration and presentation. More...
struct  SResource
 Structure describing a shader resource (texture, cube map, etc.). More...
struct  SShader
 Structure for storing shader source file names. More...
struct  SShaderInstancing
 Structure for instancing shader information. More...
struct  SAttributeMapping
 Structure for mapping UI attributes to uniforms. More...

Public Types

enum  EUIControlType {
  UITexture = 0 , UIColor , UIFloat , UIFloat2 ,
  UIFloat3 , UIFloat4 , UIGroup , UINone ,
  UICount
}
 Enum for UI control types in material editor.
enum  EResourceType {
  Texture = 0 , CubeTexture , ReflectionProbe , ShadowMap ,
  TransformTexture , VertexPositionTexture , VertexNormalTexture , LastFrame ,
  RTT0 , RTT1 , RTT2 , RTT3 ,
  RTT4 , RTT5 , RTT6 , RTT7 ,
  ResourceCount
}
 Enum for resource types used in shaders.

Public Member Functions

 CShader ()
 Constructor. Initializes internal structures and built-in callbacks.
virtual ~CShader ()
 Destructor. Releases resources, UI, callbacks and instancing shaders.
void clear ()
 Clear all internal data (resources, uniforms, UI, etc.).
void initShader (io::IXMLReader *xmlReader, const char *source, const char *shaderFolder)
 Initialize shader from XML definition.
const std::string & getName ()
 Get the name of the shader.
const std::string & getSource ()
 Get the source file path of the shader.
const std::string & getSoftwareSkinningName ()
 Get the name of the software skinning fallback shader.
bool isSkinning ()
 Returns true if the shader supports skinning.
bool isCustomShadowDepthWrite ()
 Returns true if a custom shadow depth write shader is defined.
bool isCustomShadowDistanceWrite ()
 Returns true if a custom shadow distance write shader is defined.
CShadergetSoftwareSkinningShader ()
 Get the software skinning fallback shader.
CShadergetInstancingShader (video::E_VERTEX_TYPE vtxType)
 Get the instancing shader for a specific vertex type.
std::string getInstancingVertex (video::E_VERTEX_TYPE vtxType)
 Get the vertex type name for instancing for a specific vertex type.
bool isSupportInstancing (video::E_VERTEX_TYPE vtxType)
 Returns true if instancing is supported for the given vertex type.
void setInstancing (video::E_VERTEX_TYPE vtxType, IShaderInstancing *instancing)
 Set a custom instancing logic for a specific vertex type.
IShaderInstancinggetInstancing (video::E_VERTEX_TYPE vtxType)
 Get the custom instancing logic for a specific vertex type.
void setShadowDepthWriteShader (const char *name)
 Set the custom shadow depth write shader by name.
void setShadowDistanceWriteShader (const char *name)
 Set the custom shadow distance write shader by name.
CShadergetShadowDepthWriteShader ()
 Get the custom shadow depth write shader.
CShadergetShadowDistanceWriteShader ()
 Get the custom shadow distance write shader.
int getAttributeMappingCount ()
 Get the number of attribute mappings for editor integration.
SAttributeMappinggetAttributeMapping (int id)
 Get an attribute mapping by index.
int getNumResource ()
 Get the number of texture resources bind in shader.
int getNumVS ()
 Get the number of vertex shader uniforms.
int getNumFS ()
 Get the number of fragment shader uniforms.
SResourcegetResouceInfo (int id)
 Get a shader resource info by index.
SUniformgetVSUniformID (int id)
 Get a vertex shader uniform by index.
SUniformgetFSUniformID (int id)
 Get a fragment shader uniform by index.
int getNumUI ()
 Get the number of UI elements.
SUniformUIgetUniformUI (int id)
 Get a UI element by index.
std::vector< std::string > & getDependents ()
 Get the list of dependent shader paths.
SUniformUIgetUniformUIByName (const char *name)
 Get a UI element by uniform name.
SUniformUIgetUniformUIByName (const char *name, SUniformUI *group)
 Get a UI element by uniform name within a UI group.
SUniformgetVSUniform (const char *name)
 Get a vertex shader uniform by name.
SUniformgetFSUniform (const char *name)
 Get a fragment shader uniform by name.
bool isDeferred ()
 Returns true if this shader is used for deferred rendering.
bool isOpaque ()
 Returns true if this shader is an opaque base shader.
E_MATERIAL_TYPE getBaseMaterial ()
 Get the base material type of this shader.
virtual void OnSetConstants (video::IMaterialRendererServices *services, s32 userData, bool updateTransform)
 Callback to set shader constants (uniforms) for rendering.
template<class T>
IShaderCallbackaddCallback ()
 Add a custom callback to the shader for setting constants.
template<class T>
T * getCallback ()
 Get a custom callback of a specific type.
void buildShader ()
 Build the shader by compiling vertex and fragment sources and registering with the engine.
void buildUIUniform ()
 Build UI uniform bindings for editor integration.
bool isDrawDepthShadow ()
 Returns true if this shader renders depth for shadows.
Public Member Functions inherited from Skylicht::CBaseShaderCallback
void setMaterialRenderID (int id)
int getMaterialRenderID ()
void offsetUV (core::vector2df &uv, float speedX, float speedY)
bool isOpenGLFamily ()
void setColor (IMaterialRenderer *matRender, int colorID, bool vertexConstant, const SColorf &c, float intensity)
void setWorldDirection (IMaterialRenderer *matRender, int directionID, bool vertexConstant, const core::vector3df &dir, int count=4)
void setWorldInvPosition (IMaterialRenderer *matRender, int posID, const core::vector3df &pos, bool vertexConstant=true)
void setWorldPosition (IMaterialRenderer *matRender, int posID, const core::vector3df &pos, bool vertexConstant=true)
Public Member Functions inherited from irr::video::IShaderConstantSetCallBack
virtual void OnSetMaterial (const SMaterial &material)
 Called to let the callBack know the used material (optional method).
Public Member Functions inherited from irr::IReferenceCounted
 IReferenceCounted ()
 Constructor.
virtual ~IReferenceCounted ()
 Destructor.
void grab () const
 Grabs the object. Increments the reference counter by one.
bool drop () const
 Drops the object. Decrements the reference counter by one.
s32 getReferenceCount () const
 Get the reference count.
const c8getDebugName () const
 Returns the debug name of the object.

Protected Member Functions

void parseUniform (io::IXMLReader *xmlReader)
 Parse uniform definitions from XML.
void parseUniformUI (io::IXMLReader *xmlReader)
 Parse UI uniform definitions from XML.
void parseResources (io::IXMLReader *xmlReader)
 Parse resource definitions from XML.
void parseUI (io::IXMLReader *xmlReader, SUniformUI *parent)
 Parse UI group hierarchy from XML.
E_MATERIAL_TYPE getBaseShaderByName (const char *name)
 Get the base shader type by its name string (SOLID, TRANSPARENT, etc.).
EUniformType getUniformType (const char *name)
 Get the uniform type enum from its name string.
std::string getVSShaderFileName ()
 Get the full path to the vertex shader source file (GLSL/HLSL).
std::string getFSShaderFileName ()
 Get the full path to the fragment/pixel shader source file (GLSL/HLSL).
void buildUIUniform (SUniformUI *ui)
 Recursively build UI uniform bindings for a UI element.
bool isUniformAvaiable (SUniform &uniform)
 Check if a uniform is available on the current graphics API.
bool setUniform (SUniform &uniform, IMaterialRenderer *matRender, bool vertexShader, bool updateTransform)
 Try to set a uniform value for rendering.
void deleteAllUI ()
 Delete all UI elements.
void deleteAllResource ()
 Delete all shader resources.
Protected Member Functions inherited from irr::IReferenceCounted
void setDebugName (const c8 *newName)
 Sets the debug name of the object.

Protected Attributes

std::string m_name
 Shader name.
core::array< SUniformm_vsUniforms
 Vertex shader uniforms.
core::array< SUniformm_fsUniforms
 Pixel / fragment shader uniforms.
core::array< SUniformUI * > m_ui
 UI elements.
core::array< SResource * > m_resources
 Shader texture resources.
core::array< SAttributeMappingm_attributeMapping
 UI to uniform mapping.
std::vector< IShaderCallback * > m_callbacks
 Shader callbacks.
std::vector< std::string > m_dependents
 Dependent shader paths.
SUniformm_listVSUniforms
 Pointer to VS uniforms (m_vsUniforms).
SUniformm_listFSUniforms
 Pointer to FS uniforms (m_fsUniforms).
int m_numVSUniform
 Count of VS uniforms.
int m_numFSUniform
 Count of FS uniforms.
SShader m_glsl
 GLSL shader source.
SShader m_hlsl
 HLSL shader source.
E_MATERIAL_TYPE m_baseShader
 Base material type(opaque, transparent, etc.).
bool m_deferred
 Is shader for deferred rendering.
bool m_skinning
 Is shader for skinning.
bool m_shadow
 Is shader for shadow rendering.
std::string m_softwareSkinningShaderName
 Fallback software skinning shader name.
CShaderm_softwareSkinningShader
 Fallback software skinning shader.
std::string m_shadowDepthShaderName
 Custom shadow depth shader name for directional light.
std::string m_shadowDistanceShaderName
 Custom shadow distance shader name for point light.
CShaderm_shadowDepthShader
 Custom shadow depth shader.
CShaderm_shadowDistanceShader
 Custom shadow distance shader.
SShaderInstancingm_shaderInstancing [video::EVT_UNKNOWN+1]
 Instancing shader info by vertex type.
std::string m_source
 Source file path.
Protected Attributes inherited from Skylicht::CBaseShaderCallback
int m_materialRenderID
bool m_initCallback

Detailed Description

Represents a programmable shader, including uniforms, UI, resources, instancing and platform-specific options.

Handles parsing from XML, managing uniform parameters, callbacks, shadow/deferred settings, and integration with both OpenGL and DirectX. See documentation page: Shader information structure.

Member Function Documentation

◆ addCallback()

template<class T>
IShaderCallback * Skylicht::CShader::addCallback ( )
inline

Add a custom callback to the shader for setting constants.

Template Parameters
TThe callback class, must inherit IShaderCallback.
Returns
Pointer to the created callback.

◆ buildUIUniform()

void Skylicht::CShader::buildUIUniform ( SUniformUI * ui)
protected

Recursively build UI uniform bindings for a UI element.

Parameters
uiPointer to SUniformUI element.

◆ getAttributeMapping()

SAttributeMapping & Skylicht::CShader::getAttributeMapping ( int id)
inline

Get an attribute mapping by index.

Parameters
idIndex of the mapping.
Returns
Reference to SAttributeMapping.

◆ getAttributeMappingCount()

int Skylicht::CShader::getAttributeMappingCount ( )
inline

Get the number of attribute mappings for editor integration.

Returns
Number of attribute mappings.

◆ getBaseMaterial()

E_MATERIAL_TYPE Skylicht::CShader::getBaseMaterial ( )
inline

Get the base material type of this shader.

Returns
E_MATERIAL_TYPE value.

◆ getBaseShaderByName()

E_MATERIAL_TYPE Skylicht::CShader::getBaseShaderByName ( const char * name)
protected

Get the base shader type by its name string (SOLID, TRANSPARENT, etc.).

Parameters
nameName string.
Returns
E_MATERIAL_TYPE value.

◆ getCallback()

template<class T>
T * Skylicht::CShader::getCallback ( )
inline

Get a custom callback of a specific type.

Template Parameters
TThe callback class type.
Returns
Pointer to the callback instance, or NULL if not found.

◆ getDependents()

std::vector< std::string > & Skylicht::CShader::getDependents ( )
inline

Get the list of dependent shader paths.

Returns
Reference to vector of dependent shader paths.

◆ getFSShaderFileName()

std::string Skylicht::CShader::getFSShaderFileName ( )
protected

Get the full path to the fragment/pixel shader source file (GLSL/HLSL).

Returns
Fragment shader source file path.

◆ getFSUniform()

SUniform * Skylicht::CShader::getFSUniform ( const char * name)

Get a fragment shader uniform by name.

Parameters
nameUniform name.
Returns
Pointer to SUniform.

◆ getFSUniformID()

SUniform * Skylicht::CShader::getFSUniformID ( int id)
inline

Get a fragment shader uniform by index.

Parameters
idIndex.
Returns
Pointer to SUniform.

◆ getInstancing()

IShaderInstancing * Skylicht::CShader::getInstancing ( video::E_VERTEX_TYPE vtxType)

Get the custom instancing logic for a specific vertex type.

Parameters
vtxTypeVertex type.
Returns
Pointer to IShaderInstancing.

◆ getInstancingShader()

CShader * Skylicht::CShader::getInstancingShader ( video::E_VERTEX_TYPE vtxType)

Get the instancing shader for a specific vertex type.

Parameters
vtxTypeVertex type.
Returns
Pointer to instancing shader.

◆ getInstancingVertex()

std::string Skylicht::CShader::getInstancingVertex ( video::E_VERTEX_TYPE vtxType)

Get the vertex type name for instancing for a specific vertex type.

Parameters
vtxTypeVertex type.
Returns
Name of the instancing vertex entry point.

◆ getName()

const std::string & Skylicht::CShader::getName ( )
inline

Get the name of the shader.

Returns
Reference to shader name string.

◆ getNumFS()

int Skylicht::CShader::getNumFS ( )
inline

Get the number of fragment shader uniforms.

Returns
Number of FS uniforms.

◆ getNumResource()

int Skylicht::CShader::getNumResource ( )
inline

Get the number of texture resources bind in shader.

Returns
Number of resources.

◆ getNumUI()

int Skylicht::CShader::getNumUI ( )
inline

Get the number of UI elements.

Returns
Number of UI elements.

◆ getNumVS()

int Skylicht::CShader::getNumVS ( )
inline

Get the number of vertex shader uniforms.

Returns
Number of VS uniforms.

◆ getResouceInfo()

SResource * Skylicht::CShader::getResouceInfo ( int id)
inline

Get a shader resource info by index.

Parameters
idIndex.
Returns
Pointer to SResource.

◆ getShadowDepthWriteShader()

CShader * Skylicht::CShader::getShadowDepthWriteShader ( )

Get the custom shadow depth write shader.

Returns
Pointer to CShader instance.

◆ getShadowDistanceWriteShader()

CShader * Skylicht::CShader::getShadowDistanceWriteShader ( )

Get the custom shadow distance write shader.

Returns
Pointer to CShader instance.

◆ getSoftwareSkinningName()

const std::string & Skylicht::CShader::getSoftwareSkinningName ( )
inline

Get the name of the software skinning fallback shader.

Returns
Reference to shader name string.

◆ getSoftwareSkinningShader()

CShader * Skylicht::CShader::getSoftwareSkinningShader ( )

Get the software skinning fallback shader.

Returns
Pointer to CShader instance.

◆ getSource()

const std::string & Skylicht::CShader::getSource ( )
inline

Get the source file path of the shader.

Returns
Reference to source path string.

◆ getUniformType()

EUniformType Skylicht::CShader::getUniformType ( const char * name)
protected

Get the uniform type enum from its name string.

Parameters
nameUniform name.
Returns
EUniformType value.

◆ getUniformUI()

SUniformUI * Skylicht::CShader::getUniformUI ( int id)
inline

Get a UI element by index.

Parameters
idIndex.
Returns
Pointer to SUniformUI.

◆ getUniformUIByName() [1/2]

SUniformUI * Skylicht::CShader::getUniformUIByName ( const char * name)

Get a UI element by uniform name.

Parameters
nameUniform name.
Returns
Pointer to SUniformUI.

◆ getUniformUIByName() [2/2]

SUniformUI * Skylicht::CShader::getUniformUIByName ( const char * name,
SUniformUI * group )

Get a UI element by uniform name within a UI group.

Parameters
nameUniform name.
groupUI group parent.
Returns
Pointer to SUniformUI.

◆ getVSShaderFileName()

std::string Skylicht::CShader::getVSShaderFileName ( )
protected

Get the full path to the vertex shader source file (GLSL/HLSL).

Returns
Vertex shader source file path.

◆ getVSUniform()

SUniform * Skylicht::CShader::getVSUniform ( const char * name)

Get a vertex shader uniform by name.

Parameters
nameUniform name.
Returns
Pointer to SUniform.

◆ getVSUniformID()

SUniform * Skylicht::CShader::getVSUniformID ( int id)
inline

Get a vertex shader uniform by index.

Parameters
idIndex.
Returns
Pointer to SUniform.

◆ initShader()

void Skylicht::CShader::initShader ( io::IXMLReader * xmlReader,
const char * source,
const char * shaderFolder )

Initialize shader from XML definition.

Parameters
xmlReaderXML reader object pointing to shader definition.
sourceShader source file path.
shaderFolderFolder containing shader files.

◆ isSupportInstancing()

bool Skylicht::CShader::isSupportInstancing ( video::E_VERTEX_TYPE vtxType)

Returns true if instancing is supported for the given vertex type.

Parameters
vtxTypeVertex type.
Returns
True if supported, false otherwise.

◆ isUniformAvaiable()

bool Skylicht::CShader::isUniformAvaiable ( SUniform & uniform)
protected

Check if a uniform is available on the current graphics API.

Parameters
uniformReference to SUniform.
Returns
True if available, false otherwise.

◆ OnSetConstants()

virtual void Skylicht::CShader::OnSetConstants ( video::IMaterialRendererServices * services,
s32 userData,
bool updateTransform )
virtual

Callback to set shader constants (uniforms) for rendering.

Parameters
servicesRenderer services.
userDataUser data.
updateTransformTrue to update transforms.

Implements irr::video::IShaderConstantSetCallBack.

◆ parseResources()

void Skylicht::CShader::parseResources ( io::IXMLReader * xmlReader)
protected

Parse resource definitions from XML.

Parameters
xmlReaderXML reader object.

◆ parseUI()

void Skylicht::CShader::parseUI ( io::IXMLReader * xmlReader,
SUniformUI * parent )
protected

Parse UI group hierarchy from XML.

Parameters
xmlReaderXML reader object.
parentParent UI element (or NULL for root).

◆ parseUniform()

void Skylicht::CShader::parseUniform ( io::IXMLReader * xmlReader)
protected

Parse uniform definitions from XML.

Parameters
xmlReaderXML reader object.

◆ parseUniformUI()

void Skylicht::CShader::parseUniformUI ( io::IXMLReader * xmlReader)
protected

Parse UI uniform definitions from XML.

Parameters
xmlReaderXML reader object.

◆ setInstancing()

void Skylicht::CShader::setInstancing ( video::E_VERTEX_TYPE vtxType,
IShaderInstancing * instancing )

Set a custom instancing logic for a specific vertex type.

Parameters
vtxTypeVertex type.
instancingPointer to IShaderInstancing implementation.

◆ setShadowDepthWriteShader()

void Skylicht::CShader::setShadowDepthWriteShader ( const char * name)

Set the custom shadow depth write shader by name.

Parameters
nameShader name.

◆ setShadowDistanceWriteShader()

void Skylicht::CShader::setShadowDistanceWriteShader ( const char * name)

Set the custom shadow distance write shader by name.

Parameters
nameShader name.

◆ setUniform()

bool Skylicht::CShader::setUniform ( SUniform & uniform,
IMaterialRenderer * matRender,
bool vertexShader,
bool updateTransform )
protected

Try to set a uniform value for rendering.

Parameters
uniformReference to SUniform.
matRenderMaterial renderer.
vertexShaderTrue for vertex shader, false for pixel shader.
updateTransformTrue to update transforms. This is because the object's transform is sometimes unchanged, meaning there's no need to update it.
Returns
True if handled as built-in, false if should call plugin callback.

The documentation for this class was generated from the following file: