Water reflections

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Water reflections

Post by Deadlock989 »

I've looked at the way the fuzzy reflection map is supplied for vanilla entities in 0.18.

TL;DR - it seems to be a fuzzy upside-down silhouetted version of one frame of the source entity, red channel only. But it's hard to make out exactly how they were made.

I have a mod with about 40 custom entities, most of them 3x3 tiles, but some larger, and some are "tall", exceeding their selection box substantially, i.e. more likely to be caught by the north shore of some water.

Can anyone suggest an automated method of producing the reflection sprite, given the 0.17 prototype data? I can't face doing them all manually one by one, with all their different sizes and offsets and frame counts, and I don't have a copy of the individual separate frames for most of the entities, just the final sheets.
Last edited by Deadlock989 on Sat Oct 24, 2020 2:49 pm, edited 1 time in total.
Image

Einis
Manual Inserter
Manual Inserter
Posts: 2
Joined: Fri Jul 28, 2017 3:45 pm
Contact:

Re: Question about reflections

Post by Einis »

Here is the basic process:
  • Invert image along the Y-axis or render shadow type image which will be more accurate
  • If inverted then probably some manual painting is required to mimic the reflection shape
  • In Photoshop I used gaussian blur with 5 pixels radius
So how this works. In image Red is reflection information, Blue is foam information. For reflection bigger blur means more "destroyed" representation. For foam it is straight forward, more value = more foam.

Regarding automation, if you have only sheets then setting up automation would probably take longer than making it by hand. Doing it by hand might be tedious, but it is a fairly simple process. If you have separate frames centered without offset then Photoshop Batch is the fastest route. Just make an Action with invert and blur operations. Gimp and some other editors also have some batching if Photoshop is not an option.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Question about reflections

Post by Deadlock989 »

Einis wrote:
Wed Jan 29, 2020 4:02 pm
some manual painting is required
That's what I was afraid of.
Image

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Question about reflections

Post by Deadlock989 »

Here is how I managed to automate this in Blender 2.79 for a custom offshore pump (the only entity that will always have a visible reflection) in case anyone else has ever struggled with this.

1. Set up a water reflection plane and put it on a special layer all of its own. It should be about 16 pixel-equivalent-units (per HD scale 0.5) below the usual ground level. It should have a pure white metallic surface that is pretty rough (0.5 roughness in the Principled BSDF shader). Exclude all of your existing light sources and the ground layer from your reflection layer and set up a special sun lamp that is pointing directly downwards and has a spot size about double what you have for your regular non-shadow lighting. Your actual objects should not be included in this layer but not excluded either (so that their reflection shows up but their actual structure doesn't).

plane.png
plane.png (5.48 KiB) Viewed 1281 times
2. Turn off environmental lighting in the reflection layer and give it a separate AO pass. Have AO set to about 16 units in the world settings but leave it turned off (Blender still calculates it for the compositor pass but turning it "off" stops it being automatically added to the main pass output - unless you want that, but I prefer to handle it separately in the compositor for more control over how the AO is blended).

layer.png
layer.png (130.79 KiB) Viewed 1281 times
3. We use the AO pass for the foam because it only shows up where your pipes meet / are very close to the water level, and the blurred reflection as the reflection itself. In the Compositor, you want to take the main image, invert it, then ramp it so the majority of the surface (where no reflection is falling) is black. Doesn't hurt to blur it a bit as well, the rendering is going to distort the hell out of it anyway. Put that into the red channel of a Combine RGBA node. Do similar for the AO pass output and put it into the blue channel. Tweak your ramps until you get the desired effect.

composition.png
composition.png (280.73 KiB) Viewed 1281 times
4. Hey presto, you have your reflection and foam channels.

final.png
final.png (78.22 KiB) Viewed 1281 times
5. Figuring out how the holy fuck to get the border cropping and shift values right is an exercise I leave to the reader. Hint: if all else fails, you can specify individual parts of the sheet per direction in the SpriteVariations table with specific x offset values per slice, using variation_count = 1 instead of letting variation_count = 4 do it automatically with the same shift for all the directions.
Image

Post Reply

Return to “Modding discussion”