Shader Documentation
[
Front page
] [
New
|
Page list
|
Search
|
Recent changes
|
Help
|
Log in
]
Start:
*Shader Documentation [#zac52db8]
#contents
**Location of the Created Shader [#qbd0b7ef]
- ''Folder for Storing Shaders''
To apply the created shader to Bakin, place the following...
The “xxx” sections in the table represent shader names.
|xxx.cg|Shader itself|
|xxx.txt|Resources > Material Properties: shader descript...
- ''Text for Description Field and Property Field''
This text is required when registering a shader in the Re...
By including a language code, you can set text tailored t...
When creating it, please refer to the .txt file of an exi...
**Shader Documentation [#y848575e]
**Declaration [#x0a3f2ea]
-&size(16){''Version''};
--''Example''
//_VERSION(3)
--''Description''
The current version is 3.
#br
#br
-&size(16){''Shader Type''};
--''Example''
//_SHADER_TYPE(surface)
--''Description''
Declares the shader to be a surface type (using a common ...
---''surface'': A shader that uses the common vertex shad...
---''screen'': A shader intended for post effects and sim...
---''ui'': A shader for UI rendering (used internally).
---If you use your own vertex shaders, do not declare the...
#br
#br
-&size(16){''Custom Pass''};
--''Example''
//_CUSTOM_PASS(outline,shadow,pickup,hidden_area)
--''Description''
Bakin renders the same model several times with different...
For example, rendering when creating a shadow map. These ...
---''Shadow''
---''Outline''
---''Pickup'': Hit test on the editor screen
---''HiddenArea'': When the main cast members are hidden ...
#br
Although these shaders are provided in common, there are ...
In doing so, use the _CUSTOM_PASS declaration to inform B...
Cases you may want to handle individually are, for exampl...
#br
#br
-&size(16){''GUID''};
--''Example''
//_GUID(0123456789ABCDEF0123456789ABCDEF)
--''Description''
Describe the non-hyphenated GUID for each shader.
Used to distinguish between shader files with the same na...
GUIDs can be created on websites, GUIDGen in VisualStudio...
#br
#br
-&size(16){''Vertex Shader Input''};
--''Example''
//_VIN(position)
--''Description''
Specifies elements to be input to the vertex shader.
---''position''
---''texCoord0'' Texture coordinate 0
---''texCoord1'' Texture coordinate 1
---''normal''
---''tangent''
---''color''
#br
The above can be specified.
#br
#br
-&size(16){''Vertex Shader Output''};
--''Example''
//_VOUT(normal)
--''Description''
Specifies the elements to be output from the vertex shade...
---''texCoord0'' Texture coordinate 0
---''texCoord1'' Texture coordinate 1
---''normal''
---''tangent''
---''binormal''
---''color''
#br
The above are supported.
#br
#br
-&size(16){''2D Texture''};
--''Example''
//_DECL_TEXTURE_2D(name)
--''Description''
Declares a 2D texture called name.
#br
#br
-&size(16){''Cube Texture''};
--''Example''
//_DECL_TEXTURE_CUBE(name)
--''Description''
Declares a cube texture called name.
#br
#br
-&size(16){''3D Texture''};
--''Example''
//_DECL_TEXTURE_3D(name)
--''Description''
Declares a 3D texture called name.
---The maximum number of user-defined textures is 10.
#br
#br
-&size(16){''RGB Color''};
--''Example''
//_DECL_COLOR3(name)
--''Description''
Declares a color parameter called name.
#br
#br
-&size(16){''RGBA Color''};
--''Example''
//_DECL_COLOR4(name)
--''Description''
Declares a color parameter called name.
#br
#br
-&size(16){''float Parameter''};
--''Example''
//_DECL_FLOAT(name)
//_DECL_FLOAT2(name)
//_DECL_FLOAT3(name)
//_DECL_FLOAT4(name)
--''Description''
Declares a froat parameter called name.
#br
#br
-&size(16){''Integer Parameter''};
--''Example''
//_DECL_INT(name)
//_DECL_INT2(name)
//_DECL_INT3(name)
//_DECL_INT4(name)
--''Description''
Declares an integer parameter called name.
#br
#br
-&size(16){''BOOL Parameter''};
--''Example''
//_DECL_BOOL(name)
--''Description''
Declares a BOOL parameter called name.
#br
#br
-&size(16){''MATRIX Parameter''};
--''Example''
//_DECL_MATRIX(name)
--''Description''
Declares a 4x4 matrix called name.
---Matrix cannot be edited from the Material Editor.
#br
#br
-&size(16){''ENUM Parameter''};
--''Example''
//_DECL_ENUM(name);//enum:Red Green Blue
--''Description''
Declares an ENUM parameter called name.
After the declaration, declare the name to be enumerated ...
**Declaration 2 [#wb2ba2bd]
-&size(16){''Main Drawing Pass''};
--''Example''
//_DRAW_PASS(opaque)
--''Description''
Specifies when the main pass will be drawn.
---''opaque''
---''unlit'': Opaque drawing after 'opaque' pass
---''skybox'': After unlit, drawing the sky sphere, etc.
---''translucent''
#br
You can choose from the above.
#br
#br
-&size(16){''Blend''};
--''Example''
//_BLEND(true)
--''Description''
This setting determines whether or not blending is enable...
You can choose true/false.
Valid when using translucent pass.
#br
#br
-&size(16){''Blend Settings''};
--''Example''
#br
//_BLEND_SRC_COLOR(one);
//_BLEND_DST_COLOR(one);
//_BLEND_SRC_ALPHA(one);
//_BLEND_DST_ALPHA(one);
--''Description''
Specifies the blending method when blending is enabled.
SRCCOLOR/DSTCOLOR sets the color weighting SRCALPHA/DSTAL...
---''zero''
---''one''
---''srccolor''
---''rsrccolor''
---''dstcolor''
---''rdstcolor''
---''srcalpha''
---''rsrcalpha''
---''dstalpha''
---''rdstalpha''
#br
You can choose from the above.
#br
#br
-&size(16){''Color Write''};
--''Example''
@//_COLOR_WRITE(true true true true)
--''Description''
Configure whether to write to each RGBA channel.
If not declared, writing occurs to all channels.
#br
#br
#br
#br
-&size(16){''Depth Test''};
--''Example''
//_DEPTH_TEST(false)
--''Description''
Sets whether or not to use depth testing on the main pass.
#br
#br
-&size(16){''Depth Write''};
--''Example''
//_DEPTH_WRITE(true)
--''Description''
Sets whether or not the depth is written in the main pass.
#br
#br
-&size(16){''Stencil Ref''};
--''Example''
//_STENCIL_REF(1)
--''Description''
Sets the reference value for the stencil test for the mai...
#br
#br
-&size(16){''Stencil Mask''};
--''Example''
//_STENCIL_MASK(1)
--''Description''
Sets the stencil test mask value for the main pass.
#br
#br
-&size(16){''Stencil Test''};
--''Example''
//_STEINCIL_ENABLE(true)
--''Description''
Specifies whether stencil testing is enabled on the main ...
#br
#br
-&size(16){''Stencil Op''};
--''Example''
//_STENCIL_OPPASS()
//_STENCIL_OPDEPTHFAIL()
//_STENCIL_OPFAIL()
--''Description''
Sets how the stencil value will be used in the test resul...
---''keep''
---''replace'': Replace by Ref value
---''inc'': Increase by 1
---''dec'': Decrease by 1
#br
You can choose from the above.
#br
#br
-&size(16){''Test Func''};
--''Example''
//_DEPTH_FUNC(lequal)
//_STENCIL_FUNC(noteqal)
--''Description''
You can specify acceptable/failure types for the main pas...
---''never'': Always failed.
---''less'': If less than, then acceptable.
---''equal'': If equal, then acceptable.
---''lequal'': If less than or equal to, then acceptable.
---''greater'': If greater than, then acceptable.
---''notequal'': If not equal, then acceptable.
---''gequal'': If greater than or equal to, then acceptab...
---''always'': Always acceptable.
#br
You can choose from the above.
#br
#br
-&size(16){''Dither Translucent''};
--''Example''
@//_DITHER_TRANSLUCENT(false)
--''Description''
Disable the use of dithered transparency in opaque path s...
#br
#br
-&size(16){''Skin''};
--''Example''
@//_SKIN(false)
--''Description''
Declare that skinning (bone-based deformation) is not per...
Include this declaration whenever possible to reduce shad...
#br
#br
-&size(16){''Morph''};
--''Example''
@//_MORPH(false)
--''Description''
Declare that no morphing (shape animation) will be perfor...
Include this declaration whenever possible to reduce shad...
#br
#br
-&size(16){''ZPrepass''};
--''Example''
@//_ZPREPASS(false)
--''Description''
Disable rendering to the Z-prepass in the opaque path sha...
#br
#br
-&size(16){''Forward Fog''};
--''Example''
@//_FORWARD_FOG(true)
--''Description''
Add fog effects to the rendering of translucent paths.
#br
#br
-&size(16){''Outline Pass''};
--''Example''
@//_NO_OUTLINE_PASS(true)
--''Description''
Disable the generation of outline rendering shaders.
#br
#br
-&size(16){''Hidden Area Pass''};
--''Example''
@//_NO_HIDDEN_AREA_PASS(true)
--''Description''
Disable shader generation for rendering player character ...
#br
#br
-&size(16){''Cast Shadow''};
--''Example''
@//_CAST_SHADOW(false)
--''Description''
Disable shadow rendering.
**Parameters (Uniform) [#v231a222]
This section explains the parameters that are passed from...
-&size(16){''SYSTEMCOMMONBLOCK''};
--''Description''
It contains information about the scene.
Data can be accessed with its variable name.
#br
vec3 eyePosition; //Camera position
vec3 eyeDirection; //Camera orientation (-Z)
mat4 projToWorld; //Projection to World matrix
mat4 worldToProj; //World to Projection matrix
mat4 projToView; //Projection To View(Camera) matrix
mat4 viewToProj; //View(Camera) To Projection matrix
mat4 worldToView; //World To View matrix
float drawTime; //Elapsed time (sec)
int drawCount; //Number of elapsed frames
float reflectionIntensity; //Environment Map Intensity
float reflectionMipCount; //Number of environment map m...
float IBLMipIndex; //Environment map mipmap index for...
float IBLIntensity; //IBL Intensity
vec4 fogColor; //fog(See editor's Rendering Settings)
float fogStart;
float fogDepthDensity;
float fogHeightFallOff;
vec2 _3DScreenSize; //Viewport size for 3D rendering
vec2 _3DScreenScale; //Scale to frame buffer during 3D...
vec2 _DefaultSurfaceSize; //Frame buffer size for 3D re...
vec2 _GameViewScreenSize; //Game Resolution
mat4 shadowMatrix[4]; //Shadow Matrix
int cascadeCount; //Shadow cascade count
float cascadeVisualize; //For Development
float shadowBias; //Shadow Bias
float shadowDistance; //Shadow effective distance
float shadowmapScale; //Dynamic resolution of shadow map
//One Directional(With Shadow)
vec3 directionalLightDir; //Parallel light source dire...
vec3 directionalLightColor; //Parallel light source co...
vec3 directionalLightShadowColor; //Unused
//Ambient
vec3 ambientLightColor; //Ambient light color
float buildingLightBrightness; //Brightness of b...
float ssrScale; //Unused
float billboardLightModulation; //Billboard Light Inte...
vec4 hiddenAreaColor; //Color of Hidden Area
float distanceFadeBias; //Distance Fade Parameter
float distanceFadeStart;
float distanceFadeNearClip;
//
float deltaTime; //Elapsed time from previous frame
#br
#br
-&size(16){''SYSTEMMATERIALBLOCK''};
#br
Material parameters assigned by the system.
Accessed by SVAL(name) macro.
SVAL(emissionMultiply)
The above and more.
#br
int localLightCount; //Number of allocated local lig...
int localLightIndex[LOCALLIGHTASSIGNLIMIT]; //Index of ...
float emissionMultiply; //Emissive Strength
float opacityMultiplier; //Opacity Strength
vec4 overrideColor; //Override Color
float outlineWidth; //Outline Width
vec4 outlineColor; //Outline Color
float pickupID; //ID for the editor
float distanceFadeBias; //Distance fade bias
float buildingLightMask; //Whether it is affected by...
vec2 uvofs; //Built-in UV Offset
vec2 uvscl; //Built-in UV Scale
mat3x4 localToWorldMatrix; //local to world matrix (typ...
mat3x4 worldToLocalMatrix; //world to local matrix (typ...
mat3x4 localToWorldAxis; //local to world matrix (ty...
mat3x4 worldToLocalAxis; //world to local matrix (ty...
#br
#br
-&size(16){''LOCALLIGHTLISTBLOCK''};
#br
Local light information is stored in an array.
You can find the index of the array based on the localLig...
#br
struct LocalLight{
int type; //Light Type
float radius; //Radius
float specularScale; //Specular strength
vec3 color; //Color
vec3 position; //Position
float innerAngle; //Internal angle of spotlight
vec3 direction; //Spotlight Direction
float outerAngle; //External angle of spotlight
};
LocalLight _localLights[LOCAL_LIGHT_BLOCK_ARRAYSIZE];
#br
#br
-&size(16){''USERMATERIAL''};
#br
A parameter declared in the shader, accessed using the UV...
//DECL_COLOR3(color)
If you declare something like above,
vec3 tmp = UVAL(color);
can be used.
**Compile Condition [#s7714dfd]
-&size(16){''Vertex Shader''};
FLAG_VP is defined during compilation.
#br
#ifdef FLAG_VP
/*Describe vertex shader*/
#endif
#br
If you bundle as above, that part will be enabled when co...
#br
#br
-&size(16){''Fragment Shader''};
FLAG_FP is defined during compilation.
#br
#ifdef FLAG_FP
/*Describe fragment shader*/
#endif
If you bundle as above, that part will be enabled when co...
#br
#br
-&size(16){''Pass''};
Bakin creates several passages from a single shader.
#br
--''Main'' The pass for normal rendering.
--''Shadow'' The pass for rendering shadows.
--''Outline'' The pass for rendering outlines.
--''Pickup'' This is the pass used to test mouse hits in ...
--''HiddenArea'' The pass is used to render the area that...
#br
Each is defined at compilation time as follows:
#br
--Main : _MAIN_PASS_COMPILE
--Shadow : _SHADOW_PASS_COMPILE
--Outline : _OUTLINE_PASS_COMPILE
--Pickup : _PICKUP_PASS_COMPILE
--HiddenArea : _HIDDEN_AREA_PASS_COMPILE
#br
For example, the Shadow pass is as follows:
#br
#ifdef _SHADOW_PASS_COMPILE
/*Description for shadow pass case*/
#endif
#br
You can describe the behavior of the Shadow pass by bundl...
#br
''If a pass other than Main is not described, a common so...
''If you want to describe a pass, declare _CUSTOM_PASS an...
#br
As an example of describing multiple passes, refer to the...
#br
#ifdef FLAG_VP
#ifdef _SHADOW_PASS_COMPILE
VertexOutStruct usermain(VertexInStruct vin)
{
/*Vertex shader code for shadow pass*/
}
#endif
#ifdef _MAIN_PASS_COMPILE
VertexOutStruct usermain(VertexInStruct vin)
{
/*Vertex shader code for the main pass*/
}
#endif
#endif
#br
**User Main Functions [#f9edf0bb]
''The main functions of vertex shader and fragment shader...
-&size(16){''Vertex Shader''};
Input is done with a structure called VertexInStruct and ...
例
#br
VertexOutStruct usermain(VertexInStruct vin)
{
VertexOutStruct vout
vout.position = calcPositionWorldToScreen(calcPositionL...
vout.texCoord0.xy = vin.uv0.xy;
return vout;
}
#br
#br
-&size(16){''Fragment Shader''};
FragmentInStruct is used for input.
#br
For opaque rendering, returns PBRMaterialResult and the c...
例
#br
PBRMaterialResult usermain(FragmentInStruct fin)
{
vec4 t = SAMPLING2D( AMap, fin.texCoord0.xy );
if(t.w < UVAL(discard_threshold))discard;
vec4 nt = SAMPLING2D( NMap, fin.texCoord0.xy );
nt.xyz = decompressNormal(nt.xy);
vec3 n = nt.y * fin.binormal * UVAL(normalscl) + nt.x *...
vec4 rmt = SAMPLING2D( RMMap, fin.texCoord0.xy );
PBRMaterialResult fout;
fout.baseColor = t.xyz * fin.color.xyz * UVAL(color);
fout.normal = normalize(n.xyz);
fout.roughness = rmt.g * UVAL(roughness);
fout.metallic = rmt.b * UVAL(metallic);
fout.specular= rmt.a * UVAL(specular);
fout.emissiveColor = UVAL(emissive_color) * rmt.r * UVA...
fout.worldPosition = CalcWorldPosition();
fout.opacity = 1.0f;
fout.sssColor = vec4(0,0,0,0);
return fout;
}
#br
The members of PBRMaterialResult are as follows:
#br
--''baseColor''
--''normal''
--''roughness''
--''metallic''
--''specular''
--''emissiveColor''
--''worldPosition'': World coordinate system position
--''opacity'': Used for dither translucent processing
--''sssColor'': SSS color and applicability
#br
Otherwise, Unlit and Translucent return vec4 colors.
Example:
#br
vec4 usermain(FragmentInStruct fin)
{
return SAMPLING2D( DifMap, fin.texCoord0.xy ) * fin.col...
}
**Function [#oceb0148]
-&size(16){''Matrix''};
For compatibility, please use the mul macro for matrix mu...
-&size(16){''Samplers''};
Samplers should use the following macros for compatibility.
#br
--''SAMPLING2D(name, uv)'': 2D texture sampling, uv is vec2
--''SAMPLING2DLOD(name, uv)'': LOD sampling of 2D texture...
--''SAMPLING3D(name, uvw)'': 3D texture sampling, uvw is ...
--''SAMPLING3DLOD(name, uvw)'': LOD sampling of 3D textur...
--''SAMPLINGCUBE(name, uv)'': Cube map sampling, uv is ve...
--''SAMPLINGCUBELOD(name, uv)'': Cube map sampling, uv is...
#br
#br
-&size(16){''Vertex Shader Functions''};
--''World Position''
vec3 calcPositionLocalToWorld(vec3 vtx)
--- ''Description''
Passing a world vertex position vtx returns vec3 converte...
--''View Position''
vec3 calcPositionWorldToView(vec3 vtx)
--- ''Description''
Passing a world vertex position vtx returns vec3 converte...
--''Screen Position''
vec4 calcPositionWorldToScreen(vec3 vtx)
--- ''Description''
Passing a world vertex vtx returns vec4 in the clipping c...
--''Screen Position 2''
vec4 calcPositionViewToScreen(vec3 vtx)
--- ''Description''
Passing view vertex vtx returns vec4 in the clipping coor...
--''World Normal Calculation''
vec3 calcNormalLocalToWorld(vec3 normal)
--- ''Description''
Passing a local normal will convert it to a world normal ...
--''World Tangent Calculation''
vec4 calcTangentLocalToWorld(vec4 tangent)
--- ''Description''
Passing a local tangent is converted to a world tangent a...
--''Binormal Calculation''
vec3 calcBinormal(vec3 normal, vec4 tangent)
--- ''Description''
Finds binormal from the outer product of the normal and t...
--''Outline Calculation''
vec calcOutlineVertex(vec3 vtx, vec3 normal)
--- ''Description''
Returns the position of the vertex after translating it a...
--''World Matrix''
vec3 getLocalToWorldMatrix()
--- ''Description''
Returns the matrix for transforming a model's vertices fr...
--''Outline Width''
@float getOutlineWidth()
--- ''Description''
Returns the width of the outline set in the material.
#br
#br
-&size(16){''Fragment Shader Functions''};
--''World Position''
vec3 CalcWorldPosition()
--- ''Description''
Converts from the current fragment position to world coor...
--''View Coordinate Position''
vec3 CalcViewPosition()
--- ''Description''
Converts from the current fragment position to the coordi...
--''Directional Light Brightness''
float directionalLightAttenuation(vec3 wposition)
--- ''Description''
Obtains the state of hiding by shadow of a directional li...
--''Local Light Brightness''
float localLightAttenuation(int index, vec3 wposition)
--- ''Description''
Obtains the influence of a local light.
--''Number of Local Lights''
int getLocalLightCount()
--- ''Description''
Returns the number of local lights.
--''Local Light Position''
vec3 getLocalLightPosition(int index)
--- ''Description''
Returns the position of the index-th local light.
--''Local Light Color''
getLocalLightColor(int index)
--- ''Description''
Returns the color of the index-th local light.
--''Fog Calculation''
vec4 calcFog(vec3 wposition)
--- ''Description''
Calculates fog for a specified world position.
--''Environment Map''
vec3 GetReflectionImg(vec3 wposition, vec3 normal, float...
--- ''Description''
Returns the environment map at the specified position and...
Specify the MipMap level derived from roughness and other...
The maximum MipMap level for the environment map can be o...
--''IBL''
vec3 GetIBL( vec3 normal, float level)
--- ''Description''
Returns the IBL for the specified normal direction. The I...
level specifies the MipMap level of the environment map (...
--''Outline Color''
vec4 fpGetOutlineColor()
--- ''Description''
Returns the outline color considering linear lighting.
--''PBR Lighting''
PBRLightingResult PbrSSSWithWorldPosition(vec3 albedo, v...
--- ''Description''
Providing PBR parameters returns the lighting result.
--''Unlit''
vec4 Unlit(vec3 emissive, float opacity, vec3 worldPosit...
--- ''Description''
Performs the necessary calculations for Unlit materials a...
--''Unlit with Reflection''
vec4 UnlitWithReflection(vec3 albedo, vec3 normal, vec3 ...
--- ''Description''
Returns a color that reflects the environment map without...
--''Translucent''
void Translucent(vec4 value, vec3 worldPosition)
--- ''Description''
Returns a color for translucent rendering, taking fog and...
End:
*Shader Documentation [#zac52db8]
#contents
**Location of the Created Shader [#qbd0b7ef]
- ''Folder for Storing Shaders''
To apply the created shader to Bakin, place the following...
The “xxx” sections in the table represent shader names.
|xxx.cg|Shader itself|
|xxx.txt|Resources > Material Properties: shader descript...
- ''Text for Description Field and Property Field''
This text is required when registering a shader in the Re...
By including a language code, you can set text tailored t...
When creating it, please refer to the .txt file of an exi...
**Shader Documentation [#y848575e]
**Declaration [#x0a3f2ea]
-&size(16){''Version''};
--''Example''
//_VERSION(3)
--''Description''
The current version is 3.
#br
#br
-&size(16){''Shader Type''};
--''Example''
//_SHADER_TYPE(surface)
--''Description''
Declares the shader to be a surface type (using a common ...
---''surface'': A shader that uses the common vertex shad...
---''screen'': A shader intended for post effects and sim...
---''ui'': A shader for UI rendering (used internally).
---If you use your own vertex shaders, do not declare the...
#br
#br
-&size(16){''Custom Pass''};
--''Example''
//_CUSTOM_PASS(outline,shadow,pickup,hidden_area)
--''Description''
Bakin renders the same model several times with different...
For example, rendering when creating a shadow map. These ...
---''Shadow''
---''Outline''
---''Pickup'': Hit test on the editor screen
---''HiddenArea'': When the main cast members are hidden ...
#br
Although these shaders are provided in common, there are ...
In doing so, use the _CUSTOM_PASS declaration to inform B...
Cases you may want to handle individually are, for exampl...
#br
#br
-&size(16){''GUID''};
--''Example''
//_GUID(0123456789ABCDEF0123456789ABCDEF)
--''Description''
Describe the non-hyphenated GUID for each shader.
Used to distinguish between shader files with the same na...
GUIDs can be created on websites, GUIDGen in VisualStudio...
#br
#br
-&size(16){''Vertex Shader Input''};
--''Example''
//_VIN(position)
--''Description''
Specifies elements to be input to the vertex shader.
---''position''
---''texCoord0'' Texture coordinate 0
---''texCoord1'' Texture coordinate 1
---''normal''
---''tangent''
---''color''
#br
The above can be specified.
#br
#br
-&size(16){''Vertex Shader Output''};
--''Example''
//_VOUT(normal)
--''Description''
Specifies the elements to be output from the vertex shade...
---''texCoord0'' Texture coordinate 0
---''texCoord1'' Texture coordinate 1
---''normal''
---''tangent''
---''binormal''
---''color''
#br
The above are supported.
#br
#br
-&size(16){''2D Texture''};
--''Example''
//_DECL_TEXTURE_2D(name)
--''Description''
Declares a 2D texture called name.
#br
#br
-&size(16){''Cube Texture''};
--''Example''
//_DECL_TEXTURE_CUBE(name)
--''Description''
Declares a cube texture called name.
#br
#br
-&size(16){''3D Texture''};
--''Example''
//_DECL_TEXTURE_3D(name)
--''Description''
Declares a 3D texture called name.
---The maximum number of user-defined textures is 10.
#br
#br
-&size(16){''RGB Color''};
--''Example''
//_DECL_COLOR3(name)
--''Description''
Declares a color parameter called name.
#br
#br
-&size(16){''RGBA Color''};
--''Example''
//_DECL_COLOR4(name)
--''Description''
Declares a color parameter called name.
#br
#br
-&size(16){''float Parameter''};
--''Example''
//_DECL_FLOAT(name)
//_DECL_FLOAT2(name)
//_DECL_FLOAT3(name)
//_DECL_FLOAT4(name)
--''Description''
Declares a froat parameter called name.
#br
#br
-&size(16){''Integer Parameter''};
--''Example''
//_DECL_INT(name)
//_DECL_INT2(name)
//_DECL_INT3(name)
//_DECL_INT4(name)
--''Description''
Declares an integer parameter called name.
#br
#br
-&size(16){''BOOL Parameter''};
--''Example''
//_DECL_BOOL(name)
--''Description''
Declares a BOOL parameter called name.
#br
#br
-&size(16){''MATRIX Parameter''};
--''Example''
//_DECL_MATRIX(name)
--''Description''
Declares a 4x4 matrix called name.
---Matrix cannot be edited from the Material Editor.
#br
#br
-&size(16){''ENUM Parameter''};
--''Example''
//_DECL_ENUM(name);//enum:Red Green Blue
--''Description''
Declares an ENUM parameter called name.
After the declaration, declare the name to be enumerated ...
**Declaration 2 [#wb2ba2bd]
-&size(16){''Main Drawing Pass''};
--''Example''
//_DRAW_PASS(opaque)
--''Description''
Specifies when the main pass will be drawn.
---''opaque''
---''unlit'': Opaque drawing after 'opaque' pass
---''skybox'': After unlit, drawing the sky sphere, etc.
---''translucent''
#br
You can choose from the above.
#br
#br
-&size(16){''Blend''};
--''Example''
//_BLEND(true)
--''Description''
This setting determines whether or not blending is enable...
You can choose true/false.
Valid when using translucent pass.
#br
#br
-&size(16){''Blend Settings''};
--''Example''
#br
//_BLEND_SRC_COLOR(one);
//_BLEND_DST_COLOR(one);
//_BLEND_SRC_ALPHA(one);
//_BLEND_DST_ALPHA(one);
--''Description''
Specifies the blending method when blending is enabled.
SRCCOLOR/DSTCOLOR sets the color weighting SRCALPHA/DSTAL...
---''zero''
---''one''
---''srccolor''
---''rsrccolor''
---''dstcolor''
---''rdstcolor''
---''srcalpha''
---''rsrcalpha''
---''dstalpha''
---''rdstalpha''
#br
You can choose from the above.
#br
#br
-&size(16){''Color Write''};
--''Example''
@//_COLOR_WRITE(true true true true)
--''Description''
Configure whether to write to each RGBA channel.
If not declared, writing occurs to all channels.
#br
#br
#br
#br
-&size(16){''Depth Test''};
--''Example''
//_DEPTH_TEST(false)
--''Description''
Sets whether or not to use depth testing on the main pass.
#br
#br
-&size(16){''Depth Write''};
--''Example''
//_DEPTH_WRITE(true)
--''Description''
Sets whether or not the depth is written in the main pass.
#br
#br
-&size(16){''Stencil Ref''};
--''Example''
//_STENCIL_REF(1)
--''Description''
Sets the reference value for the stencil test for the mai...
#br
#br
-&size(16){''Stencil Mask''};
--''Example''
//_STENCIL_MASK(1)
--''Description''
Sets the stencil test mask value for the main pass.
#br
#br
-&size(16){''Stencil Test''};
--''Example''
//_STEINCIL_ENABLE(true)
--''Description''
Specifies whether stencil testing is enabled on the main ...
#br
#br
-&size(16){''Stencil Op''};
--''Example''
//_STENCIL_OPPASS()
//_STENCIL_OPDEPTHFAIL()
//_STENCIL_OPFAIL()
--''Description''
Sets how the stencil value will be used in the test resul...
---''keep''
---''replace'': Replace by Ref value
---''inc'': Increase by 1
---''dec'': Decrease by 1
#br
You can choose from the above.
#br
#br
-&size(16){''Test Func''};
--''Example''
//_DEPTH_FUNC(lequal)
//_STENCIL_FUNC(noteqal)
--''Description''
You can specify acceptable/failure types for the main pas...
---''never'': Always failed.
---''less'': If less than, then acceptable.
---''equal'': If equal, then acceptable.
---''lequal'': If less than or equal to, then acceptable.
---''greater'': If greater than, then acceptable.
---''notequal'': If not equal, then acceptable.
---''gequal'': If greater than or equal to, then acceptab...
---''always'': Always acceptable.
#br
You can choose from the above.
#br
#br
-&size(16){''Dither Translucent''};
--''Example''
@//_DITHER_TRANSLUCENT(false)
--''Description''
Disable the use of dithered transparency in opaque path s...
#br
#br
-&size(16){''Skin''};
--''Example''
@//_SKIN(false)
--''Description''
Declare that skinning (bone-based deformation) is not per...
Include this declaration whenever possible to reduce shad...
#br
#br
-&size(16){''Morph''};
--''Example''
@//_MORPH(false)
--''Description''
Declare that no morphing (shape animation) will be perfor...
Include this declaration whenever possible to reduce shad...
#br
#br
-&size(16){''ZPrepass''};
--''Example''
@//_ZPREPASS(false)
--''Description''
Disable rendering to the Z-prepass in the opaque path sha...
#br
#br
-&size(16){''Forward Fog''};
--''Example''
@//_FORWARD_FOG(true)
--''Description''
Add fog effects to the rendering of translucent paths.
#br
#br
-&size(16){''Outline Pass''};
--''Example''
@//_NO_OUTLINE_PASS(true)
--''Description''
Disable the generation of outline rendering shaders.
#br
#br
-&size(16){''Hidden Area Pass''};
--''Example''
@//_NO_HIDDEN_AREA_PASS(true)
--''Description''
Disable shader generation for rendering player character ...
#br
#br
-&size(16){''Cast Shadow''};
--''Example''
@//_CAST_SHADOW(false)
--''Description''
Disable shadow rendering.
**Parameters (Uniform) [#v231a222]
This section explains the parameters that are passed from...
-&size(16){''SYSTEMCOMMONBLOCK''};
--''Description''
It contains information about the scene.
Data can be accessed with its variable name.
#br
vec3 eyePosition; //Camera position
vec3 eyeDirection; //Camera orientation (-Z)
mat4 projToWorld; //Projection to World matrix
mat4 worldToProj; //World to Projection matrix
mat4 projToView; //Projection To View(Camera) matrix
mat4 viewToProj; //View(Camera) To Projection matrix
mat4 worldToView; //World To View matrix
float drawTime; //Elapsed time (sec)
int drawCount; //Number of elapsed frames
float reflectionIntensity; //Environment Map Intensity
float reflectionMipCount; //Number of environment map m...
float IBLMipIndex; //Environment map mipmap index for...
float IBLIntensity; //IBL Intensity
vec4 fogColor; //fog(See editor's Rendering Settings)
float fogStart;
float fogDepthDensity;
float fogHeightFallOff;
vec2 _3DScreenSize; //Viewport size for 3D rendering
vec2 _3DScreenScale; //Scale to frame buffer during 3D...
vec2 _DefaultSurfaceSize; //Frame buffer size for 3D re...
vec2 _GameViewScreenSize; //Game Resolution
mat4 shadowMatrix[4]; //Shadow Matrix
int cascadeCount; //Shadow cascade count
float cascadeVisualize; //For Development
float shadowBias; //Shadow Bias
float shadowDistance; //Shadow effective distance
float shadowmapScale; //Dynamic resolution of shadow map
//One Directional(With Shadow)
vec3 directionalLightDir; //Parallel light source dire...
vec3 directionalLightColor; //Parallel light source co...
vec3 directionalLightShadowColor; //Unused
//Ambient
vec3 ambientLightColor; //Ambient light color
float buildingLightBrightness; //Brightness of b...
float ssrScale; //Unused
float billboardLightModulation; //Billboard Light Inte...
vec4 hiddenAreaColor; //Color of Hidden Area
float distanceFadeBias; //Distance Fade Parameter
float distanceFadeStart;
float distanceFadeNearClip;
//
float deltaTime; //Elapsed time from previous frame
#br
#br
-&size(16){''SYSTEMMATERIALBLOCK''};
#br
Material parameters assigned by the system.
Accessed by SVAL(name) macro.
SVAL(emissionMultiply)
The above and more.
#br
int localLightCount; //Number of allocated local lig...
int localLightIndex[LOCALLIGHTASSIGNLIMIT]; //Index of ...
float emissionMultiply; //Emissive Strength
float opacityMultiplier; //Opacity Strength
vec4 overrideColor; //Override Color
float outlineWidth; //Outline Width
vec4 outlineColor; //Outline Color
float pickupID; //ID for the editor
float distanceFadeBias; //Distance fade bias
float buildingLightMask; //Whether it is affected by...
vec2 uvofs; //Built-in UV Offset
vec2 uvscl; //Built-in UV Scale
mat3x4 localToWorldMatrix; //local to world matrix (typ...
mat3x4 worldToLocalMatrix; //world to local matrix (typ...
mat3x4 localToWorldAxis; //local to world matrix (ty...
mat3x4 worldToLocalAxis; //world to local matrix (ty...
#br
#br
-&size(16){''LOCALLIGHTLISTBLOCK''};
#br
Local light information is stored in an array.
You can find the index of the array based on the localLig...
#br
struct LocalLight{
int type; //Light Type
float radius; //Radius
float specularScale; //Specular strength
vec3 color; //Color
vec3 position; //Position
float innerAngle; //Internal angle of spotlight
vec3 direction; //Spotlight Direction
float outerAngle; //External angle of spotlight
};
LocalLight _localLights[LOCAL_LIGHT_BLOCK_ARRAYSIZE];
#br
#br
-&size(16){''USERMATERIAL''};
#br
A parameter declared in the shader, accessed using the UV...
//DECL_COLOR3(color)
If you declare something like above,
vec3 tmp = UVAL(color);
can be used.
**Compile Condition [#s7714dfd]
-&size(16){''Vertex Shader''};
FLAG_VP is defined during compilation.
#br
#ifdef FLAG_VP
/*Describe vertex shader*/
#endif
#br
If you bundle as above, that part will be enabled when co...
#br
#br
-&size(16){''Fragment Shader''};
FLAG_FP is defined during compilation.
#br
#ifdef FLAG_FP
/*Describe fragment shader*/
#endif
If you bundle as above, that part will be enabled when co...
#br
#br
-&size(16){''Pass''};
Bakin creates several passages from a single shader.
#br
--''Main'' The pass for normal rendering.
--''Shadow'' The pass for rendering shadows.
--''Outline'' The pass for rendering outlines.
--''Pickup'' This is the pass used to test mouse hits in ...
--''HiddenArea'' The pass is used to render the area that...
#br
Each is defined at compilation time as follows:
#br
--Main : _MAIN_PASS_COMPILE
--Shadow : _SHADOW_PASS_COMPILE
--Outline : _OUTLINE_PASS_COMPILE
--Pickup : _PICKUP_PASS_COMPILE
--HiddenArea : _HIDDEN_AREA_PASS_COMPILE
#br
For example, the Shadow pass is as follows:
#br
#ifdef _SHADOW_PASS_COMPILE
/*Description for shadow pass case*/
#endif
#br
You can describe the behavior of the Shadow pass by bundl...
#br
''If a pass other than Main is not described, a common so...
''If you want to describe a pass, declare _CUSTOM_PASS an...
#br
As an example of describing multiple passes, refer to the...
#br
#ifdef FLAG_VP
#ifdef _SHADOW_PASS_COMPILE
VertexOutStruct usermain(VertexInStruct vin)
{
/*Vertex shader code for shadow pass*/
}
#endif
#ifdef _MAIN_PASS_COMPILE
VertexOutStruct usermain(VertexInStruct vin)
{
/*Vertex shader code for the main pass*/
}
#endif
#endif
#br
**User Main Functions [#f9edf0bb]
''The main functions of vertex shader and fragment shader...
-&size(16){''Vertex Shader''};
Input is done with a structure called VertexInStruct and ...
例
#br
VertexOutStruct usermain(VertexInStruct vin)
{
VertexOutStruct vout
vout.position = calcPositionWorldToScreen(calcPositionL...
vout.texCoord0.xy = vin.uv0.xy;
return vout;
}
#br
#br
-&size(16){''Fragment Shader''};
FragmentInStruct is used for input.
#br
For opaque rendering, returns PBRMaterialResult and the c...
例
#br
PBRMaterialResult usermain(FragmentInStruct fin)
{
vec4 t = SAMPLING2D( AMap, fin.texCoord0.xy );
if(t.w < UVAL(discard_threshold))discard;
vec4 nt = SAMPLING2D( NMap, fin.texCoord0.xy );
nt.xyz = decompressNormal(nt.xy);
vec3 n = nt.y * fin.binormal * UVAL(normalscl) + nt.x *...
vec4 rmt = SAMPLING2D( RMMap, fin.texCoord0.xy );
PBRMaterialResult fout;
fout.baseColor = t.xyz * fin.color.xyz * UVAL(color);
fout.normal = normalize(n.xyz);
fout.roughness = rmt.g * UVAL(roughness);
fout.metallic = rmt.b * UVAL(metallic);
fout.specular= rmt.a * UVAL(specular);
fout.emissiveColor = UVAL(emissive_color) * rmt.r * UVA...
fout.worldPosition = CalcWorldPosition();
fout.opacity = 1.0f;
fout.sssColor = vec4(0,0,0,0);
return fout;
}
#br
The members of PBRMaterialResult are as follows:
#br
--''baseColor''
--''normal''
--''roughness''
--''metallic''
--''specular''
--''emissiveColor''
--''worldPosition'': World coordinate system position
--''opacity'': Used for dither translucent processing
--''sssColor'': SSS color and applicability
#br
Otherwise, Unlit and Translucent return vec4 colors.
Example:
#br
vec4 usermain(FragmentInStruct fin)
{
return SAMPLING2D( DifMap, fin.texCoord0.xy ) * fin.col...
}
**Function [#oceb0148]
-&size(16){''Matrix''};
For compatibility, please use the mul macro for matrix mu...
-&size(16){''Samplers''};
Samplers should use the following macros for compatibility.
#br
--''SAMPLING2D(name, uv)'': 2D texture sampling, uv is vec2
--''SAMPLING2DLOD(name, uv)'': LOD sampling of 2D texture...
--''SAMPLING3D(name, uvw)'': 3D texture sampling, uvw is ...
--''SAMPLING3DLOD(name, uvw)'': LOD sampling of 3D textur...
--''SAMPLINGCUBE(name, uv)'': Cube map sampling, uv is ve...
--''SAMPLINGCUBELOD(name, uv)'': Cube map sampling, uv is...
#br
#br
-&size(16){''Vertex Shader Functions''};
--''World Position''
vec3 calcPositionLocalToWorld(vec3 vtx)
--- ''Description''
Passing a world vertex position vtx returns vec3 converte...
--''View Position''
vec3 calcPositionWorldToView(vec3 vtx)
--- ''Description''
Passing a world vertex position vtx returns vec3 converte...
--''Screen Position''
vec4 calcPositionWorldToScreen(vec3 vtx)
--- ''Description''
Passing a world vertex vtx returns vec4 in the clipping c...
--''Screen Position 2''
vec4 calcPositionViewToScreen(vec3 vtx)
--- ''Description''
Passing view vertex vtx returns vec4 in the clipping coor...
--''World Normal Calculation''
vec3 calcNormalLocalToWorld(vec3 normal)
--- ''Description''
Passing a local normal will convert it to a world normal ...
--''World Tangent Calculation''
vec4 calcTangentLocalToWorld(vec4 tangent)
--- ''Description''
Passing a local tangent is converted to a world tangent a...
--''Binormal Calculation''
vec3 calcBinormal(vec3 normal, vec4 tangent)
--- ''Description''
Finds binormal from the outer product of the normal and t...
--''Outline Calculation''
vec calcOutlineVertex(vec3 vtx, vec3 normal)
--- ''Description''
Returns the position of the vertex after translating it a...
--''World Matrix''
vec3 getLocalToWorldMatrix()
--- ''Description''
Returns the matrix for transforming a model's vertices fr...
--''Outline Width''
@float getOutlineWidth()
--- ''Description''
Returns the width of the outline set in the material.
#br
#br
-&size(16){''Fragment Shader Functions''};
--''World Position''
vec3 CalcWorldPosition()
--- ''Description''
Converts from the current fragment position to world coor...
--''View Coordinate Position''
vec3 CalcViewPosition()
--- ''Description''
Converts from the current fragment position to the coordi...
--''Directional Light Brightness''
float directionalLightAttenuation(vec3 wposition)
--- ''Description''
Obtains the state of hiding by shadow of a directional li...
--''Local Light Brightness''
float localLightAttenuation(int index, vec3 wposition)
--- ''Description''
Obtains the influence of a local light.
--''Number of Local Lights''
int getLocalLightCount()
--- ''Description''
Returns the number of local lights.
--''Local Light Position''
vec3 getLocalLightPosition(int index)
--- ''Description''
Returns the position of the index-th local light.
--''Local Light Color''
getLocalLightColor(int index)
--- ''Description''
Returns the color of the index-th local light.
--''Fog Calculation''
vec4 calcFog(vec3 wposition)
--- ''Description''
Calculates fog for a specified world position.
--''Environment Map''
vec3 GetReflectionImg(vec3 wposition, vec3 normal, float...
--- ''Description''
Returns the environment map at the specified position and...
Specify the MipMap level derived from roughness and other...
The maximum MipMap level for the environment map can be o...
--''IBL''
vec3 GetIBL( vec3 normal, float level)
--- ''Description''
Returns the IBL for the specified normal direction. The I...
level specifies the MipMap level of the environment map (...
--''Outline Color''
vec4 fpGetOutlineColor()
--- ''Description''
Returns the outline color considering linear lighting.
--''PBR Lighting''
PBRLightingResult PbrSSSWithWorldPosition(vec3 albedo, v...
--- ''Description''
Providing PBR parameters returns the lighting result.
--''Unlit''
vec4 Unlit(vec3 emissive, float opacity, vec3 worldPosit...
--- ''Description''
Performs the necessary calculations for Unlit materials a...
--''Unlit with Reflection''
vec4 UnlitWithReflection(vec3 albedo, vec3 normal, vec3 ...
--- ''Description''
Returns a color that reflects the environment map without...
--''Translucent''
void Translucent(vec4 value, vec3 worldPosition)
--- ''Description''
Returns a color for translucent rendering, taking fog and...
Page: