27#include "CBaseShaderCallback.h"
28#include "Instancing/IShaderInstancing.h"
41 WORLD_VIEW_PROJECTION,
45 WORLD_INVERSE_TRANSPOSE,
52 WORLD_CAMERA_POSITION,
55 WORLD_LIGHT_DIRECTION,
58 POINT_LIGHT_ATTENUATION,
62 SPOT_LIGHT_ATTENUATION,
68 AREA_LIGHT_SHADOW_MATRIX,
80 DEFERRED_VIEW_PROJECTION,
84 PARTICLE_ORIENTATION_UP,
85 PARTICLE_ORIENTATION_NORMAL,
89 RENDER_TEXTURE_MATRIX,
156 memset(
Value, 0,
sizeof(
float) * 16);
160 Type = NUM_SHADER_TYPE;
169 class SKYLICHT_API IShaderCallback
177 virtual ~IShaderCallback()
197 class SKYLICHT_API
CShader :
public CBaseShaderCallback
226 VertexPositionTexture,
295 for (
u32 i = 0, n =
Childs.size(); i < n; i++)
327 struct SShaderInstancing
692 return (
int)
m_ui.size();
788 if (shaderCallback == NULL)
790 char exceptionInfo[512];
791 sprintf(exceptionInfo,
"CShader::addCallback %s must inherit IShaderCallback",
typeid(T).name());
792 os::Printer::log(exceptionInfo);
812 if (
typeid(T) ==
typeid(*cb))
Represents a programmable shader, including uniforms, UI, resources, instancing and platform-specific...
Definition CShader.h:198
void parseUniform(io::IXMLReader *xmlReader)
Parse uniform definitions from XML.
SShader m_glsl
GLSL shader source.
Definition CShader.h:403
void buildShader()
Build the shader by compiling vertex and fragment sources and registering with the engine.
CShader * getShadowDistanceWriteShader()
Get the custom shadow distance write shader.
int getAttributeMappingCount()
Get the number of attribute mappings for editor integration.
Definition CShader.h:614
std::string getFSShaderFileName()
Get the full path to the fragment/pixel shader source file (GLSL/HLSL).
virtual ~CShader()
Destructor. Releases resources, UI, callbacks and instancing shaders.
core::array< SUniformUI * > m_ui
UI elements.
Definition CShader.h:376
void deleteAllUI()
Delete all UI elements.
SUniform * m_listVSUniforms
Pointer to VS uniforms (m_vsUniforms).
Definition CShader.h:391
void initShader(io::IXMLReader *xmlReader, const char *source, const char *shaderFolder)
Initialize shader from XML definition.
const std::string & getSource()
Get the source file path of the shader.
Definition CShader.h:507
SUniform * getVSUniformID(int id)
Get a vertex shader uniform by index.
Definition CShader.h:671
CShader * getShadowDepthWriteShader()
Get the custom shadow depth write shader.
void parseUI(io::IXMLReader *xmlReader, SUniformUI *parent)
Parse UI group hierarchy from XML.
bool isUniformAvaiable(SUniform &uniform)
Check if a uniform is available on the current graphics API.
CShader * m_shadowDepthShader
Custom shadow depth shader.
Definition CShader.h:433
int getNumVS()
Get the number of vertex shader uniforms.
Definition CShader.h:642
std::string getInstancingVertex(video::E_VERTEX_TYPE vtxType)
Get the vertex type name for instancing for a specific vertex type.
int getNumResource()
Get the number of texture resources bind in shader.
Definition CShader.h:633
CShader * getInstancingShader(video::E_VERTEX_TYPE vtxType)
Get the instancing shader for a specific vertex type.
void buildUIUniform()
Build UI uniform bindings for editor integration.
void parseUniformUI(io::IXMLReader *xmlReader)
Parse UI uniform definitions from XML.
EUIControlType
Enum for UI control types in material editor.
Definition CShader.h:204
core::array< SUniform > m_fsUniforms
Pixel / fragment shader uniforms.
Definition CShader.h:373
const std::string & getName()
Get the name of the shader.
Definition CShader.h:498
bool setUniform(SUniform &uniform, IMaterialRenderer *matRender, bool vertexShader, bool updateTransform)
Try to set a uniform value for rendering.
int m_numFSUniform
Count of FS uniforms.
Definition CShader.h:400
bool isDeferred()
Returns true if this shader is used for deferred rendering.
Definition CShader.h:746
E_MATERIAL_TYPE getBaseMaterial()
Get the base material type of this shader.
Definition CShader.h:763
bool m_skinning
Is shader for skinning.
Definition CShader.h:415
int m_numVSUniform
Count of VS uniforms.
Definition CShader.h:397
CShader * m_softwareSkinningShader
Fallback software skinning shader.
Definition CShader.h:424
std::vector< std::string > & getDependents()
Get the list of dependent shader paths.
Definition CShader.h:709
EUniformType getUniformType(const char *name)
Get the uniform type enum from its name string.
std::string m_name
Shader name.
Definition CShader.h:367
std::string getVSShaderFileName()
Get the full path to the vertex shader source file (GLSL/HLSL).
SUniform * getFSUniformID(int id)
Get a fragment shader uniform by index.
Definition CShader.h:681
E_MATERIAL_TYPE getBaseShaderByName(const char *name)
Get the base shader type by its name string (SOLID, TRANSPARENT, etc.).
CShader()
Constructor. Initializes internal structures and built-in callbacks.
SUniformUI * getUniformUIByName(const char *name, SUniformUI *group)
Get a UI element by uniform name within a UI group.
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.
std::string m_shadowDistanceShaderName
Custom shadow distance shader name for point light.
Definition CShader.h:430
bool isOpaque()
Returns true if this shader is an opaque base shader.
Definition CShader.h:754
bool m_shadow
Is shader for shadow rendering.
Definition CShader.h:418
bool isSupportInstancing(video::E_VERTEX_TYPE vtxType)
Returns true if instancing is supported for the given vertex type.
std::string m_shadowDepthShaderName
Custom shadow depth shader name for directional light.
Definition CShader.h:427
void deleteAllResource()
Delete all shader resources.
T * getCallback()
Get a custom callback of a specific type.
Definition CShader.h:808
IShaderCallback * addCallback()
Add a custom callback to the shader for setting constants.
Definition CShader.h:784
SUniform * m_listFSUniforms
Pointer to FS uniforms (m_fsUniforms).
Definition CShader.h:394
std::string m_source
Source file path.
Definition CShader.h:442
E_MATERIAL_TYPE m_baseShader
Base material type(opaque, transparent, etc.).
Definition CShader.h:409
core::array< SResource * > m_resources
Shader texture resources.
Definition CShader.h:379
SUniformUI * getUniformUI(int id)
Get a UI element by index.
Definition CShader.h:700
virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData, bool updateTransform)
Callback to set shader constants (uniforms) for rendering.
SResource * getResouceInfo(int id)
Get a shader resource info by index.
Definition CShader.h:661
bool isCustomShadowDistanceWrite()
Returns true if a custom shadow distance write shader is defined.
Definition CShader.h:540
bool m_deferred
Is shader for deferred rendering.
Definition CShader.h:412
CShader * getSoftwareSkinningShader()
Get the software skinning fallback shader.
bool isDrawDepthShadow()
Returns true if this shader renders depth for shadows.
Definition CShader.h:834
EResourceType
Enum for resource types used in shaders.
Definition CShader.h:220
bool isSkinning()
Returns true if the shader supports skinning.
Definition CShader.h:524
SShaderInstancing * m_shaderInstancing[video::EVT_UNKNOWN+1]
Instancing shader info by vertex type.
Definition CShader.h:439
bool isCustomShadowDepthWrite()
Returns true if a custom shadow depth write shader is defined.
Definition CShader.h:532
IShaderInstancing * getInstancing(video::E_VERTEX_TYPE vtxType)
Get the custom instancing logic for a specific vertex type.
SUniformUI * getUniformUIByName(const char *name)
Get a UI element by uniform name.
std::string m_softwareSkinningShaderName
Fallback software skinning shader name.
Definition CShader.h:421
std::vector< std::string > m_dependents
Dependent shader paths.
Definition CShader.h:388
const std::string & getSoftwareSkinningName()
Get the name of the software skinning fallback shader.
Definition CShader.h:516
core::array< SUniform > m_vsUniforms
Vertex shader uniforms.
Definition CShader.h:370
int getNumUI()
Get the number of UI elements.
Definition CShader.h:690
SShader m_hlsl
HLSL shader source.
Definition CShader.h:406
SAttributeMapping & getAttributeMapping(int id)
Get an attribute mapping by index.
Definition CShader.h:624
std::vector< IShaderCallback * > m_callbacks
Shader callbacks.
Definition CShader.h:385
int getNumFS()
Get the number of fragment shader uniforms.
Definition CShader.h:651
void setInstancing(video::E_VERTEX_TYPE vtxType, IShaderInstancing *instancing)
Set a custom instancing logic for a specific vertex type.
SUniform * getFSUniform(const char *name)
Get a fragment shader uniform by name.
core::array< SAttributeMapping > m_attributeMapping
UI to uniform mapping.
Definition CShader.h:382
void buildUIUniform(SUniformUI *ui)
Recursively build UI uniform bindings for a UI element.
CShader * m_shadowDistanceShader
Custom shadow distance shader.
Definition CShader.h:436
void parseResources(io::IXMLReader *xmlReader)
Parse resource definitions from XML.
SUniform * getVSUniform(const char *name)
Get a vertex shader uniform by name.
void clear()
Clear all internal data (resources, uniforms, UI, etc.).
Interface for shader callbacks, used to set constants in user-extended shaders.
Definition CShader.h:170
virtual void OnSetConstants(CShader *shader, SUniform *uniform, IMaterialRenderer *matRender, bool vertexShader)=0
Called to set uniform constants for the shader.
Abstract base class for GPU instancing logic in Skylicht-Engine.
Definition IShaderInstancing.h:45
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
Interface for material rendering.
Definition IMaterialRenderer.h:27
Interface providing some methods for changing advanced, internal states of a IVideoDriver.
Definition IMaterialRendererServices.h:21
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
EUniformType
Enum for all supported uniform types in shaders. See documentation page: Shader information structure...
Definition CShader.h:39
IIrrXMLReader< wchar_t, IReferenceCounted > IXMLReader
An xml reader for wide characters, derived from IReferenceCounted.
Definition IXMLReader.h:19
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.h:19
@ EVT_UNKNOWN
Null.
Definition S3DVertex.h:37
E_MATERIAL_TYPE
Abstracted and easy to use fixed function/programmable pipeline material modes.
Definition EMaterialTypes.h:15
@ EMT_SOLID
Standard solid material.
Definition EMaterialTypes.h:19
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
signed int s32
32 bit signed variable.
Definition irrTypes.h:66
Structure for mapping UI attributes to uniforms.
Definition CShader.h:357
std::string AttributeName
Associated editor attribute name.
Definition CShader.h:362
std::string UniformName
Name of the uniform.
Definition CShader.h:359
Structure describing a shader resource (texture, cube map, etc.).
Definition CShader.h:306
Structure for storing shader source file names.
Definition CShader.h:316
std::string FragmentShader
Fragment / pixel shader file path.
Definition CShader.h:321
std::string VertexShader
Vertex shader file path.
Definition CShader.h:318
Structure for instancing shader information.
Definition CShader.h:328
video::E_VERTEX_TYPE VertexType
Vertex type for instancing.
Definition CShader.h:330
std::string InstancingVertex
Definition CShader.h:337
std::string ShaderName
Name of instancing shader.
Definition CShader.h:333
IShaderInstancing * Instancing
Custom instancing logic.
Definition CShader.h:340
CShader * InstancingShader
Pointer to instancing shader.
Definition CShader.h:343