Script tg_splatter_craters.py

Started by Kevin Kipper, January 14, 2025, 06:48:19 PM

Previous topic - Next topic

Kevin Kipper

As promised, here's a script that's a bit more artistic in nature.  This script "splatters" instances of the Crater shader across your terrain.  Now you can create fields of impact craters with just one click. 

tg_splatter_craters_forumpost.jpg

Each crater's parameter values are randomly generated and based in between the minimum and maximum values you provide.

tg_splatter_craters_gui.jpg

The first thing you'll notice is a checkbutton for "Tooltips".  Hovering over the script's parameters will display a tooltip when the checkbutton is checked.

tg_splatter_craters_tooltips.jpg

To add Crater shaders to the active Terragen project enter the quantity you want in the "Number of craters" field.  The shaders can be grouped together by checking the "Group" checkbutton and providing a name.

The "On mountain or in valley?" parameter will add one Simple Shape Shader beneath all the Crater shaders.  The Simple Shape shader will displace the terrain by the amount specified.  Positive values will displace upwards creating a mound and negative values will displace downward like a valley or pit.  I've found that having a subtle displacement of just a few metres can work wonders when eroding the terrain later on (downstream) in the node network.

Each crater is randomly positioned around the "Area centre x,y,z" coordinates and within the "Area volume x,y,z".  This is similar to how the Populator v4 shader works in Terragen.  You can copy valid x,y,z coordinates from the clipboard to the "Area centre x,y,z" parameter by clicking the "Clip" button, and reset them back to the origin of the project with the "Reset" button.

Parameters for each Crater shader are randomly generated between the "Minimum" and "Maximum" value for that parameter. Some parameter values can be based on the crater's diameter by checking the "or % of diameter" checkbutton.  Furthermore, those values can be randomized by checking the "+/- Offset" checkbutton.

The script includes a list of certain types of displacement shaders that can be assigned to the Crater shader's "Rim shader" parameter.  Select a displacement shader from the list and check the checkbutton.  One displacement shader will be assigned to all the crater shaders generated when the Apply button is clicked.  Most of the displacement shader's parameters are set to their default values, so you'll need to tweak those values based on the size of the craters you're adding to the project.  For example, the default value of the Alpine Fractal shader's "Feature scale" is 4000 metres and its "Displacement amplitude" is 2000 metres. This may be extreme if the crater you're adding is only 10 meters across.  Perhaps a future version of this script can take this into account and scale certain parameters of the displacement shader assigned to the craters.

If desired, the Crater shaders can be inserted into the node network workflow. The "Output > Main input" option will attempt to connect the added Crater shaders in between the first Compute terrain node in the project and whatever shader was assigned to its Main input when the Apply button is clicked.  The "Merge shader" option will attempt the same via a Merge shader node.  When the "Don't" option is chosen, no attempt is made to connect the Crater shaders to the existing node network.

When checked, the "Append fractal warp shader?" checkbutton will add a Fractal Warp shader node after all the Craters.  This comes in handy when you want to apply a warp to the shape of the craters you've just added.  When your craters have been inserted into the node network via the Merge shader this is a handy way to warp only that grouping of Crater shaders.  The Fractal Warp shader's Scale value is set to about twenty-five percent of the crater diameter.

Clicking the "Apply" button will add the Crater shaders and other supporting nodes to the project.

tg_splatter_craters_NodeNetwork.jpg

The menu includes a set of "Presets". These values are meant for fun and are not necessarily scientifically accurate.  I'd love to add more presets to the menu, both artistic and scientific, so if you come up with any good ones please let me know, or try your hand at editing the preset dictionary in the script.

tg_splatter_craters_presets.jpg

Have you ever noticed that the Crater shader doesn't have handles so that you can move it around in the 3D Preview, even though it has x,y,z coordinates?  What if you want to move a crater?  This is where the tg_copy_coords_to_selected.py script comes into play.  You can right click in the 3D Preview and select "Copy Coordinates" for the location you want to move the crater to, then run the tg_copy_coords_to_selected.py script.  The script will copy the coordinates from the clipboard to any nodes you have selected in the Node Network that accept xyz coordinates.  Here's a link to the forum post with more information about that script: https://planetside.co.uk/forums/index.php/topic,30972.0.html

