Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
default-material [2019/04/08 08:33] – [Globally available variables] admin | default-material [2020/01/17 11:30] – [Globally available variables] admin | ||
---|---|---|---|
Line 54: | Line 54: | ||
| TGorillaGLSLUniformsNode | Create this node, if you need additional input variables in your shader | | | TGorillaGLSLUniformsNode | Create this node, if you need additional input variables in your shader | | ||
| TGorillaGLSLLocalsNode | Holds the local variables defined at the beginning of the main() function | | | TGorillaGLSLLocalsNode | Holds the local variables defined at the beginning of the main() function | | ||
- | | TGorillaGLSLAttributesNode | Holds the available vertex attributes. It is not recommend to change this node, if you are not sure if the additional attributes are provided by the mesh data. **a_Position**, | + | | TGorillaGLSLAttributesNode | Holds the available vertex attributes. It is not recommend to change this node, if you are not sure if the additional attributes are provided by the mesh data. **a_Position**, |
| TGorillaGLSLInOutNode | Holds the input/ | | TGorillaGLSLInOutNode | Holds the input/ | ||
| TGorillaGLSLTextureUniformNode | You don't have to instanciate this type of node, simply use DoAddBitmapToPool() function provided by the material class. Internal available texture uniforms: **_Texture0**, | | TGorillaGLSLTextureUniformNode | You don't have to instanciate this type of node, simply use DoAddBitmapToPool() function provided by the material class. Internal available texture uniforms: **_Texture0**, | ||
Line 76: | Line 76: | ||
| GORILLA_GLSL_DEFINE_DEPTH | Activates the depth map functionality. Nevertheless a depth render pass needs to be attached to the material | | | GORILLA_GLSL_DEFINE_DEPTH | Activates the depth map functionality. Nevertheless a depth render pass needs to be attached to the material | | ||
| GORILLA_GLSL_DEFINE_SHADOW | Activates shadow casting. The GORILLA_GLSL_DEFINE_DEPTH needs to be activated too. | | | GORILLA_GLSL_DEFINE_SHADOW | Activates shadow casting. The GORILLA_GLSL_DEFINE_DEPTH needs to be activated too. | | ||
- | | GORILLA_GLSL_DEFINE_RAYTRACING | + | | GORILLA_GLSL_DEFINE_SHADOW_SM |
+ | | GORILLA_GLSL_DEFINE_SHADOW_VSM | Activates variance shadow mapping. The GORILLA_GLSL_DEFINE_SHADOW needs to be activated too. | | ||
+ | | GORILLA_GLSL_DEFINE_SHADOW_FT | Activates faketracing shadow casting. The GORILLA_GLSL_DEFINE_SHADOW needs to be activated too. | | ||
| GORILLA_GLSL_DEFINE_REFLECTION | Activates reflection handling. | | | GORILLA_GLSL_DEFINE_REFLECTION | Activates reflection handling. | | ||
| GORILLA_GLSL_DEFINE_REFRACTION | Activates refraction handling. | | | GORILLA_GLSL_DEFINE_REFRACTION | Activates refraction handling. | | ||
+ | | GORILLA_GLSL_DEFINE_CLIPPINGPLANE | Activates clipping plane handling. | | ||
| GORILLA_GLSL_DEFINE_NORMALMAP | Activates normal mapping functionality. | | | GORILLA_GLSL_DEFINE_NORMALMAP | Activates normal mapping functionality. | | ||
| GORILLA_GLSL_DEFINE_BUMP | Activates bump mapping functionality in combination with GORILLA_GLSL_DEFINE_NORMALMAP | | | GORILLA_GLSL_DEFINE_BUMP | Activates bump mapping functionality in combination with GORILLA_GLSL_DEFINE_NORMALMAP | | ||
Line 85: | Line 88: | ||
| GORILLA_GLSL_DEFINE_LIGHTING | Enables lighting computation with lambert, phong or blinnphong algorithm. | | | GORILLA_GLSL_DEFINE_LIGHTING | Enables lighting computation with lambert, phong or blinnphong algorithm. | | ||
| GORILLA_GLSL_DEFINE_USE_SPECULAR | Enables specular light computation. | | | GORILLA_GLSL_DEFINE_USE_SPECULAR | Enables specular light computation. | | ||
- | | GORILLA_GLSL_DEFINE_USE_COLOR | + | | GORILLA_GLSL_DEFINE_USE_VERTEXCOLOR |
- | | GORILLA_GLSL_DEFINE_USE_TEXTURE | Enables the Texture0 handling in the material | | + | | GORILLA_GLSL_DEFINE_USE_TEXTURE |
+ | | GORILLA_GLSL_DEFINE_USE_TEXTURE0 | ||
| GORILLA_GLSL_DEFINE_USE_TEXTURE_ATLAS | Declares texture atlas mapping functionality. | | | GORILLA_GLSL_DEFINE_USE_TEXTURE_ATLAS | Declares texture atlas mapping functionality. | | ||
| GORILLA_GLSL_DEFINE_USE_POINTSPRITE | In combination with GORILLA_GLSL_DEFINE_USE_TEXTURE_ATLAS the Texture0 will be used as atlas and mapped onto each vertex point. | | | GORILLA_GLSL_DEFINE_USE_POINTSPRITE | In combination with GORILLA_GLSL_DEFINE_USE_TEXTURE_ATLAS the Texture0 will be used as atlas and mapped onto each vertex point. | | ||
+ | | GORILLA_GLSL_DEFINE_PACKED_NORMAL | Enables packed normals | | ||
+ | | GORILLA_GLSL_DEFINE_INOUTVARS | Enables in/out variables for GLSLv3+ | | ||
+ | | GORILLA_GLSL_DEFINE_VARYINGSTRUCTS | Enables varying structs. This define manages backwards compatibility | | ||
+ | | GORILLA_GLSL_DEFINE_DEPRECATED | Enables OpenGL es v2 support. This define manages backwards compatibility | | ||
+ | | GORILLA_GLSL_DEFINE_INTEL | Automatically set by the system, in case of an Intel graphics card. | | ||
+ | | GORILLA_GLSL_DEFINE_AMD | Automatically set by the system, in case of an AMD graphics card. | | ||
+ | | GORILLA_GLSL_DEFINE_NVIDIA | Automatically set by the system, in case of an NVidia graphics card. | | ||
+ | | GORILLA_GLSL_DEFINE_GEFORCE | Automatically set by the system, in case of an GeForce graphics card. | | ||
+ | | GORILLA_GLSL_DEFINE_RADEON | Automatically set by the system, in case of an Radeon graphics card. | | ||
+ | | GORILLA_GLSL_DEFINE_HDGRAPHICS | Automatically set by the system, in case of an HDGraphics graphics card. | | ||
To enable a shader section call: | To enable a shader section call: | ||
Line 101: | Line 115: | ||
^ Shader ^ Defines ^ | ^ Shader ^ Defines ^ | ||
- | | VertexShader | GORILLA_GLSL_DEFINE_VERTEXSHADER | | + | | VertexShader | GORILLA_GLSL_DEFINE_VERTEXSHADER, GORILLA_GLSL_DEFINE_CLIPPINGPLANE |
- | | FragmentShader | GORILLA_GLSL_DEFINE_FRAGMENTSHADER, | + | | FragmentShader | GORILLA_GLSL_DEFINE_FRAGMENTSHADER, |
===== Extending the default material ===== | ===== Extending the default material ===== | ||
Line 324: | Line 338: | ||
| a_Binormal | TPoint3D | vec3 | | | a_Binormal | TPoint3D | vec3 | | ||
| a_TexCoord0 | TPointF | vec2 | | | a_TexCoord0 | TPointF | vec2 | | ||
- | | a_Color0 | + | | a_TexCoord1 | TPointF | vec2 | |
+ | | a_TexCoord2 | TPointF | vec2 | | ||
+ | | a_TexCoord3 | TPointF | vec2 | | ||
+ | | a_Color | ||
+ | | a_Color1 | TAlphaColorF | vec4 | | ||
+ | | a_Color2 | TAlphaColorF | vec4 | | ||
+ | | a_Color3 | TAlphaColorF | vec4 | | ||
+ | |||
+ | === Uniform Buffer === | ||
+ | |||
+ | **Only available in GLES v3!** | ||
+ | |||
+ | ^ Name ^ Delphi-Type ^ GLSL-Type ^ Description ^ | ||
+ | | _ModelViewMatrix | TMatrix3D | mat4 | model matrix with translation, | ||
+ | | _ModelViewProjectionMatrix | TMatrix3D | mat4 | model * view * projection multiplied matrix | | ||
+ | | _ModelNormalMatrix | TMatrix3D | mat4 | inverse transposed model * view multiplied matrix | | ||
+ | | _ViewMatrix | TMatrix3D | mat4 | view / camera matrix | | ||
+ | | _ProjectionMatrix | TMatrix3D | mat4 | projection matrix | | ||
+ | | _ShadowMatrix | TMatrix3D | mat4 | shadow mapping matrix | | ||
+ | | _TimeInfo | TVector3D | vec4 | x = starting time, y = current time, z = previous time, w = delta time | | ||
+ | | _ViewDir | TPoint3D | vec3 | camera view direction | | ||
+ | | _ShadingModel | FixedInt | int | used shading model: 0 = lambert, 1 = phong, 2 = blinnphong | | ||
+ | | _Material[0] | TGorillaShaderMaterial | struct Material | material values | | ||
+ | | _Lights[x] | Array of TGorillaShaderLight | struct Lights[...] | light values | | ||
+ | | _LightsCount | FixedInt | int | number of available lights in lights-array | | ||
+ | | _BoundaryMin | TVector3D | vec4 | 3D minimum corner of scene bounds | | ||
+ | | _BoundaryMax | TVector3D | vec4 | 3D maximum corner of scene bounds | | ||
+ | | _ViewSize | TVector3D | vec4 | viewport resolution (X, Y) and near / far values (Z, W) | | ||
+ | | _PassData[0] | TGorillaShaderPassData | struct PassData | pass information values | ||
=== Varying values in fragment shader === | === Varying values in fragment shader === | ||
Line 334: | Line 376: | ||
| vars.v_TexCoord0 | TPointF | vec2 | vertex texture coordinate for first texture | | | vars.v_TexCoord0 | TPointF | vec2 | vertex texture coordinate for first texture | | ||
| vars.v_Color0 | TAlphaColorF | vec4 | first vertex color information (may be black if not provided) | | | vars.v_Color0 | TAlphaColorF | vec4 | first vertex color information (may be black if not provided) | | ||
- | | vars.v_EyeVertPos | TVector3D | vec4 | model view space transformed vertex position | | + | | vars.v_EyeVertPos | TVector3D | vec4 | modelmatrix |
| vars.v_ReflProjTextureCoords | TVector3D | vec4 | when reflection is active, these are the transformed coordinates for reflection texture | | | vars.v_ReflProjTextureCoords | TVector3D | vec4 | when reflection is active, these are the transformed coordinates for reflection texture | | ||
| vars.v_RefrProjTextureCoords | TVector3D | vec4 | when refraction is active, these are the transformed coordinates for refraction texture | | | vars.v_RefrProjTextureCoords | TVector3D | vec4 | when refraction is active, these are the transformed coordinates for refraction texture | | ||
Line 361: | Line 403: | ||
=== Available Textures === | === Available Textures === | ||
^ Name ^ GLSL-Type ^ Description ^ | ^ Name ^ GLSL-Type ^ Description ^ | ||
- | | _Texture0 | sampler2D | If USE_TEXTURE | + | | _Texture0 | sampler2D | If GORILLA_GLSL_DEFINE_USE_TEXTURE |
| _NormalMapTexture | sampler2D | If GORILLA_GLSL_DEFINE_NORMALMAP is activated. | | | _NormalMapTexture | sampler2D | If GORILLA_GLSL_DEFINE_NORMALMAP is activated. | | ||
- | | _SpecularMapTexture | sampler2D | If USE_SPECULAR | + | | _SpecularMapTexture | sampler2D | If GORILLA_GLSL_DEFINE_USE_SPECULAR |
- | | _DepthTexture | sampler2D | If DEPTH is activated. | | + | | _DepthTexture | sampler2D | If GORILLA_GLSL_DEFINE_DEPTH |
- | | _DisplacementMapTexture | sampler2D | If DISPLACEMENT | + | | _DisplacementMapTexture | sampler2D | If GORILLA_GLSL_DEFINE_DISPLACEMENT |
- | | _ReflectionTexture | sampler2D | If REFLECTION | + | | _ReflectionTexture | sampler2D | If GORILLA_GLSL_DEFINE_REFLECTION |
- | | _RefractionTexture | sampler2D | If REFRACTION | + | | _RefractionTexture | sampler2D | If GORILLA_GLSL_DEFINE_REFRACTION |
+ | | _GeometryTexture0, | ||
+ | |||
+ | === Shader Locals === | ||
+ | |||
+ | == VertexShader == | ||
+ | ^Name ^Type ^Shader ^Description ^ | ||
+ | | l_Position | vec4 | VS | MVP transformed vertex position | | ||
+ | | l_Displace | vec3 | VS | Raw disposition value from displacement map. Use TGorillaGLSLDisplacementMappingGetNode and TGorillaGLSLDisplacementMappingApplyNode to manipulate displacement | | ||
+ | |||
+ | == FragmentShader == | ||
+ | ^Name ^Type ^Shader ^Description ^ | ||
+ | | l_Ambient| vec3 | FS | Ambient light color (only in lights loop) | | ||
+ | | l_Diffuse| vec3 | FS | Diffuse light color (only in lights loop) | | ||
+ | | l_Specular | vec3 | FS | Specular light color (only in lights loop) | | ||
+ | | l_SpecularColor | vec3 | FS | Specular material color (from texture or computed) | | ||
+ | | l_TexCoord0 | vec2 | FS | transformed and tiled first texture coordinate | | ||
+ | | l_Tiling0 | vec2 | FS | Tiling information for texture 0. | | ||
+ | | l_Shading | vec2 | FS | Multiple light combined value | | ||
+ | | l_LightDir | vec4 | FS | Direction of light (only in lights loop) | | ||
+ | | l_LightVec | vec3 | FS | Light vector (only in lights loop) | | ||
+ | | l_LightType | int | FS | Type of light (point, direction or spot light) (only in lights loop) | | ||
+ | | l_LightDist | float | FS | Distance to light source | ||
+ | | l_Attenuation | float | FS | Computed light attenuation (only in lights loop) | | ||
+ | | l_BumpSum | vec2 | FS | Bump-Mapping for each light source | | ||
+ | | l_BaseColor | vec4 | FS | Diffuse texture color / vertex color / computed color | | ||
+ | | l_Alpha | float | FS | Final alpha output value - combine with l_SumColor | | ||
+ | | l_SumColor | vec3 | FS | Final RGB output value - combine with l_Alpha | | ||
+ | |||
+ | ===== Properties ===== | ||
+ | |||
+ | Default material component provides a few easy-to-use properties for automatic defines settings. By using the following properties in your default material, you can setup the necessary defines, your shaders need for computation. | ||
+ | |||
+ | ^Property^Description^ | ||
+ | | UseLighting | Enable or disable lighting shading model computation in shader | | ||
+ | | UseTexturing | Enable or disable texturing functionality (using tex2D and tex2DProj in shader) | | ||
+ | | UseTexture0 | Enable or disable " | ||
+ | | UseVertexColor | Enable or disable to use vertex color rendering. | | ||
+ | |||
+ | <file pascal> | ||
+ | constructor TMyMaterial.Create(const ASource : TGorillaDefaultMaterialSource); | ||
+ | begin | ||
+ | inherited; | ||
+ | |||
+ | UseTexturing := true; | ||
+ | UseTexture0 := true; | ||
+ | UseLighting := true; | ||
+ | UseVertexColor := false; | ||
+ | end; | ||
+ | </ |