Skip to content

Commit a0aef00

Browse files
authored
Merge pull request #899 from Xtarsia/improve-flat-bg-mode
Improve Region Blend, gizmos, shaders
2 parents dae01b1 + 9507421 commit a0aef00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+989
-714
lines changed

Terrain3D.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@
224224
<None Include="src\shaders\debug_views.glsl" />
225225
<None Include="src\shaders\displacement.glsl" />
226226
<None Include="src\shaders\displacement_buffer.glsl" />
227+
<None Include="src\shaders\macro_variation.glsl" />
227228
<None Include="src\shaders\main.glsl" />
228229
<None Include="src\shaders\overlays.glsl" />
229230
<None Include="src\shaders\pbr_views.glsl">
230231
<FileType>Document</FileType>
231232
</None>
233+
<None Include="src\shaders\projection.glsl" />
232234
<None Include="src\shaders\samplers.glsl" />
233235
<None Include="src\shaders\backgrounds.glsl" />
234236
<None Include="src\shaders\editor_functions.glsl" />

Terrain3D.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@
283283
<None Include="doc\docs\displacement.md">
284284
<Filter>2. Docs</Filter>
285285
</None>
286+
<None Include="src\shaders\macro_variation.glsl">
287+
<Filter>4. Shaders</Filter>
288+
</None>
289+
<None Include="src\shaders\projection.glsl">
290+
<Filter>4. Shaders</Filter>
291+
</None>
286292
</ItemGroup>
287293
<ItemGroup>
288294
<Text Include=".readthedocs.yaml">

doc/api/class_terrain3dassets.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ Methods
7474
+-----------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
7575
| ``PackedFloat32Array`` | :ref:`get_texture_uv_scales<class_Terrain3DAssets_method_get_texture_uv_scales>`\ (\ ) |const| |
7676
+-----------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
77-
| ``int`` | :ref:`get_texture_vertical_projections<class_Terrain3DAssets_method_get_texture_vertical_projections>`\ (\ ) |const| |
78-
+-----------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
7977
| Error | :ref:`save<class_Terrain3DAssets_method_save>`\ (\ path\: ``String`` = ""\ ) |
8078
+-----------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
8179
| |void| | :ref:`set_mesh_asset<class_Terrain3DAssets_method_set_mesh_asset>`\ (\ id\: ``int``, mesh\: :ref:`Terrain3DMeshAsset<class_Terrain3DMeshAsset>`\ ) |
@@ -416,18 +414,6 @@ Returns the array of uv scale values for each texture asset, indexed by asset id
416414

417415
----
418416

419-
.. _class_Terrain3DAssets_method_get_texture_vertical_projections:
420-
421-
.. rst-class:: classref-method
422-
423-
``int`` **get_texture_vertical_projections**\ (\ ) |const| :ref:`🔗<class_Terrain3DAssets_method_get_texture_vertical_projections>`
424-
425-
Returns a 32-bit int that identifies which textures are to be projected vertically.
426-
427-
.. rst-class:: classref-item-separator
428-
429-
----
430-
431417
.. _class_Terrain3DAssets_method_save:
432418

433419
.. rst-class:: classref-method

doc/api/class_terrain3dmaterial.rst

Lines changed: 177 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ This class handles options for both the built-in shader and any custom override
2323

2424
It is a savable resource, so you can save it to disk and use the same material settings in multiple scenes that use Terrain3D. The amount of data is small, assuming you have saved your shader parameter textures to disk, so it can be saved as a git-friendly, text based .tres file or left within the scene file.
2525

26-
While it does mimic some of the functionality of ShaderMaterial, it does not derive from any of the Godot Material classes. It will not pass any ``is Material`` checks. It is a ``Resource``.
26+
While it does mimic some of the functionality of ShaderMaterial, it does not derive from any of the Godot Material classes. It will fail any ``is Material`` checks. It is a ``Resource``.
27+
28+
Inspector settings above `Custom Shader` and :ref:`shader_override<class_Terrain3DMaterial_property_shader_override>` are used to determine what code is used in the current shader. Inspector settings in `Shader Uniforms` are the public uniforms (not prefaced with `\_`) available in the current shader.
2729

2830
.. rst-class:: classref-reftable-group
2931