This script can create some interesting terrains to say the least.  When applying the techniques described in the Terrain Techniques blog posts such as warping and eroding a basic shape, in this case the Crater shaders, you can come up with unique and exciting terrains. 

https://planetside.co.uk/blog/terrain-techniques-simple-shape-shader/
https://planetside.co.uk/blog/terrain-techniques-image-map-shader/
https://planetside.co.uk/blog/terrain-techniques-detail-warp-erode/

Here are some example renders that I've made by just goofing around with the script.

tg_splatter_craters_examples.jpg

This script is now included with the redmaw-tg-toolkit repository.
 
Click the link below for download and installation information for the entire toolkit.
https://github.com/RedMawVFX/redmaw-tg-toolkit

Or, click the link below to go directly to the tg-splatter-craters folder in the toolkit.
https://github.com/RedMawVFX/redmaw-tg-toolkit/tree/main/scripts/tg-splatter-craters

Dune

This is really cool! I have't used RPC yet, so I'm curious how this will work. Actually I was hoping that once you execute the script you end up with a clipfile that can be saved and used with an open TG, not by using the script. Because I imagine you sometimes want to enliven a landscape with something like this, but then you've already opened a project. But I guess you miss certain parameters then.
Your samples are very inviting!

Kevin Kipper

For most of the scripts I'm posting, you need Terragen to be open.  That's what I refer to as the "active" Terragen project.  When you run a script that utilizes the RPC feature, the script is communicating with that open Terragen project.

In this script you're adding Crater shaders to the active project.  You can always select all the Crater shaders and save them as a clip file for use in other Terragen projects.


Dune

Thanks Kevin. Good to know it works like that. I will dive into this...

RichTwo

Hello once again.  Since I had medical issue which limited computer use, I had taken a somewhat sustained absence from both this forum and Terragen itself. This is a welcome addition indeed, except I haven't found a way to get Terragen to communicate with the script.

So far, trying use TG to open / read the script results in my only getting an error message, which I guess says it's unable to do so. The message box is too small to show all of the message.

The only app I have that will show anything, which I assume is the entire script, is the MS File Viewer.  I have not found any practical way to use this, so there must be something else, which I'm not sure I have.

I have read the above instructions several times, and it's still not clear to me how the script will create the TG nodes.

I'd really love to have this capability, since much of my endeavors are of a space / extraterrestrial theme. Thanks in advance for any helpful advice.

They're all wasted!

Matt

#5
Hi Rich. There is a bit of setup required, but it's not as difficult as it sounds, and you should only have to do this once. Then any other RPC scripts that Kevin or other people post should just run without any hassle.

I'll go over the steps in a moment. But just to give you a high level overview of how you use Kevin's crater script, you can think of it as a sidecar program that talks to Terragen while they are both running. It's a standalone program, but it works a bit like a Terragen plugin. All you do is double click on the .py or .pyw file in your downloads folder, or wherever you put it on your hard drive, and it should open up the scatter craters UI. You open it from a normal Windows Explorer window; do NOT try to open it in Terragen because it's not a Terragen file.

You will need two things installed: 1) Python, and 2) an extra module for Python that allows Kevin's scripts to communicate with Terragen. That's the Terragen RPC module.

1) It sounds like you don't have Python installed, but other people reading this might have it installed already. To test that, download the .py file from Kevin's Github page and double click on the .py file in your downloads folder, or wherever it is on your hard drive (in Windows Explorer; do NOT try to open it in Terragen), and see what happens.

If you get an error about "terragen_rpc" then we know that Python is already installed and we just need to get terragen_rpc.

If you don't see anything at all, go into a Windows command prompt (run 'cmd' from Windows Start button or search field) and type in 'python -help' (without quotes), to see if python is installed.

I recommend not using the Microsoft Store version of Python, but if you have it installed already then that's fine.

I recommend downloading Python from here: https://www.python.org/downloads/

When installing Python make sure you enable the option to set up the PATH environment variable in the Python installer.

2) Go into a Windows command prompt again (click on Windows Start button and type 'cmd'). At the command prompt enter this:

