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
Last revisionBoth sides next revision
water [2020/01/10 09:03] – [Refraction] adminwater [2020/06/02 14:52] – [Example] admin
Line 2: Line 2:
  
 A water surface is not seldomly a popular game component. We do not provide directly a water surface component, but it is quite easy to setup one. A water surface is not seldomly a popular game component. We do not provide directly a water surface component, but it is quite easy to setup one.
 +
 +{{ :water-example.jpg |}}
  
 Water rendering is based on: Water rendering is based on:
Line 8: Line 10:
   * reflection computation   * reflection computation
   * and the water shader itself   * and the water shader itself
- 
 ===== Components ===== ===== Components =====
  
Line 18: Line 19:
  
 Refraction is the image data simulating __underwater__ 3D objects, modified by some visual effects (Fresnel Effect). We'll need a separated RenderPass for this, to pre-compute the information. Refraction is the image data simulating __underwater__ 3D objects, modified by some visual effects (Fresnel Effect). We'll need a separated RenderPass for this, to pre-compute the information.
-That's the reason why there is no all-in-one component for water, because we want users to reuse their renderpasses instead of instanciating multiple renderpasses for the same image data. This would lead to horrible performance issues. This means you could use the refraction renderpass for water and at the same time f.e. for some transparency effect.+That's the reason why there is no all-in-one component for water, because we want users to reuse their renderpasses instead of instanciating multiple renderpasses for the same image data. This would lead to horrible performance issues. It means you could use the refraction renderpass for water and at the same time f.e. for some transparency effect.
  
 Create an instance of TGorillaRenderPassRefraction and apply the viewport and camera to it. Create an instance of TGorillaRenderPassRefraction and apply the viewport and camera to it.
  
-Because water surface getting rendered in main pass, we should ignore it while refraction computation. This can be done very easily, by:+Because we don't want to appear the water surface itself (would be black) in this image data, we should ignore it while refraction computation. This can be done very easily, by:
 <file pascal> <file pascal>
 FRefraction.IgnoreControl(FWaterPlane); FRefraction.IgnoreControl(FWaterPlane);
 </file> </file>
 +The water surface would be black, because it's image information will be computed in main render pass first.
  
 ==== Reflection ==== ==== Reflection ====
Line 52: Line 54:
 ==== Water Material ==== ==== Water Material ====
  
-Finally of course we need a material shader (TGorillaWaterMaterialSource), which is able to merge all components together.+Finally of course we need a material shader (TGorillaWaterMaterialSource), which is able to merge all components together. The material source is inherited from the TGorillaDefaultMaterialSource and supports multiple light sources and the different shading models.
  
 For computing waves, riffles and foam the shader needs a few textures: For computing waves, riffles and foam the shader needs a few textures:
Line 61: Line 63:
   * FoamTexture   * FoamTexture
  
-The different texture may look like these:+The different textures may look like these:
  
 {{:water-normal.jpg?200|Water normals map}} {{:water-normal.jpg?200|Water normals map}}
Line 80: Line 82:
  
 In the end do not forget to link water plane with water material source. In the end do not forget to link water plane with water material source.
 +<file pascal>
 +FWaterPlane.MaterialSource := FWaterMaterial;
 +</file>
 +
 +=== Properties ===
 +
 +Besides the textures, the water material source provides a few configuration properties to influence water look.
 +
 +^ Property ^ Description ^
 +| Diffuse | The material shader uses this color as main color for water. |
 +| Specular | The specular color interacts with the applied specular color map and configurates its intensity. |
 +| WaveSpeed | Defines how fast waves are moving. |
 +| WaveSize | Defines the amplitude of waves, which means how high or low waves are simulated. This value do not manipulate mesh vertices (only by displacement mapping). |
 +| Displacement | Defines the factor of vertex displacement based on the displacement map or normal map. |
 +| ReflCorrection | By this value you can modify the color of reflection, default value: Vector3D(1.0, 1.0, 1.0, 1.0) |
 +| RefrCorrection | By this value you can modify the color of refraction on water surface, default value: Vector3D(1.1, 1.1, 1.1, 1.0) |
  
 ===== Example ===== ===== Example =====
 +
 +{{youtube>HGlyOlVD28I?medium}}
  
 Take a look at this example code for a complex water surface setup. Take a look at this example code for a complex water surface setup.
Line 130: Line 150:
   FWaterMaterial := TGorillaWaterMaterialSource.Create(FWaterPlane);   FWaterMaterial := TGorillaWaterMaterialSource.Create(FWaterPlane);
   FWaterMaterial.Parent := FWaterPlane;   FWaterMaterial.Parent := FWaterPlane;
-  FWaterMaterial.NormalTexture.LoadFromFile(LTexPath + 'water_normal.png');+  FWaterMaterial.NormalMap.LoadFromFile(LTexPath + 'water_normal.png');
   FWaterMaterial.DUDVTexture.LoadFromFile(LTexPath + 'water3-dudv.jpg');   FWaterMaterial.DUDVTexture.LoadFromFile(LTexPath + 'water3-dudv.jpg');
-  FWaterMaterial.DisplacementTexture.LoadFromFile(LTexPath + 'water_height.png'); +  FWaterMaterial.DisplacementMap.LoadFromFile(LTexPath + 'water_height.png'); 
-  FWaterMaterial.SpecularTexture.LoadFromFile(LTexPath + 'water_height.png');+  FWaterMaterial.SpecularMap.LoadFromFile(LTexPath + 'water_height.png');
   FWaterMaterial.FoamTexture.LoadFromFile(LTexPath + 'foam.png');   FWaterMaterial.FoamTexture.LoadFromFile(LTexPath + 'foam.png');
  
Line 143: Line 163:
 end; end;
 </file> </file>
 +
 +Next step: [[bokeh|Bokeh]]