Chaos Corona Forum

Chaos Corona for 3ds Max => [Max] I need help! => Topic started by: microwerx on 2017-09-12, 03:17:15

Title: Corona Sky Material orientation
Post by: microwerx on 2017-09-12, 03:17:15
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?
Title: Re: Corona Sky Material orientation
Post by: microwerx on 2017-09-12, 03:27:11
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>
Title: Re: Corona Sky Material orientation
Post by: Ondra on 2017-09-12, 11:15:16
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
Title: Re: Corona Sky Material orientation
Post by: microwerx on 2017-09-12, 16:07:18
I like it. Thanks!
Title: Re: Corona Sky Material orientation
Post by: microwerx on 2017-09-16, 03:18:56
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.