New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underwater effect #15

Open
PiKeyAr opened this Issue Dec 23, 2016 · 12 comments

Comments

Projects
None yet
5 participants
@PiKeyAr
Collaborator

PiKeyAr commented Dec 23, 2016

This isn't necessarily lighting-related, but I thought it would fit the profile of this mod, and it can be implemented with a shader as well.

In SA1, when the camera is underwater, the whole screen except the HUD gets a slight blue tint.

Comparison:
SA1
SA1
SADX PC
SADX PC

This effect was removed in SADX, possibly because the Gamecube TEV underwater shader took its place. The PC version has neither the shader nor the tint effect.

The exact parameters of the effect are unknown, but a very similar look can be achieved by applying a Soft Light filter with the color of #3f5bd3 and alpha of 50%.

Sample, SA1 at the bottom
SA1 at the bottom

@SonicFreak94

This comment has been minimized.

Show comment
Hide comment
@SonicFreak94

SonicFreak94 Dec 25, 2016

Owner

This will require figuring out how an entity knows that it's under water. It's very likely that the way characters are notified of their under water status will be the same for the camera. Much like characters, the camera is an entity with collision, and it uses the same entity structure (EntityData1).

A good place to start would be to see what writes to the underwater timer for any character in particular. There will most likely be a condition check just before the write which can be investigated further. Following that lead upward in the code should lead to something common between characters and the camera.

Owner

SonicFreak94 commented Dec 25, 2016

This will require figuring out how an entity knows that it's under water. It's very likely that the way characters are notified of their under water status will be the same for the camera. Much like characters, the camera is an entity with collision, and it uses the same entity structure (EntityData1).

A good place to start would be to see what writes to the underwater timer for any character in particular. There will most likely be a condition check just before the write which can be investigated further. Following that lead upward in the code should lead to something common between characters and the camera.

@RinMaru

This comment has been minimized.

Show comment
Hide comment
@RinMaru

RinMaru Feb 16, 2017

Be nice to get the GC water effects too

RinMaru commented Feb 16, 2017

Be nice to get the GC water effects too

@KNNSpeed

This comment has been minimized.

Show comment
Hide comment
@KNNSpeed

KNNSpeed Feb 16, 2017

You mean the ripple effect?

image

