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
0.8.3:volumerendering [2021/03/03 15:21] – [Slicing] admin0.8.3:volumerendering [2022/04/08 10:06] (current) – [Gamut Mapping] admin
Line 17: Line 17:
   * Different render shapes: cube, sphere, cylinder   * Different render shapes: cube, sphere, cylinder
   * Changable ray front and back limit   * Changable ray front and back limit
 +  * Managable ray step detail
   * Clipping plane support for optimal slicing   * Clipping plane support for optimal slicing
   * RAW file support   * RAW file support
Line 103: Line 104:
 |TGorillaVolumetricMeshShape.vmsCylinder |Will set up a static cylinder mesh.| |TGorillaVolumetricMeshShape.vmsCylinder |Will set up a static cylinder mesh.|
  
-==== Upload Data ====+==== Details ==== 
 + 
 +TGorillaVolumetricMesh provides a "Details" property, which allows users to control raymarching algorithm. 
 + 
 +The details value increases or decreases ray steps when marching through the 3D volume data. 
 + 
 +This will have direct effect on the number of rendered slices and also on the produced color. 
 + 
 +Sometimes its necessary to have more performance, so lower detail may be a solution. 
 + 
 +==== RayLimits ==== 
 + 
 +Besides "[[#Slicing|Slicing]]" technique users can also manipulate ray cast offsets. 
 +By reducing or increasing the so called "RayLimits"
 + 
 +This is an optimization to reduce marching algorithm in shader and can improve efficiency. 
 + 
 +__NOTICE:__ But carefully, if setting limits to low or to high it may cause slicing in view direction. 
 +===== Upload Data =====
  
 TGorillaVolumetricMesh provides two file formats. TGorillaVolumetricMesh provides two file formats.
Line 110: Line 129:
   * NRRD File   * NRRD File
  
-=== RAW File ===+==== RAW File ====
  
 When uploading 3D data to the volumetric mesh, you can use the direct RAW data upload method. When uploading 3D data to the volumetric mesh, you can use the direct RAW data upload method.
Line 126: Line 145:
 </file> </file>
  
-=== NRRD File ===+==== NRRD File ====
  
 When uploading 3D from a NRRD file, you don't need further parameters. The method will automatically When uploading 3D from a NRRD file, you don't need further parameters. The method will automatically
Line 135: Line 154:
 </file> </file>
  
 +You can setup a NRRD header yourself in case you have only a RAW file.
 +Just add some similar code at the beginning of your file:
 +
 +<code>
 +NRRD0001
 +content: "My NRRD File"
 +type: unsigned char
 +dimension: 3
 +sizes: 256 256 256
 +spacings: 1 1 1
 +encoding: raw
 +
 +[... RAW DATA ...]
 +</code>
 +
 +__NOTICE:__ **LF** and **CRLF** are supported as line endings.
 +
 +
 +==== Procedural Data ====
 +
 +You can of course fill the 3D data array also manually.
 +Pushing data to the 3D-texture by UpdateBuffer() expects to fill data correctly. Otherwise exception may occur.
 +
 +You have to take care of the 3D-texture size by the "Sizes" property of the component and the configured "DataType".
 +
 +In the following a simple code snippet showing a procedure to fill a 512 x 512 x 512 with 4-Byte float values.
 +
 +<file pascal>
 +uses Gorilla.Material.Types, Gorilla.Context.Texturing;
 +
 +TMyVolumetricMesh = class(TGorillaVolumetricMesh)
 +  procedure RandomFill();
 +end;
 +
 +{...}
 +
 +procedure TMyVolumetricMesh.RandomFill();
 +var LTex    : TGorillaTextureBitmap;
 +    LData   : TBytes;
 +    LDPtr   : PSingle; // vmdtFloat !!!
 +    LValue  : Byte;
 +    LOfs,
 +    w, h, d : Integer;
 +    LSizeF  : TPoint3D;
 +    LSizeI  : record
 +                X : Integer;
 +                Y : Integer;
 +                Z : Integer;
 +              end;
 +    LFSize,
 +    LDSize  : Integer;
 +begin
 +  Self.Sizes := TGorillaVolumetricMeshSize.vms512x512x512;
 +  Self.DataType := vmdtFloat; /// !!!
 + 
 +  // get size in fragments
 +  LSizeF := Self.GetSizeAsVector();
 +  LSizeI.X := Round(LSizeF.X);
 +  LSizeI.Y := Round(LSizeF.Y);
 +  LSizeI.Z := Round(LSizeF.Z);
 +
 +  LFSize := GORILLA_VOLUMETRIC_MESH_DATASIZE[Self.DataType];
 +
 +  // create data array
 +  LDSize := LSizeI.X * LSizeI.Y * LSizeI.Z * LFSize;
 +  System.SetLength(LData, LDSize);
 +  try
 +    LDPtr := @LData[0];
 +    // fill data with perlin noise
 +    for w := 0 to (LSizeI.X - 1) do
 +    begin
 +      for h := 0 to (LSizeI.Y - 1) do
 +      begin
 +        for d := 0 to (LSizeI.Z - 1) do
 +        begin
 +          // NOTICE: MAYBE THE VALUE NEED TO BE IN REVERSED BYTE ORDER!
 +          LDPtr^ := Single(RandomRange(0, 10000) / 10000);
 +          Inc(LDPtr);
 +      end;
 +    end;
 +
 +    // push data to 3D texture
 +    LTex := TGorillaVolumetricMeshMaterialSource(FMaterial).Texture as TGorillaTextureBitmap;
 +    LTex.UpdateBuffer(LData, LDSize);
 +  finally
 +    System.SetLength(LData, 0);
 +  end;
 +end;
 +</file>
 ===== Scene Setup ===== ===== Scene Setup =====
  
Line 230: Line 338:
 </file> </file>
  
 +===== Gamut Mapping =====
 +
 +Gamut is a colored texture to define how 3D values will be colored. 
 +Since 0.8.3.2265 this feature is available.
 +
 +Here an example of a simple gradient gamut texture:
 +
 +{{:0.8.3:gamut.jpg?nolink|}}
 +
 +
 +TGorillaVolumetricMesh allows to configure the coloring method by some properties:
 +
 +^Property^Description^
 +|Gamut|Texture used for mapping the 3D value during Raytracing|
 +|GamutMode|Defines when and how the value-color mapping happens. Here different modes are available: GamutNone, GamutByValue, GamutByValueMultiply, GamutBySum, GamutBySumMultiply|
 +|GamutFactor|A factor applied to the absolute 3D value before mapping onto the gamut texture (default value is 1.0)|
 +
 +=== Modes ===
 +
 +The available gamut modes allow to control the output of color mapping. 
 +
 +^Mode^Description^
 +|GamutNone|Gamut mapping is disabled|
 +|GamutByValue|Gamut mapping will be applied to each 3D value on the casted ray.|
 +|GamutByValueMultiply|Gamut mapping will be applied to each 3D value on the casted ray and afterwards multiplied with the previously computed color value.|
 +|GamutBySum|Gamut mapping will be applied to the final casted ray value.|
 +|GamutBySumMultiply|Gamut mapping will be applied to the final casted ray value and afterwards multiplied with the previously computed color value.|
 +
 +Next step: [[particles|Particles]]