@@ -48,6 +50,18 @@ Properties
4850
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
4951
| ``bool`` | :ref:`dual_scaling_enabled<class_Terrain3DMaterial_property_dual_scaling_enabled>` | ``false`` |
5052
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
53+
| ``bool`` | :ref:`macro_variation_enabled<class_Terrain3DMaterial_property_macro_variation_enabled>` | ``false`` |
54+
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
55+
| ``bool`` | :ref:`output_albedo<class_Terrain3DMaterial_property_output_albedo>` | ``true`` |
56+
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
57+
| ``bool`` | :ref:`output_ambient_occlusion<class_Terrain3DMaterial_property_output_ambient_occlusion>` | ``true`` |
58+
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
59+
| ``bool`` | :ref:`output_normal_map<class_Terrain3DMaterial_property_output_normal_map>` | ``true`` |
60+
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
61+
| ``bool`` | :ref:`output_roughness<class_Terrain3DMaterial_property_output_roughness>` | ``true`` |
62+
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
63+
| ``bool`` | :ref:`projection_enabled<class_Terrain3DMaterial_property_projection_enabled>` | ``false`` |
64+
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
5165
| ``Shader`` | :ref:`shader_override<class_Terrain3DMaterial_property_shader_override>` | |
5266
+------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+-----------+
5367
| ``bool`` | :ref:`shader_override_enabled<class_Terrain3DMaterial_property_shader_override_enabled>` | ``false`` |
@@ -124,7 +138,7 @@ Methods
124138
+-------------+----------------------------------------------------------------------------------------------------------------------------+
125139
| |void| | :ref:`set_shader_param<class_Terrain3DMaterial_method_set_shader_param>`\ (\ name\: ``StringName``, value\: ``Variant``\ ) |
126140
+-------------+----------------------------------------------------------------------------------------------------------------------------+
127-
| |void| | :ref:`update<class_Terrain3DMaterial_method_update>`\ (\ full\: ``bool`` = false\ ) |
141+
| |void| | :ref:`update<class_Terrain3DMaterial_method_update>`\ (\ flags\: ``int`` = 0\ ) |
128142
+-------------+----------------------------------------------------------------------------------------------------------------------------+
129143

130144
.. rst-class:: classref-section-separator
@@ -192,6 +206,56 @@ Textures are filtered using a blend of 4 adjacent pixels. Use this for most case
192206

193207
Textures are filtered using a the nearest pixel only. It is faster than LINEAR, but the texture will look pixelated. Use this for a low-poly look, with a very low uv_scale.
194208

209+
.. rst-class:: classref-item-separator
210+
211+
----
212+
213+
.. _enum_Terrain3DMaterial_UpdateFlags:
214+
215+
.. rst-class:: classref-enumeration
216+
217+
enum **UpdateFlags**: :ref:`🔗<enum_Terrain3DMaterial_UpdateFlags>`
218+
219+
.. _class_Terrain3DMaterial_constant_UNIFORMS_ONLY:
220+
221+
.. rst-class:: classref-enumeration-constant
222+
223+
:ref:`UpdateFlags<enum_Terrain3DMaterial_UpdateFlags>` **UNIFORMS_ONLY** = ``0``
224+
225+
Non-texture array values are assigned to the shader. This is the default and is always done.
226+
227+
.. _class_Terrain3DMaterial_constant_TEXTURE_ARRAYS:
228+
229+
.. rst-class:: classref-enumeration-constant
230+
231+
:ref:`UpdateFlags<enum_Terrain3DMaterial_UpdateFlags>` **TEXTURE_ARRAYS** = ``1``
232+
233+
The ground texture arrays are assigned to the shader, along with the values in `UNIFORMS_ONLY`.
234+
235+
.. _class_Terrain3DMaterial_constant_REGION_ARRAYS:
236+
237+
.. rst-class:: classref-enumeration-constant
238+
239+
:ref:`UpdateFlags<enum_Terrain3DMaterial_UpdateFlags>` **REGION_ARRAYS** = ``2``
240+
241+
The region data texture arrays are assigned to the shader, along with the values in `UNIFORMS_ONLY`.
242+
243+
.. _class_Terrain3DMaterial_constant_UPDATE_ARRAYS:
244+
245+
.. rst-class:: classref-enumeration-constant
246+
247+
:ref:`UpdateFlags<enum_Terrain3DMaterial_UpdateFlags>` **UPDATE_ARRAYS** = ``3``
248+
249+
Values in `TEXTURE_ARRAYS` and `REGION_ARRAYS` are assigned to the shader.
250+
251+
.. _class_Terrain3DMaterial_constant_FULL_REBUILD:
252+
253+
.. rst-class:: classref-enumeration-constant
254+
255+
:ref:`UpdateFlags<enum_Terrain3DMaterial_UpdateFlags>` **FULL_REBUILD** = ``7``
256+
257+
The shader is rebuilt, then all values in `UPDATE_ARRAYS` are assigned to the shader.
258+
195259
.. rst-class:: classref-section-separator
196260

