Author Topic: Accessing shoreline position data?  (Read 4088 times)

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Accessing shoreline position data?
« on: March 19, 2016, 10:31:22 PM »
Hi, I'm trying to get access to a collection of positions in world space of the occurrences of shorelines in a terrain, and since Suimono already seems to calculate them for its shoreline effects I was wondering if there is a way I can get access to the results of those calculations to use for myself rather than writing my own script to do the calculations again. Is this possible?
Thank you!

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #1 on: March 20, 2016, 10:04:47 AM »
Hi Fatalis,

This is an interesting question!  In Suimono the 'shorelineObject' gameobject handles the generatio of a top-down depth texture which gets passed to other Suimono components.  You can access this texture directly from the shorelineObject by accessing the RenderTexture that it generates, as per the example below...

Code: [Select]
#pragma strict

var shorelineTexture : RenderTexture;
private var shorelineRenderer : Renderer;

function Start () {
shorelineRenderer = GameObject.Find("shorelineObject").GetComponent(Renderer) as Renderer;
}

function LateUpdate () {
if (shorelineRenderer != null){
shorelineTexture = shorelineRenderer.sharedMaterial.GetTexture("_MainTex");
}
}

You can replace the "shorelineObject" above with whatever you've named it in your scene, and then use the captured shorelineTexture how you like.  To extrapolate world positions from this texture you should be able to cross reference the position/scale of your shorelineObject with the resolution and pixel positions in the captured RenderTexture.

This is the first time anyone has ever asked about doing this, so I hope the above helps!  Let me know if you have any more questions on this.

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #2 on: March 20, 2016, 02:39:19 PM »
Thank you for your reply! This helps greatly. My only other questions are how is the position of foam calculated as it seems to not need the shoreline object to appear? And I noticed in the Suimono 2.1.1 preview that the presence of a shoreline object in a scene greatly reduces fps and didn't really seem to change the behavior of the shoreline?

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #3 on: March 26, 2016, 05:09:18 AM »
After some fiddling I have gotten some shoreline waves working with the shoreline object, but no matter what I try the fps is terrible compared to have no active shoreline object. Any info as to why this is?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #4 on: March 26, 2016, 07:20:55 AM »
So are you saying that just by having a ShorelineObject in your scene that the fps performance is severely impacted?  The shorelineObject is supposed to only render once when the scene is first started (in order to capture the scene depth info for the shoreline generation), but it sounds like it might be continuously firing for some reason on your end...?


Edit: Actually I just double checked the 2.1.1 Preview code and there indeed might b an issue there with continuous rendering.  If you like I can email you a link to the latest dev version, which I think will improve your performance, and give you a few more options/settings on the shoreline component.  Unfortunately there's too many dependencies to do a simple patch for this, so you'd need to uninstall suimono before installing the latest.

These edits wll of course also be in the final dev version which I'm putting the finishing touches on this week and hope to have ready for everyone soon.

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #5 on: March 29, 2016, 02:13:11 AM »
Thanks! No hit to fps while using the shoreline object in the dev version. Another problem I have come across in the 2.1.1 preview that I didn't notice before is that Suimono actually significantly affects fps in scenes with lots of Speedtree foliage. I have been struggling with getting good performance with tens of thousands of Speedtree assets for a while, with Suimono always in the scene. It doesn't come up in the profiler, but when I disable Suimono in the scene, I go from having 30 fps to 60 fps in the most dense parts of the foliaged parts of the map, even though my camera is not actively looking at any part of the Suimono surface. Looking at the Suimono surface actually is less intensive. Any idea why this might be?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #6 on: March 29, 2016, 07:53:18 AM »
There's two possibilities here... dynamic reflections and the scene transparency function.  Each one is re-rendering your scene for it's own internal purposes, so when it comes to a heavy rendering obstacle (like lots of trees) you're getting an exponential fps hit.  The first thing I would recommend is perhaps lowering the reflection resolution/distance on your Suimono Surface to see if that eeks out more performance.  You can also reduce the transparency resolution/distance on the module.

