Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
0.8.4:default-material [2022/06/21 21:16] – [Register a texture variable] admin | 0.8.4:default-material [2023/01/31 14:07] (current) – [Changing Shaders at DesignTime] admin | ||
---|---|---|---|
Line 149: | Line 149: | ||
- <6> [TGorillaGLSLSurfaceShaderExec] | - <6> [TGorillaGLSLSurfaceShaderExec] | ||
- <7> [TGorillaGLSLMergedColorOutputNode] | - <7> [TGorillaGLSLMergedColorOutputNode] | ||
- | - <8> [TGorillaGLSLFragColorOutputNode] | + | - <8> [TGorillaGLSLBrightnessColorNode] |
- | - <9> [TGorillaGLSLColorClipNode] | + | - <9> [TGorillaGLSLFragColorOutputNode] |
- | - <10> [TGorillaGLSLFogApplyNode] | + | - <10> [TGorillaGLSLColorClipNode] |
- | - <11> [TGorillaGLSLWeightedBlendedOITNode] | + | - <11> [TGorillaGLSLFogApplyNode] |
+ | - <12> [TGorillaGLSLWeightedBlendedOITNode] | ||
</ | </ | ||
===== Node Classes ===== | ===== Node Classes ===== | ||
Line 303: | Line 304: | ||
* **tex2D()** | * **tex2D()** | ||
* **tex2DProj()** | * **tex2DProj()** | ||
- | * **tex3d()** | + | * **tex3D()** |
* **texCube()** | * **texCube()** | ||
* **Texture_GetNormal()** | * **Texture_GetNormal()** | ||
Line 402: | Line 403: | ||
| SurfaceShader | TGorillaGLSLSurfaceShaderExec| Calls **SurfaceShader(LOCALS); | | SurfaceShader | TGorillaGLSLSurfaceShaderExec| Calls **SurfaceShader(LOCALS); | ||
| SurfaceShader | TGorillaGLSLMergedColorOutputNode |It will compute the final **LOCALS.SumColor** depending if GORILLA_GLSL_DEFINE_LIGHTING, | | SurfaceShader | TGorillaGLSLMergedColorOutputNode |It will compute the final **LOCALS.SumColor** depending if GORILLA_GLSL_DEFINE_LIGHTING, | ||
+ | | SurfaceShader | TGorillaGLSLBrightnessColorNode | It will multiply **_Brightness** value with **LOCALS.SumColor** (since v0.8.4.2322)| | ||
| SurfaceShader | TGorillaGLSLFragColorOutputNode | It will apply material alpha value to **LOCALS.Alpha** and finally write **vec4(LOCALS.SumColor, | | SurfaceShader | TGorillaGLSLFragColorOutputNode | It will apply material alpha value to **LOCALS.Alpha** and finally write **vec4(LOCALS.SumColor, | ||
| SurfaceShader | TGorillaGLSLColorClipNode | If GORILLA_GLSL_DEFINE_USE_COLORCLIP is activated, it will discard the fragment if threshold was reached. | | | SurfaceShader | TGorillaGLSLColorClipNode | If GORILLA_GLSL_DEFINE_USE_COLORCLIP is activated, it will discard the fragment if threshold was reached. | | ||
Line 585: | Line 587: | ||
/// </ | /// </ | ||
Options : FixedInt; | Options : FixedInt; | ||
+ | | ||
+ | /// < | ||
+ | /// Defines how much shading is applied to diffuse and specular color. | ||
+ | /// </ | ||
+ | ShadingIntensity : Single; | ||
+ | /// < | ||
+ | /// Defines the brightness factor applied to the diffuse color. | ||
+ | /// </ | ||
+ | Brightness : Single; | ||
/// < | /// < | ||
Line 603: | Line 614: | ||
/// </ | /// </ | ||
FogEnd : Single; // default = 500.0 | FogEnd : Single; // default = 500.0 | ||
- | |||
- | /// < | ||
- | /// Due to memory alignment in GPU we need to adjust bytes here. | ||
- | /// It is important to use the untyped array of byte. | ||
- | /// </ | ||
- | Reserved0 : Array[0..7] of Byte; | ||
- | |||
/// < | /// < | ||
/// Define the fog color used for computation. | /// Define the fog color used for computation. | ||
Line 1151: | Line 1155: | ||
Registering textures in shader is a little but different, but quite easy. | Registering textures in shader is a little but different, but quite easy. | ||
- | Because the default material manages a pool of textures, we simply | + | Because the default material manages a pool of textures, we only have to add a texture to it, and the component will do the rest for us. |
Working further with our // | Working further with our // | ||
Line 1292: | Line 1296: | ||
==== Calling an individual functions ==== | ==== Calling an individual functions ==== | ||
- | After we declared our user specific function, we want to call it in the shader. | + | After we' |
- | For that we do again need a new node type. | + | For that we need a new node. Here the basic class //TGorillaNodeEntity// is quite perfect for the job. |
- | Here the easiest | + | |
Afterwards we have to attach the node to the node-builder again. | Afterwards we have to attach the node to the node-builder again. | ||
Line 1300: | Line 1303: | ||
In our example we've written a function that returns the current texture color. | In our example we've written a function that returns the current texture color. | ||
- | This is called base-color. The default shader declares a local variable "l_BaseColor" for that. | + | This is called base-color. The default shader declares a local variable "LOCALS.BaseColor" for that. |
If we set this, it will automatically be used in the color-light-summary. | If we set this, it will automatically be used in the color-light-summary. | ||
Line 1306: | Line 1309: | ||
" | " | ||
- | __Caution: | + | __Caution: |
<file pascal> | <file pascal> | ||
Line 1343: | Line 1346: | ||
+ | ==== Changing Shaders at DesignTime ==== | ||
+ | Since 0.8.4 it's possible to modify your default shader at designtime, by using published properties *VertexShader* or *SurfaceShader*. | ||
+ | |||
+ | Simply select your default material source, go to object inspector and open the text editor of the property. An empty GLSL function should be visible depending on the shader used. | ||
+ | |||
+ | For VertexShader: | ||
+ | <file glsl> | ||
+ | void VertexShader(inout TLocals DATA){ | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | For SurfaceShader (Fragment/ | ||
+ | <file glsl> | ||
+ | void SurfaceShader(inout TLocals DATA){ | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can then modify or extend the shader functionality. | ||
+ | Please have a look a the section [[# | ||
+ | |||
+ | **NOTICE:** //Modifying the vertex position in vertex-shader all 3 fields " | ||
+ | |||
+ | In the following example we've created a wobbling effect in the vertex shader: | ||
+ | |||
+ | <file glsl> | ||
+ | vec2 DELPHI_HASH2(vec2 n){ | ||
+ | return fract(sin(n)*1399763.5453123); | ||
+ | } | ||
+ | |||
+ | float DELPHI_NOISE(vec2 st){ | ||
+ | vec2 i = floor(st); | ||
+ | vec2 f = fract(st); | ||
+ | |||
+ | vec2 u = f * f * (3.0 - 2.0 * f); | ||
+ | |||
+ | float a = dot(DELPHI_HASH2(i + vec2(0.0, | ||
+ | float b = dot(DELPHI_HASH2(i + vec2(1.0, | ||
+ | float c = dot(DELPHI_HASH2(i + vec2(0.0, | ||
+ | float d = dot(DELPHI_HASH2(i + vec2(1.0, | ||
+ | |||
+ | return mix(mix(a, b, u.x), mix(c, d, u.x), u.y); | ||
+ | } | ||
+ | |||
+ | vec3 DELPHI_WOBBLE(vec3 pos, float time, float intensity){ | ||
+ | return vec3(pos.x, pos.y + (DELPHI_NOISE(vec2(pos.x, | ||
+ | } | ||
+ | |||
+ | void VertexShader(inout TLocals DATA){ | ||
+ | DATA.Position.xyz = DELPHI_WOBBLE(DATA.Position.xyz, | ||
+ | |||
+ | DATA.TransfVertexPos = _ModelMatrix * DATA.Position; | ||
+ | DATA.WorldViewProjVertPos = _ModelViewProjectionMatrix * DATA.Position; | ||
+ | } | ||
+ | </ | ||
===== Properties ===== | ===== Properties ===== | ||