197261
----
@@ -221,8 +285,8 @@ This private dictionary stores all of the shader parameters in the resource. It
221285

222286
.. rst-class:: classref-property-setget
223287

224-
- |void| **set_auto_shader**\ (\ value\: ``bool``\ )
225-
- ``bool`` **get_auto_shader**\ (\ )
288+
- |void| **set_auto_shader_enabled**\ (\ value\: ``bool``\ )
289+
- ``bool`` **get_auto_shader_enabled**\ (\ )
226290

227291
Enables selecting two texture IDs that will automatically be applied to the terrain based upon slope.
228292

@@ -306,15 +370,117 @@ Adjusts the transition between textures. When set at `1.0`, the blending of disp
306370

307371
.. rst-class:: classref-property-setget
308372

309-
- |void| **set_dual_scaling**\ (\ value\: ``bool``\ )
310-
- ``bool`` **get_dual_scaling**\ (\ )
373+
- |void| **set_dual_scaling_enabled**\ (\ value\: ``bool``\ )
374+
- ``bool`` **get_dual_scaling_enabled**\ (\ )
311375

312376
Enables selecting one texture ID that will have multiple scales applied based upon camera distance. Use it for something like a rock texture so up close it will be nicely detailed, and far away mountains can be covered in the same rock texture without looking tiled. The two blend together at a specified distance.
313377

314378
.. rst-class:: classref-item-separator
315379

316380
----
317381

382+
.. _class_Terrain3DMaterial_property_macro_variation_enabled:
383+
384+
.. rst-class:: classref-property
385+
386+
``bool`` **macro_variation_enabled** = ``false`` :ref:`🔗<class_Terrain3DMaterial_property_macro_variation_enabled>`
387+
388+
.. rst-class:: classref-property-setget
389+
390+
- |void| **set_macro_variation_enabled**\ (\ value\: ``bool``\ )
391+
- ``bool`` **get_macro_variation_enabled**\ (\ )
392+
393+
Allows you to add a couple of noise patterns at different scales and colors to add variation to your terrain to avoid tiled textures.
394+
395+
.. rst-class:: classref-item-separator
396+
397+
----
398+
399+
.. _class_Terrain3DMaterial_property_output_albedo:
400+
401+
.. rst-class:: classref-property
402+
403+
``bool`` **output_albedo** = ``true`` :ref:`🔗<class_Terrain3DMaterial_property_output_albedo>`
404+
405+
.. rst-class:: classref-property-setget
406+
407+
- |void| **set_output_albedo_enabled**\ (\ value\: ``bool``\ )
408+
- ``bool`` **get_output_albedo_enabled**\ (\ )
409+
410+
Enables the Albedo, aka Base Color or Diffuse, output channel in the shader.
411+
412+
.. rst-class:: classref-item-separator
413+
414+
----
415+
416+
.. _class_Terrain3DMaterial_property_output_ambient_occlusion:
417+
418+
.. rst-class:: classref-property
419+
420+
``bool`` **output_ambient_occlusion** = ``true`` :ref:`🔗<class_Terrain3DMaterial_property_output_ambient_occlusion>`
421+
422+
.. rst-class:: classref-property-setget
423+
424+
- |void| **set_output_ambient_occlusion_enabled**\ (\ value\: ``bool``\ )
425+
- ``bool`` **get_output_ambient_occlusion_enabled**\ (\ )
426+
427+
Enables the Ambient Occlusion output channel in the shader.
428+
429+
.. rst-class:: classref-item-separator
430+
431+
----
432+
433+
.. _class_Terrain3DMaterial_property_output_normal_map:
434+
435+
.. rst-class:: classref-property
436+
437+
``bool`` **output_normal_map** = ``true`` :ref:`🔗<class_Terrain3DMaterial_property_output_normal_map>`
438+
439+
.. rst-class:: classref-property-setget
440+
441+
- |void| **set_output_normal_map_enabled**\ (\ value\: ``bool``\ )
442+
- ``bool`` **get_output_normal_map_enabled**\ (\ )
443+
444+
Enables the Normal Map output channel in the shader.
445+
446+
.. rst-class:: classref-item-separator
447+
448+
----
449+
450+
.. _class_Terrain3DMaterial_property_output_roughness:
451+
452+
.. rst-class:: classref-property
453+
454+
``bool`` **output_roughness** = ``true`` :ref:`🔗<class_Terrain3DMaterial_property_output_roughness>`
455+
456+
.. rst-class:: classref-property-setget
457+
458+
- |void| **set_output_roughness_enabled**\ (\ value\: ``bool``\ )
459+
- ``bool`` **get_output_roughness_enabled**\ (\ )
460+
461+
Enables the Roughness output channel in the shader.
462+
463+
.. rst-class:: classref-item-separator
464+
465+
----
466+
467+
.. _class_Terrain3DMaterial_property_projection_enabled:
468+
469+
.. rst-class:: classref-property
470+
471+
``bool`` **projection_enabled** = ``false`` :ref:`🔗<class_Terrain3DMaterial_property_projection_enabled>`
472+
473+
.. rst-class:: classref-property-setget
474+
475+
- |void| **set_projection_enabled**\ (\ value\: ``bool``\ )
476+
- ``bool`` **get_projection_enabled**\ (\ )
477+
478+
Enables textures to be projected vertically when placed on slopes above 45 degrees. This is useful for mapping textures on cliff faces without stretching, even though the polygons are stretched.
479+
480+
.. rst-class:: classref-item-separator
481+
482+
----
483+
318484
.. _class_Terrain3DMaterial_property_shader_override:
319485