The more extreme fix for this is to separate the trees onto a separate game layer from your terrain.  This involves duplicating the terrain, and then turning off tree/grass rendering on the original and simultaneously turning off terrain rendering on the copy, and placing it onto it's own game layer.  This allows you to determine individually whether the transparency/reflections will render the terrain, trees, or both.

And regardless of the above I would also try to optimize your speedtrees as much as possible, as they don't really come with the most optimized settings by default.  I'm speaking of adjusting the LOD thresholds, adjusting (or eliminating) their fading functions etc.  You can also simplify their colliders which can really help improve their general performance.

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #7 on: March 29, 2016, 06:52:19 PM »
I haven't tried everything you suggested as of yet, but turning off scene reflections does nothing to improve performance. I have to disable both the Suimono surface and module to get any type of performance increase.

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #8 on: March 29, 2016, 07:09:24 PM »
Hmm... perhaps try turning off transparency as well as caustics to see where the bottle neck is(?), before moving on to the more drastic scene/tree optimizations I posted about.

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #9 on: March 29, 2016, 07:47:02 PM »
Tried turning off everything in the module without disabling it, including transparency and caustics, no change in performance. I also halved the scale of my Suimono surface from 100 to 50 and moved it so that it was only where the beach part of my map is so that there was no surface "under" where I have forest. This did not change performance either.

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #10 on: April 03, 2016, 08:50:08 AM »
Hi Fatalis,
Sorry for the late reply.  I've been going through every component in the Suimono system doing cleanup and optimizations in anticipation of the final 2.1.1 release, and I believe I've isolated and corrected a few underground issues that may have been contributing to a bleed of performance here.

I've added a 'generation mode' option to the shoreline component so you can choose to run it once on play, or continuously (defaults to once).

I've also added some additional handling for background tasks in suimono (such as height calculation) to prevent these functions from firing unnecessarily.

I'm Just doing some final cleanup and testing today and tomorrow. The final version of 2.1.1 should be ready in the next few days.

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #11 on: April 04, 2016, 03:40:36 PM »
Sounds awesome, thanks for the update! Reading back though the thread I noticed I had a question that had been overlooked:

How is the position of foam calculated as it seems to not need the shoreline object to appear?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #12 on: April 04, 2016, 04:35:16 PM »
Foam is calculated based on view-dependent depth mask... essentially comparing depth values between the water surface and other objects in the scene... so you're right the normal foam doesn't need the shoreline object.  There is also a second foam specific to the shoreline effect (on top of shoreline waves) and this does require the shoreline object since it relies on the position/calculations from this object..

Fatalis

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Accessing shoreline position data?
« Reply #13 on: April 11, 2016, 01:30:22 PM »
Had another question for ya:

How much has Suimono_ShorelineObject changed from Suimono_flowGenerator ? I used to successfully access the shoreline Texture2D from flowGenerator, but now it seems like the "customDepthTex" field (which I'm assuming is analogous to "shoreMapTex" in flowGenerator) in Suimono_ShorelineGenerator is always null when I access it--why is this?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
    • View Profile
    • Tanuki Digital
Re: Accessing shoreline position data?
« Reply #14 on: April 11, 2016, 06:51:51 PM »
'customDepthTex' is only used for the manual texture function.  When shorelineObject is set to automatic mode (which is probably going to be most of the time for most people) the texture is generated by the 'cameraTools' component which is on the cam_LocalShore sub-object.  so instead of accessing shorelineObject, you should access a child of this object called 'cam_LocalShore'.  This object is normally hidden in the scene view, but you should still be able to access it through code regardless.

The texture variable you're looking for on this component is a RenderTexture called 'renderTexDiff'.

Here's an example that should work:

Code: [Select]
#pragma strict

var renderTex : RenderTexture;
private var renderComponent : cameraTools;

function Start () {
renderComponent = GameObject.Find("shorelineObject").transform.GetChild(0).GetComponent(cameraTools) as cameraTools;
}

function LateUpdate () {
if (renderComponent != null){
renderTex = renderComponent.renderTexDiff;
}
}

Note: The other method I posted at the top of this thread works as well, it gets the same texture data but reads it from the shader renderer instead.  I'm not sure if one is faster than the other.
« Last Edit: April 11, 2016, 07:00:49 PM by Chingwa »