Author Topic: Viewport with transparent background  (Read 1454 times)

jortegano

  • Newbie
  • *
  • Posts: 9
    • View Profile
Viewport with transparent background
« on: April 26, 2016, 02:13:48 PM »
Hi, I'm using the World Political Map 2D edition to render a map inside a scene with several fixed position gameObjects. To do Zoom in/out on the map without the map intersecting other gameObjects I'm using a viewport, but I need the map to have a transparent background in order to see my fixed background; when I switch off "Show Earth" option I just get a solid black background. Is there anyway to achieve what I want with a viewport? Thanks for your help.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5390
    • View Profile
Re: Viewport with transparent background
« Reply #1 on: April 26, 2016, 03:22:36 PM »
The viewport itself is a mesh with an assigned material. The shader of this material needs to be modified or replaced to support transparency. I will check this out tomorrow.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5390
    • View Profile
Re: Viewport with transparent background
« Reply #2 on: April 27, 2016, 12:40:37 AM »
Hi!

Right. To make the viewport transparent, we need to change the Viewport material and apply a small code change.
Follow these steps:

- Edit WorldMap2DPrivate.cs around line 1243, and replace the line:

Code
cam.backgroundColor = new Color(0,0,0,1);

with

Code
cam.backgroundColor = new Color(0,0,0,0);

- Locate "ViewportMaterial" material inside Resources/WPMF/Materials and change the shader to Unlit/Transparent CutOut.

That's it.

We've changed the code above for future releases, but not the material. You should duplicate the viewport material and use that copy in your scene's gameobject so future updates don't replace it.

jortegano

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Viewport with transparent background
« Reply #3 on: April 27, 2016, 03:05:58 PM »
Hi, thanks for your help. The solution provided worked perfectly.