(Image from here: http://forums.sonicretro.org/?showtopic=33390)

KNNSpeed commented Feb 16, 2017

You mean the ripple effect?

image

(Image from here: http://forums.sonicretro.org/?showtopic=33390)

@RinMaru

This comment has been minimized.

Show comment
Hide comment
@RinMaru

RinMaru Feb 16, 2017

yes THAT lol i always loved that and it's the only real improvement i cared about in DX

RinMaru commented Feb 16, 2017

yes THAT lol i always loved that and it's the only real improvement i cared about in DX

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Mar 6, 2017

On the GameCube version, the ripple effect texture is there. It's this texture.
https://s13.postimg.org/yn6r92ojb/salt_tev01_01.png

also known as “tex1_256x256_m_f94822877d9452de_14”
on Dolphin…

When disabling the texture (by making texture completely black),
the ripple effect turns off.

Note that this specific texture is not for the shaky screen nor ripple look during underwater. Never was a fan of the shakiness while underwater anyway, but I still approve the ripple look.

Tried replacing salt_tev01_01.png with it, and nothing. Hope someone out there can figure a way to add the two water effects above back into the game…if even possible. Ripple improves the look of water so much more, especially for the overly transparent water of DXStylesWater. Imagine this effect with Dreamcast water that was brought back into Emerald Coast just recently? Only one can dream. That'd look too good.

ghost commented Mar 6, 2017

On the GameCube version, the ripple effect texture is there. It's this texture.
https://s13.postimg.org/yn6r92ojb/salt_tev01_01.png

also known as “tex1_256x256_m_f94822877d9452de_14”
on Dolphin…

When disabling the texture (by making texture completely black),
the ripple effect turns off.

Note that this specific texture is not for the shaky screen nor ripple look during underwater. Never was a fan of the shakiness while underwater anyway, but I still approve the ripple look.

Tried replacing salt_tev01_01.png with it, and nothing. Hope someone out there can figure a way to add the two water effects above back into the game…if even possible. Ripple improves the look of water so much more, especially for the overly transparent water of DXStylesWater. Imagine this effect with Dreamcast water that was brought back into Emerald Coast just recently? Only one can dream. That'd look too good.

@RinMaru

This comment has been minimized.

Show comment
Hide comment
@RinMaru

RinMaru Mar 6, 2017

May have to dig into the code of the GC version to actually get the ripple to work unless some of it is left over in the PC version but that will be someone elses job since i dont know code i can only look around textures and test builds of mods

RinMaru commented Mar 6, 2017

May have to dig into the code of the GC version to actually get the ripple to work unless some of it is left over in the PC version but that will be someone elses job since i dont know code i can only look around textures and test builds of mods

@SonicFreak94

This comment has been minimized.

Show comment
Hide comment
@SonicFreak94

SonicFreak94 Mar 6, 2017

Owner

The distortion unfortunately won't just appear by adding the texture back in (as SADX PC actually has this and one additional texture still ingame). Implementing it again would be relatively simple though.

What we're looking at with that texture is a bump map (or a height map), where the brighter white the pixel is, the more extreme the bump is. The idea is to use this to offset texture coordinates before sampling pixels in the back buffer (what has already been rendered) which gives the appearance of distortion.

Here's a simple overview of the process of applying the distortion:

  • Render the scene, holding back water mesh until everything else has been rendered.
  • Copy the scene to a texture.
  • Begin rendering the water, taking note of the water's texture coordinates.
  • Note the screen coordinates for every pixel that the water covers.
  • Use the water's texture coordinates to pull a color from the bump map.
  • Offset the screen coordinates by the color taken from the bump map.
  • Using the offset screen coordinates, take a pixel from the scene texture, and render the final result.

A normal map would be more effective in this case, but bump maps can be easily converted. Additionally, the depth buffer (z-buffer) can be (ab)used to reduce some artifacting that's present on the GameCube, such as the pseudo-reflection of Sonic visible when standing in front of the water. It would be as simple as verifying that the depth is greater than the surface of the water before applying the distortion.

Owner

SonicFreak94 commented Mar 6, 2017

The distortion unfortunately won't just appear by adding the texture back in (as SADX PC actually has this and one additional texture still ingame). Implementing it again would be relatively simple though.

What we're looking at with that texture is a bump map (or a height map), where the brighter white the pixel is, the more extreme the bump is. The idea is to use this to offset texture coordinates before sampling pixels in the back buffer (what has already been rendered) which gives the appearance of distortion.

Here's a simple overview of the process of applying the distortion:

  • Render the scene, holding back water mesh until everything else has been rendered.
  • Copy the scene to a texture.
  • Begin rendering the water, taking note of the water's texture coordinates.
  • Note the screen coordinates for every pixel that the water covers.
  • Use the water's texture coordinates to pull a color from the bump map.
  • Offset the screen coordinates by the color taken from the bump map.
  • Using the offset screen coordinates, take a pixel from the scene texture, and render the final result.

A normal map would be more effective in this case, but bump maps can be easily converted. Additionally, the depth buffer (z-buffer) can be (ab)used to reduce some artifacting that's present on the GameCube, such as the pseudo-reflection of Sonic visible when standing in front of the water. It would be as simple as verifying that the depth is greater than the surface of the water before applying the distortion.

@RinMaru

This comment has been minimized.

Show comment
Hide comment
@RinMaru

RinMaru Mar 7, 2017

@SonicFreak94 sounds like you got that figured out ^^ dont mind me but im feeling giddy atm the fact you guys are making sadx better so we can exp it the way it should is the stuff of dreams and to think soon that a dreamcast emulator will not be needed to exp the best version soon.

RinMaru commented Mar 7, 2017

@SonicFreak94 sounds like you got that figured out ^^ dont mind me but im feeling giddy atm the fact you guys are making sadx better so we can exp it the way it should is the stuff of dreams and to think soon that a dreamcast emulator will not be needed to exp the best version soon.

@toxicdumbster

This comment has been minimized.

Show comment
Hide comment
@toxicdumbster

toxicdumbster Jul 23, 2017

Figures why DX water looked clear as glass. Distortion implementation should be meant for the SADXStyleWater. That being said I still don’t get why most youtubers use DX water in a Dreamcast conversion mod by default. To each their own.

toxicdumbster commented Jul 23, 2017

Figures why DX water looked clear as glass. Distortion implementation should be meant for the SADXStyleWater. That being said I still don’t get why most youtubers use DX water in a Dreamcast conversion mod by default. To each their own.

@RinMaru

This comment has been minimized.

Show comment
Hide comment
@RinMaru

RinMaru Jul 23, 2017

some think the water looks better in DX but it only really looked good with the bump mapping effect and I think the DC water would look better with it and if not still would be nice to have lol

RinMaru commented Jul 23, 2017

some think the water looks better in DX but it only really looked good with the bump mapping effect and I think the DC water would look better with it and if not still would be nice to have lol

@PiKeyAr

This comment has been minimized.

Show comment
Hide comment
@PiKeyAr

PiKeyAr Nov 24, 2017

Collaborator

I've been poking around and I found the function that determines whether the character is underwater: sub_49F1A0. All playable characters plus Tikal and Eggman call it, and disabling the function makes the character ignore water completely.

The function takes two arguments: EntityData1* and something that looks like (int)&EntityData2->field_1DC.

This may not be exactly what is needed for the camera, but I think starting from here may help.

Collaborator

PiKeyAr commented Nov 24, 2017

I've been poking around and I found the function that determines whether the character is underwater: sub_49F1A0. All playable characters plus Tikal and Eggman call it, and disabling the function makes the character ignore water completely.

The function takes two arguments: EntityData1* and something that looks like (int)&EntityData2->field_1DC.

This may not be exactly what is needed for the camera, but I think starting from here may help.

@PiKeyAr

This comment has been minimized.

Show comment
Hide comment
@PiKeyAr

PiKeyAr May 1, 2018

Collaborator

Near the end of Camera_DisplayB_() there's a check that looks like this:

if ( p2.y < 0.0 || p2.y > 480.0 )
        {
          njPushMatrix(0);
          njProjectScreen(0, &v13, &p2);
          njPopMatrix(1u);
        }

The if condition is triggered whenever the camera is underwater. I hooked this to recreate a Dreamcast-like overlay - ended up using the color 0x1E0008FF with an additive effect as that looked the closest to the original and it's probably how the game does it anyway.

Before:
image
After:
image

Shader shenanigans aside I think this is enough to add distortion effects for when the camera is underwater. The actual effect and what to do with stuff that gets distorted below the water surface I don't know, but I hope this is a start.

Collaborator

PiKeyAr commented May 1, 2018

Near the end of Camera_DisplayB_() there's a check that looks like this:

if ( p2.y < 0.0 || p2.y > 480.0 )
        {
          njPushMatrix(0);
          njProjectScreen(0, &v13, &p2);
          njPopMatrix(1u);
        }

The if condition is triggered whenever the camera is underwater. I hooked this to recreate a Dreamcast-like overlay - ended up using the color 0x1E0008FF with an additive effect as that looked the closest to the original and it's probably how the game does it anyway.

Before:
image
After:
image

Shader shenanigans aside I think this is enough to add distortion effects for when the camera is underwater. The actual effect and what to do with stuff that gets distorted below the water surface I don't know, but I hope this is a start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment