Vargol / PhotonPump

A .net port of Sunflow
GNU General Public License v2.0
3 stars 4 forks source link

Texture baking example #2

Open Rbn3D opened 8 years ago

Rbn3D commented 8 years ago

Hello.

I'm trying to figure out how the parameter "optionsName" of SunflowApi.Render() should look like to bake texture for a mesh of the scene. I have everything already set up, just don't know how optionsName syntax should be.

Thanks.

Vargol commented 8 years ago

On 29/07/2016 20:41, Rubén Vallejo wrote:

Hello.

I'm trying to figure out how the parameter "optionsName" of SunflowApi.Render() should look like to bake texture for a mesh of the scene. I have everything already set up, just don't know how optionsName syntax should be.

Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Vargol/PhotonPump/issues/2, or mute the thread https://github.com/notifications/unsubscribe-auth/AAD1lFxMv7gNUXsn3JcdxHMOTTa6m0Wkks5qaldmgaJpZM4JYgnI.

Hi,

It's the 'name' you gave to the options, if you've used them.

For example If you've used any parameters them you've probably done something like

Sunflow Wiki PDF parameter("bucket.order","hilbert"); parameter("bucket.size",32); parameter("baking.instance","cake.instance");

instance("cake.instance","cake");

options(SunflowAPI.DEFAULT_OPTIONS);

That sets the options name to the value of SunflowAPI.DEFAULT_OPTIONS which is publicstaticstringDEFAULT_OPTIONS="::options";

It that case the render call would be something like

render(SunflowAPI.DEFAULT_OPTIONS,newFileDisplay("output.png"));

or

render("::options",newFileDisplay("output.png"));

If you haven't used any options then again use SunflowAPI.DEFAULT_OPTIONS

https://github.com/Vargol/PhotonPump/blob/master/SunflowSharp/RealtimeBenchmark.cs is a decent example of using the the API to render.

Dave

Rbn3D commented 8 years ago

Ok thanks, now it's working, this can be closed

Rbn3D commented 8 years ago

EDIT:

I were able to set the options and render, but I'm not getting any output. No image file was saved to disk after render.

Here is the code i'm using to render:

`

   var path = "C:\output.exr";

    Debug.Log("Saving lightmap to \"" + path + "\"");

    api.render(SunflowAPI.DEFAULT_OPTIONS, new FileDisplay(path));

` Here are the renderer messages:

[API] Building scene instance list for rendering ... [API] Building scene light list for rendering ... [SCENE] Scene stats: [SCENE] * Infinite instances: 1 [SCENE] * Instances: 1 [SCENE] * Primitives: 200 [SCENE] * Instance accel: auto [ACCEL] Building null acceleration structure... [SCENE] * Scene bounds: (-5, -1.110223E-16, -5) to (5, 1.110223E-16, 5) [SCENE] * Scene center: (0, 0, 0) [SCENE] * Scene diameter: 14.14214 [SCENE] * Lightmap bake: off [LIGHT] Irradiance cache settings: [LIGHT] * Samples: 32 [LIGHT] * Tolerance: 1 [LIGHT] * Spacing: 0.10 to 0.90 [LIGHT] Light Server stats: [LIGHT] * Light sources found: 1 [LIGHT] * Light samples: 1 [LIGHT] * Max raytrace depth: [LIGHT] - Diffuse 1 [LIGHT] - Reflection 4 [LIGHT] - Refraction 4 [LIGHT] * GI engine irr-cache [LIGHT] * Caustics: none [LIGHT] * Shader override: [LIGHT] * Photon override: False [LIGHT] * Build time: 32ms [SCENE] Rendering ... [BCKT] Bucket renderer settings: [BCKT] * Resolution: 1024x1024 [BCKT] * Bucket size: 32 [BCKT] * Number of buckets: 32x32 [BCKT] * Anti-aliasing: 1 sample -> 16 samples (adaptive) [BCKT] * Rays per sample: 4 [BCKT] * Subpixel jitter: off [BCKT] * Contrast threshold: 0.2 [BCKT] * Filter type: box [BCKT] * Filter size: 1 pixels [ACCEL] Building null acceleration structure... [ACCEL] Building kdtree acceleration structure... [BCKT] Render time: 0:00:18.4 [SCENE] Raytracing stats: [SCENE] * Rays traced: (per pixel) (per eye ray) (percentage) [SCENE] eye 4460544 4.25 1.00 1.00 [SCENE] total 4460544 4.25 1.00 1.00 [SCENE] Done.

Everything seems ok, but no file is saved to disk.

Also, this line says that lightmap baking is off:

[SCENE] * Lightmap bake: off

But I set the options to bake here:

` var meshName = "mesh" + meshR.GetInstanceID();

api.parameter("baking.instance", meshName+".instance"); api.instance(meshName + ".instance", meshName); `

Do I need to set any additional parameters?

Vargol commented 8 years ago

Try this two the other way around... api.parameter("baking.instance", meshName+".instance"); api.instance(meshName + ".instance", meshName);

e.g.

api.instance(meshName + ".instance", meshName); api.parameter("baking.instance", meshName+".instance");

[SCENE] * Lightmap bake: off means it hasn't set the baking instance.

Over all you should have something like

/* create a sphere */ var name = "mysphere"; api.geometry(name, "sphere"); api.parameter("transform", Matrix4.translation(0.0f, 0.0f, 0.0f).multiply(Matrix4.scale(0.5f))); api.parameter("shaders", shaders); if (modifiers != null) api.parameter("modifiers", modifiers);

/* create an instance of the sphere */ api.instance(name + ".instance", name);

/* set that instance to bake */ api.parameter("baking.instance", name+".instance");

api.options(api.DEFAULT_OPTIONS);

Rbn3D commented 8 years ago

Regular meshes (triangle meshes) are allowed too?

Vargol commented 8 years ago

Actually looking through the source I think triangle meshes and ITesselatable objects are the only things that work.

The only bit of Sunflow documentation I could find about it added this....

1) make sure the object you want to bake textures for has non-overlapping UV coordinates that fall in the [0,1] square.