Author Topic: Corona Sky Material orientation  (Read 2569 times)

2017-09-12, 03:17:15

microwerx

  • Users
  • *
  • Posts: 4
    • View Profile
Howdy,

I'm using Corona standalone renderer to render some ground truth images for a new graphics technique i'm working on. However, I'm trying to figure out the best way of converting from standard OpenGL right handed coordinates to what's used in Corona. If I supply my camera matrix and world matrices for my objects, it's fine (that is, I get what I get in my 3d program). However, it doesn't match the coordinate system used by the physically based sky. So, the sky is rotated 90 degrees on the horizon because it thinks Z is up.

So, if I use my overhead coordinates for my Sun vector (0, 1, 0), I get sunset and if I use Z-up coordinates like (0, 0, 1) I get noon. So, here's the issue. If you supply an identity matrix for a perspective camera in the SCN file, then the sky does not render as expected and you have to use a different transformation matrix like [ 1 0 0 0 ] [ 0 0 1 0 ] [ 0 1 0 0 ] [ 0 0 0 1 ] for the camera for the sky to look correct.

Is this a bug, or is there a setting to have the sky behave as if in a right handed coordinate system with Y up?

2017-09-12, 03:27:11
Reply #1

microwerx

  • Users
  • *
  • Posts: 4
    • View Profile
For reference, here's what I'm using for a test render:

<mtlLib>
   <mapDefinition name="Skylight_environment">
   <map class = "Sky" originalMapClass = "SkyShader">
      <groundColor>0.471 0.373 0.251 </groundColor>
      <mode>hosek</mode>
   </map>
   </mapDefinition>
</mtlLib>

----

<scene>

<mtllib>export_corona_sky.mtl</mtllib>

<camera class="perspective">
   <!-- right handed coordinate system
   This faces the ground
   -->
   <tm>1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1</tm>

   <!-- Z up coordinate system
   This faces the horizon
   -->
   <!-- <tm>1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1</tm> -->

   <fov>90 </fov>
</camera>

<sun>
   <dirTo>0 0 1</dirTo>
   <turbidity>4</turbidity>
</sun>

<environment>1 1 1<map class="Reference">Skylight_environment</map></environment>

</scene>
« Last Edit: 2017-09-12, 04:46:57 by microwerx »

2017-09-12, 11:15:16
Reply #2

Ondra

  • Administrator
  • Active Users
  • *****
  • Posts: 9048
  • Turning coffee to features since 2009
    • View Profile
Hi,
I think the best solution would be for us to add up vector into the sky shader, I will put it on our TODO
Rendering is magic.How to get minidumps for crashed/frozen 3ds Max | Sorry for short replies, brief responses = more time to develop Corona ;)

2017-09-12, 16:07:18
Reply #3

microwerx

  • Users
  • *
  • Posts: 4
    • View Profile
I like it. Thanks!

2017-09-16, 03:18:56
Reply #4

microwerx

  • Users
  • *
  • Posts: 4
    • View Profile
So my current work around is to do a little matrix math.

For my camera matrix, I fix it by multiplying my camera matrix by a -PI/2 x axis rotation ([1 0 0 0] [0 0 1 0] [0 -1 0 0] [0 0 0 1]):

fixedCameraMatrix = cameraMatrix * MakeRotation(-PI/2, 1, 0, 0); // write to <camera></camera>

And then for all my world transformation for each geometryGroup I premultiply a +PI/2 x axis rotation ([1 0 0 0] [0 0 -1 0] [0 1 0 0] [0 0 0 1]).

fixedWorldMatrix = MakeRotation(PI/2, 1, 0, 0) * worldMatrix; // write to <geometryGroup><instance><transform></transform></instance></geometryGroup>

And finally for my sun vector, I used (X, -Z, Y) to place it in the right position.