Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
1.1.0:default-material [2023/08/01 12:07] – [Material Behaviours] admin1.1.0:default-material [2024/01/05 10:07] (current) – [TGorillaShaderLight] admin
Line 537: Line 537:
 Having a closer look at the structure below, it's showing further sub structures for lights, material, textures and render pass data. Having a closer look at the structure below, it's showing further sub structures for lights, material, textures and render pass data.
 Those sub structures are automatically submitted to shaders too. Those sub structures are automatically submitted to shaders too.
 +
 +//Notice: Modified since v1.1//
  
 <file pascal> <file pascal>
   TGorillaShaderData = packed record   TGorillaShaderData = packed record
-    /// <summary> 
-    /// Defines the multiplied model and view matrix. 
-    /// </summary> 
-    ModelMatrix : TMatrix3D; 
     /// <summary>     /// <summary>
     /// Defines the multiplied model, view and projection matrix.     /// Defines the multiplied model, view and projection matrix.
     /// </summary>     /// </summary>
     ModelViewProjectionMatrix : TMatrix3D;     ModelViewProjectionMatrix : TMatrix3D;
-    /// <summary> 
-    /// Defines the inverted and transposed multiplied model and view matrix. 
-    /// </summary> 
-    ModelNormalMatrix : TMatrix3D; 
     /// <summary>     /// <summary>
     /// Defines the view / camera matrix.     /// Defines the view / camera matrix.
Line 728: Line 722:
     /// </summary>     /// </summary>
     Clipping : TAlphaColorF;     Clipping : TAlphaColorF;
 +    
 +    /// <summary>
 +    /// Alpha cutoff value: (X > 0.01) == enabled, (Y == tolerated value)
 +    /// </summary>
 +    AlphaCutoff : TPointF;
 +    /// <summary>
 +    /// Tonemapping exposure value
 +    /// </summary>
 +    ToneMapExp  : Single;
 +    Reserve     : Single;
  
     /// <summary>     /// <summary>
Line 846: Line 850:
   {$ENDIF}   {$ENDIF}
     Position    : TVector3D;     Position    : TVector3D;
-    /// <summary> 
-    /// A "halfway vector" (if you mean that by "half vector") is the unit 
-    /// vector at the half angle between two other vectors. Normally the 
-    /// halfway vector [...] is computed between the vector to the viewer v 
-    /// and the light source. 
-    /// </summary> 
-    /// <remarks> 
-    /// H(a,b) = normalize(normalize(a) + normalize(b)) 
-    /// </remarks> 
-//    HalfVector  : TVector3D; 
     Direction   : TVector3D;     Direction   : TVector3D;
     Ambient     : TAlphaColorF;     Ambient     : TAlphaColorF;
     Diffuse     : TAlphaColorF;     Diffuse     : TAlphaColorF;
     Specular    : TAlphaColorF;     Specular    : TAlphaColorF;
 +    
 +    /// <summary>
 +    /// Light-Scattering settings are compressed into a single vec4 value, with
 +    /// the following structure:
 +    /// x=intensity, y=exposure, z=decay, w=density
 +    /// </summary>
 +    Scattering : TVector3D;    
  
     SpotCutoff    : Single;     SpotCutoff    : Single;
Line 868: Line 869:
     LinearAttenuation    : Single;     LinearAttenuation    : Single;
     QuadraticAttenuation : Single;     QuadraticAttenuation : Single;
-  {$IFDEF GL_ES_VERSION_3_0} +     
-    // due to memory alignment in gpu - we have to adjust +    Intensity : Single; 
-    Reserved4   : Array[0..7] of Byte; +    Enabled   : FixedInt;
-  {$ENDIF}+
  
     constructor Create(ALight : TLightDescription);     constructor Create(ALight : TLightDescription);
Line 1033: Line 1033:
 Apply a single material behaviour to multiple material sources, but the place to edit parameters of your behaviour stay centralized. This makes it very easy to manage complex shading behaviour. Apply a single material behaviour to multiple material sources, but the place to edit parameters of your behaviour stay centralized. This makes it very easy to manage complex shading behaviour.
  
-Read more [[material-behaviour|Material Behaviour]]+Read more about [[material-behaviour|Material Behaviour]]
 ===== Extending the default material ===== ===== Extending the default material =====
  
Line 1446: Line 1446:
   DATA.Position.xyz = DELPHI_WOBBLE(DATA.Position.xyz, _TimeInfo.y, 0.5);   DATA.Position.xyz = DELPHI_WOBBLE(DATA.Position.xyz, _TimeInfo.y, 0.5);
  
-  DATA.TransfVertexPos = _ModelMatrix * DATA.Position;+  DATA.TransfVertexPos = a_ModelMatrix * DATA.Position;
   DATA.WorldViewProjVertPos = _ModelViewProjectionMatrix * DATA.Position;   DATA.WorldViewProjVertPos = _ModelViewProjectionMatrix * DATA.Position;
 } }
Line 1480: Line 1480:
 Read more about TLocals structure in VertexShader/SurfaceShader in section [[#tgorillaglobalsnode_globals|TGorillaGlobalsNode]] Read more about TLocals structure in VertexShader/SurfaceShader in section [[#tgorillaglobalsnode_globals|TGorillaGlobalsNode]]
 at //TGorillaGLSLVertexShaderLocalsStructNode// and //TGorillaGLSLFragmentShaderLocalsStructNode//. at //TGorillaGLSLVertexShaderLocalsStructNode// and //TGorillaGLSLFragmentShaderLocalsStructNode//.
 +
 +To modify the "SurfaceShader" or "VertexShader" property at runtime, you have to work with a temporary TStrings component.
 +Otherwise the shader code is not getting updated after modifying the user-code:
 +
 +<file Pascal>
 +procedure TForm1.SetMyShaderCode();
 +var LStr : TStringList;
 +begin
 +  /// Create a temporary stringlist component for our source code
 +  LStr := TStringList.Create();
 +  try
 +    LStr.Text :=
 +      'void SurfaceShader(inout TLocals DATA){'#13#10 +
 +      /// make everything green
 +      '  DATA.BaseColor.xyz = vec3(0.0, 1.0, 0.0);'#13#10 +
 +      '}';
 +
 +    // Apply the temporary stringlist to the material
 +    // This will assign it to the internal stringlist and update the shader code
 +    // automatically.
 +    GorillaLambertMaterialSource1.SurfaceShader := LStr;
 +  finally
 +    FreeAndNil(LStr);
 +  end;
 +end;
 +</file>
  
 ==== Adding new Textures at DesignTime ==== ==== Adding new Textures at DesignTime ====