python -m pip install terragen-rpc

This will find terragen-rpc on the pip server and it will automatically download it and put it in the right place in your Python installation.

That should be everything for the setup. After everything's set up you won't need to do this again. And some day in the future we might have Python embedded in Terragen, and this'll get easier.

Now whenever Terragen is running you can can double click on the .py file (or .pyw file) in a Windows Explorer window. Make sure only one instance of Terragen is running, otherwise RPC might talk to the wrong one.
Just because milk is white doesn't mean that clouds are made of milk.

Matt

For Mac users the principles are mostly the same, except you might already have Python installed. But you will have to install terragen-rpc in the terminal:

python -m pip install terragen-rpc
Just because milk is white doesn't mean that clouds are made of milk.

Dune

QuoteThis will find terragen-rpc on the pip server and it will automatically download it and put it in the right place in your Python installation.
What if you want to install this on an air-gapped machine? Is there any specific place where you should put the RPC in the Python environment?

Matt

If you don't have direct access to the internet on the computer where you need to run pip install, you can download the .whl package manually and use pip install with a file you downloaded.

Get the .whl file from this page:
https://pypi.org/project/terragen-rpc/#files

Then go to the folder where the .whl file is and run this command:

python -m pip install terragen_rpc-0.9.2-py3-none-any.whl
(Of course change this filename if there is a newer version when you read this post in the future. If you have access to the internet and run python -m pip install terragen-rpc it will always get the latest version.)
Just because milk is white doesn't mean that clouds are made of milk.

RichTwo

Thanks, Matt - and Kevin. I got it all successfully installed it appears that it's working, now just have to fiddle with the settings to see what happens. Looks to be promising!
They're all wasted!

Dune

The command is looking for the file in a users/name folder, so that's where the .whl should be put (I found out). Now it works like a dream.

Kevin Kipper

Thanks Matt for the added explanation of getting Python and the terragen_rpc module installed, and to RichTwo and Dune for taking the effort to get Python and the scripts up and running on their systems. 

My hope is that by sharing these scripts and dialoging about them and other new ideas, that the entire Terragen community will benefit.

If you guys come up with cool settings for craters, we can add them to the presets menu.  Can't wait to see what you come up with.

Dune

Don't wait for me, as I hardly ever make cratery terrains. I just like to see how it worked, and have it at hand.

One thing springs to mind regarding all your scripts: it would be perfect if they could somehow be integrated into the program itself, for even easier access. An extra button somewhere to get a popup with all your inventions/additions.

RichTwo

I have been toying with this application off and on for a few days. Maybe it's my old clunker of a machine, but the control panel(s) will not stay open while I am working on a project. Have to relaunch it causes me to re-enter everything, and then it closes itself again. So I've decided to shelf it for now, until a fix becomes available if there is one.

Also, since there's no way to move the craters by dragging a visible outline or axis arrows, I need to input and copy / paste coords from Simple Shape Shader(s) and move them that way.  I've used that method long before this was released. But I do like the idea of being able to create multiple craters at one time. I'd like even better when I can see where they are and move them around.

Let me know if you need any more info. As I stated, I've got a fairly old computer.

They're all wasted!

Kevin Kipper

Can you clarify a bit about the control panel(s) not staying open.  Are you using the tg_dashboard script to run the tg_splatter_craters script?  Or, just one of the scripts?  I just want to be clear as to what is not working.  On my Windows 10 system, both panels stay open independently of Terragen.  The Python code itself makes use of the mainloop() function which tells the UI window to remain open until the script is closed by the user.  

Out of curiosity can you tell us which version of Python is being run on your system?  You can get this information by opening a command shell and typing "python --version" without the quotes.

You're correct that the crater shader does not have handles, and that's a bummer.  That was one of the reasons for the tg_copy_coords_to_selected script.  I found it was easier to right click in the 3D Preview and copy coordinates, then select a crater shader node in the Node Network and run the script.  Admittedly, you're still guessing as to which Crater shader node you're dealing with, unless you know the order they were created in or have some other way to identify which crater node is which crater in the 3D Preview.

I was thinking about adding an option to save the parameter settings.  This way you wouldn't have to re-enter them all the time.  Good suggestion.