320486
.. rst-class:: classref-property
@@ -343,7 +509,9 @@ If shader_override_enabled is true and this Shader is valid, the material will u
343509
- |void| **set_shader_override_enabled**\ (\ value\: ``bool``\ )
344510
- ``bool`` **is_shader_override_enabled**\ (\ )
345511

346-
Enables use of the :ref:`shader_override<class_Terrain3DMaterial_property_shader_override>` shader code. Generates default code if shader_override is blank.
512+
Enables using the :ref:`shader_override<class_Terrain3DMaterial_property_shader_override>` shader. An editable shader is generated from the current one if shader_override is blank.
513+
514+
The inspector settings above this group determine the code that is used in the current shader. The settings below are uniforms for the current shader.
347515

348516
.. rst-class:: classref-item-separator
349517

@@ -854,11 +1022,9 @@ Set a parameter in the active shader (built-in or override shader).
8541022

8551023
.. rst-class:: classref-method
8561024

857-
|void| **update**\ (\ full\: ``bool`` = false\ ) :ref:`🔗<class_Terrain3DMaterial_method_update>`
858-
859-
Sends all uniform values to the shader again.
1025+
|void| **update**\ (\ flags\: ``int`` = 0\ ) :ref:`🔗<class_Terrain3DMaterial_method_update>`
8601026

861-
full - recompiles the shader first.
1027+
Sends uniform values to the shader. See :ref:`UpdateFlags<enum_Terrain3DMaterial_UpdateFlags>` for options.
8621028

8631029
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
8641030
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`

doc/api/class_terrain3dregion.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Methods
6464
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
6565
| |void| | :ref:`calc_height_range<class_Terrain3DRegion_method_calc_height_range>`\ (\ ) |
6666
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
67+
| |void| | :ref:`clear<class_Terrain3DRegion_method_clear>`\ (\ ) |
68+
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
6769
| |void| | :ref:`dump<class_Terrain3DRegion_method_dump>`\ (\ verbose\: ``bool`` = false\ ) |const| |
6870
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
6971
| :ref:`Terrain3DRegion<class_Terrain3DRegion>` | :ref:`duplicate<class_Terrain3DRegion_method_duplicate>`\ (\ deep\: ``bool`` = false\ ) |
@@ -402,6 +404,18 @@ Recalculates the height range for this region by looking at every pixel in the h
402404

403405
----
404406

407+
.. _class_Terrain3DRegion_method_clear:
408+
409+
.. rst-class:: classref-method
410+
411+
|void| **clear**\ (\ ) :ref:`🔗<class_Terrain3DRegion_method_clear>`
412+
413+
Unreferences the maps and resets all of the variables to default values.
414+
415+
.. rst-class:: classref-item-separator
416+
417+
----
418+
405419
.. _class_Terrain3DRegion_method_dump:
406420

407421
.. rst-class:: classref-method

0 commit comments

Comments
 (0)