![]() |
Skylicht Engine
|
Directories | |
| Instancing | |
| ShaderCallback | |
Files | |
| CBaseShaderCallback.h | |
| CShader.h | |
| CShaderManager.h | |
| CShaderParams.h | |
Let's take a look at an example shader file (.xml)
Additionally, you can view sample shader files in the Assets\BuiltIn\Shader folder.
<shaderConfig name="TransparentColor" baseShader="TRANSPARENT_ALPHA_CHANNEL">
| Attribute | Description | Value |
|---|---|---|
| name | This is the shader name | |
| baseShader | Description of inherited shader | SOLID TRANSPARENT_ADD_COLOR TRANSPARENT_MULTIPLY_COLOR TRANSPARENT_SCREEN_COLOR TRANSPARENT_ALPHA_CHANNEL |
<uniform name="uColor" type="MATERIAL_PARAM" valueIndex="1" value="1.0, 1.0, 1.0, 1.0" float="4"/>
| Attribute | Description | Value |
|---|---|---|
| name | This is the Uniform name attached to the vertex shader or fragment shader | |
| type | The value passed to the uniform | See next table |
| valueIndex | Is an input parameter for a value type | |
| value | Default value | |
| float | Number of elements in the array | Example: 1 is float 4 is float4 16 is float4x4 |
| matrix | If a uniform is a matrix, this attribute is required for the Skylicht-Engine to transpose the matrix for DirectX | true |
| directX | When the directX=false attribute is set, this uniform will be ignored if the engine is using DirectX. For uniform textures, this property is needed because OpenGL and DirectX handle uniform binding a bit differently. DirectX doesn't require binding uniform textures | false |
Value table for the type property
| Type | Value type | Description |
|---|---|---|
| VIEW | float4x4 | Model-to-camera transformation matrix. viewMatrix = getVideoDriver()->getTransform(video::ETS_VIEW) |
| WORLD | float4x4 | Model transformation matrix. worldMatrix = getVideoDriver()->getTransform(video::ETS_WORLD) |
| VIEW_PROJECTION | float4x4 | It's often used when rendering with instancing, because world matrices are batched in the vertex attributes vpMatrix = projectionMatrix * viewMatrix |
| WORLD_VIEW_PROJECTION | float4x4 | The MVP transformation matrix to convert vertex coordinates from 3D to 2D. mvpMatrix = projectionMatrix x viewMatrix x worldMatrix |
| WORLD_INVERSE | float4x4 | Matrix to transform vertices from world coordinates to local coordinates, where local coordinates are the coordinates within the 3D model file. |
| WORLD_TRANSPOSE | float4x4 | |
| BONE_MATRIX | float4x4[64] | Matrices to transform skin-vertices to the animated skeleton's positions. See BuiltIn/Shader/Toon/SkinToon.xml |
| BONE_COUNT | float2 | |
| SHADOW_MAP_MATRIX | float4x4[4] | Matrices to project 3D vertex coordinates onto the 2D cascade shadow map textures |
| SHADOW_MAP_DISTANCE | float4 | The maximum depth (in meters) covered by the cascade shadow map |
| SHADOW_BIAS | float4 | |
| WORLD_CAMERA_POSITION | float4 | The camera position |
| LIGHT_COLOR | float4 | |
| LIGHT_AMBIENT | float4 | |
| WORLD_LIGHT_DIRECTION | float4 | It returns the light direction vector for the directional light, similar to how you'd consider the direction of sunlight. |
| POINT_LIGHT_COLOR | float4 | The parameter valueIndex is clamped from 0 to 3, representing the order of the four closest pointlights to the object. |
| POINT_LIGHT_POSITION | float4 | The light position, See CShaderLighting::setPointLight |
| POINT_LIGHT_ATTENUATION | float4 | value.y = CLight::getAttenuation() See BuiltIn\Shader\SpecularGlossiness\Lighting System\SGPointLight.xml |
| SPOT_LIGHT_COLOR | float4 | The parameter valueIndex is clamped from 0 to 3, representing the order of the four closest spotlights to the object. |
| SPOT_LIGHT_DIRECTION | float4 | |
| SPOT_LIGHT_POSITION | float4 | The light position, See CShaderLighting::setSpotLight |
| SPOT_LIGHT_ATTENUATION | float4 | value.x = cos(CSpotLight::getSplotCutoff() * 0.5f) value.y = cos(CSpotLight::getSpotInnerCutof() * 0.5f) value.z = CLight::getAttenuation() value.w = CSpotLight::getSpotExponent() See BuiltIn\Shader\SpecularGlossiness\Lighting System\SGSpotLight.xml |
| MATERIAL_PARAM | float2 float3 float4 | Gets the value already set at valueIndex within CMaterial. See CMaterial::setUniform, CMaterial::setUniform2, CMaterial::setUniform3, CMaterial::setUniform4, CMaterial::updateShaderParams Sample project: - Code: Samples\Shader\Source\SampleShader.cpp - Shader: Assets\SampleShader\Shader\Dissolved.xml |
| DEFAULT_VALUE | ||
| SHADER_VEC2 | float2 | |
| SHADER_VEC3 | float3 | |
| SHADER_VEC4 | float4 | |
| SH_CONST | float4[4] | The value used to calculate ambient light color based on Spherical Harmonics (SH) See CIndirectLighting |
| CUSTOM_VALUE | ||
| TEXTURE_MIPMAP_COUNT | float2 | |
| TEXTURE_WIDTH_HEIGHT | float2 | |
| DEFERRED_VIEW | float4x4 | |
| DEFERRED_PROJECTION | float4x4 | |
| DEFERRED_VIEW_PROJECTION | float4x4 | |
| TIME_STEP | float2 | value.x = getTimeStep() |
| PARTICLE_VIEW_UP | float4 | Used in the particle component |
| PARTICLE_VIEW_LOOK | float4 | Used in the particle component |
| PARTICLE_ORIENTATION_UP | float4 | Used in the particle component |
| PARTICLE_ORIENTATION_NORMAL | float4 | Used in the particle component |
| LIGHTMAP_INDEX | float2 | Used in the lightmapper to bake light color to texture |
| TIME | float4 | value.x = time() value.y = time() * 2.0 value.z = time() * 3.0 value.w = time() * 4.0 Default, The return value of time() will loop from 0.0 to 4.0. However, you can also adjust the default value by setting the attribute value="8.0" in the uniform node. See BuiltIn\Shader\BasicVfx\VfxScrollUV1.xml |
| COLOR_INTENSITY | float4 | Used in the particle component. This is the return value of the CShaderMaterial::getColorIntensity() function. It's used in the shader to boost color brightness beyond the 255-byte limit. Call the CShaderMaterial::setColorIntensity(const SColorf& c) function to set the value before drawing. |
| RENDER_TEXTURE_MATRIX | float4x4 | Matrix to project 3D vertex coordinates onto a 2D render texture, which is the result of CRenderToTextureRP |
The order of uniforms defined in the .xml shader file and the .hlsl shader file must be the same.
Example:
So, in vertex shader:
Set the default texture for the uniform.
| Attribute | Description | Value |
|---|---|---|
| name | The uniform name | |
| type | See next table | |
| path | Path to the texture file (if type is Texture or CubeTexture) | |
Value table for the type property
| Type | Description |
|---|---|
| Texture | Specify the path to the texture file. |
| CubeTexture | Specify the path to the cube texture file |
| ReflectionProbe | Nearest reflection probe's reflection texture TextureCube |
| ShadowMap | Depth shadow map Texture2DArray |
| TransformTexture | CShaderTransformTexture::getTexture() |
| VertexPositionTexture | CShaderTransformTexture::getPositionTexture() |
| VertexNormalTexture | CShaderTransformTexture::getNormalTexture() |
| TransformTexture, VertexPositionTexture, VertexNormalTexture used for instanced rendering of skin meshes. See example: Samples\BoidSystem and Samples\BoidSystemVAT | |
| LastFrame | Used for Screen-Space-Reflection |
| RTT0 | Get the target texture from the Render-to-Texture Pipeline CRenderToTextureRP |
| RTT1 | |
| RTT2 | |
| RTT3 | |
| RTT4 | |
| RTT5 | |
| RTT6 | |
| RTT7 | |
Describes controls like sliders and images for adjusting uniform values in the Skylicht-Editor.
| Attribute | Description | Value |
|---|---|---|
| control | Control name | UITexture UIColor UIFloat UIFloat2 UIFloat3 UIFloat4 UIGroup |
| name | Uniform name | |
| autoReplace | Only used for the UITexture control; it will automatically find textures with corresponding filenames |
| Attribute | Description | Value |
|---|---|---|
| type | GLSL, HLSL | |
| vs | Path to the vertex shader file | |
| fs | Path to the fragment shader file | |
| vs_source fs_source | Path to the source file; it will be compiled by the python BuildShader.py command. The compiled output will be overwritten to the vs or fs path | |
| define | Definition flags during compilation | You can refer to the sample file BuiltIn\Shader\PBR\Forward\PBR.xml |
<instancing vertex="standard" shader="TransparentInstancing" instancingVertex="standard_color"/>
Instancing information is described when this shader supports instancing. It will be passed to the instancing shader when the CRenderMesh::enableInstancing method is called.
| Attribute | Description | Value |
|---|---|---|
| vertex | Description of vertex input data | standard 2tcoords tangents skin skintangents 2tcoordstangents skin2tcoordtangents |
| shader | The name of shader instancing | |
| instancingVertex | Detailed information on batched vertex instancing structure | standard_color 2texcoords_color standard_sg tangents_sg |
Example: vertex=standard
Here's how instanced vertices are batched (see CStandardColorInstancing)
Here's how instanced vertices are batched (see CStandardSGInstancing)
You can define your own batching structure.
You can read more of the source code for batching instancing here Projects\Skylicht\Engine\Material\Shader\Instancing
You can also refer to some instancing-supported shaders within the engine:
Defines an accompanying shader file (.xml) to be loaded, typically its own shader instancing.