Skip to content

Commit

Permalink
Saving scene (intermediate results)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-rieznik committed Feb 5, 2023
1 parent a9cad67 commit 5690e9a
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 73 deletions.
19 changes: 0 additions & 19 deletions bin/assets/dragon/materials.mtl

This file was deleted.

37 changes: 27 additions & 10 deletions bin/assets/dragon/sss_dragon.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
{
"geometry" : "sss_dragon.obj",
"materials" : "materials.mtl",
"camera" : {
"viewport" : [1080.0, 1080.0],
"origin" : [14.0, 15.0, -12.0],
"target" : [-1.5, 1.0, 5.0],
"focal-length" : 14.0,
"lens-radius" : 0.0
}
}
"geometry": "sss_dragon.obj",
"materials": "sss_dragon.obj.materials",
"camera": {
"viewport": [
1080,
1080
],
"origin": [
18.48695182800293,
18.065654754638672,
-14.235601425170898
],
"target": [
17.837646484375,
17.565496444702148,
-13.662675857543945
],
"up": [
-0.37503513693809509,
0.86593389511108398,
0.3309185802936554
],
"lens-radius": 0.0,
"focal-distance": 0.0,
"focal-length": 49.999992370605469
}
}
28 changes: 28 additions & 0 deletions bin/assets/dragon/sss_dragon.obj.materials
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
newmtl et::dir
color 1.901 2.000 2.178
direction 0.696 0.525 0.489
angular_diameter 0.573

newmtl dragon
material class plastic
Pr 0.103
Kd 0.449 0.449 0.449
Ks 1.000 1.000 1.000
Kt 1.000 1.000 1.000
subsurface 2.000 0.500 0.125

newmtl plane
material class diffuse
Pr 0.000
Kd 0.500 0.500 0.500
Ks 1.000 1.000 1.000
Kt 1.000 1.000 1.000

newmtl no-light0
material class diffuse
Pr 0.000
Kd 1.000 1.000 1.000
Ks 1.000 1.000 1.000
Kt 1.000 1.000 1.000
Ke 7.000 7.000 7.000

8 changes: 0 additions & 8 deletions bin/assets/empty/empty.json

This file was deleted.

6 changes: 3 additions & 3 deletions bin/assets/feature-test/feature-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"geometry" : "feature-test.obj",
"materials" : "materials.mtl",
"camera" : {
"origin" : [0.0, 0.0, 11.0],
"origin" : [0.0, 0.0, 9.75],
"target" : [0.0, 0.0, 0.0],
"viewport" : [1280, 640],
"fov" : 26.99
"viewport" : [1920, 720],
"focal-length" : 85.0
}
}
38 changes: 19 additions & 19 deletions bin/assets/feature-test/materials.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@

newmtl et::dir
direction 1 1 1
color nblackbody 6500.0
color nblackbody 6500.0 scale 0.5

newmtl et::env
color nblackbody 12000.0
color nblackbody 12000.0 scale 0.1

newmtl Light
emitter nblackbody 5800.0 scale 5.0
emitter nblackbody 4000.0 scale 4.0
Ke 1 1 1

newmtl Box
xmaterial class translucent
Kd 1.000000 1.000000 1.000000
material class diffuse
Kd 1.0 1.0 1.0

newmtl Right
xmaterial class translucent
Kd 0.000000 1.000000 0.000000
material class diffuse
Kd 0.0 1.0 0.0

newmtl Left
xmaterial class translucent
Kd 1.000000 0.000000 0.000000
material class diffuse
Kd 1.0 0.0 0.0

newmtl Sphere-1
material class msdielectric
material class dielectric
int_ior water
map_Kt ../textures/planet-color.png
Pr 0.25
Pr 0.1

newmtl Sphere-2
material class diffuse
material class subsurface
Kd 0.1 0.25 1.0
map_Kd ../textures/planet.png
subsurface 0.1 0.1 0.1

newmtl Sphere-3
material class msconductor
int_ior silver
normalmap image ../textures/square_floor_nor_gl_4k.png scale 1.0
map_Ks ../textures/square_floor_diff_4k.png
int_ior bronze
normalmap image ../textures/square_floor_nor_gl_4k.png scale 0.5

newmtl Font
material class msconductor
Pr 0.25
int_ior gold
newmtl font
material class subsurface
Kd 0.5 0.5 0.5
subsurface 0.2 0.1 0.05
Binary file removed bin/assets/feature-test/reference.png
Binary file not shown.
13 changes: 7 additions & 6 deletions bin/assets/sds-test/sds-test.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ newmtl et::env
image ../hdri/environment.exr

newmtl et::medium
id xglass
sigma_a 0.3333 0.16666 0.083333
id glass
sigma_a 0.1 0.125 0.15
sigma_s 0.0 0.0 0.0

newmtl plane
map_Kd ../textures/checkers_grayscale.png
Expand All @@ -17,14 +18,14 @@ int_ior water
int_medium glass

newmtl metal
material class msconductor
material class conductor
int_ior chrome
Pr 0.2

newmtl thorus
material class msconductor
int_ior gold
material class conductor
int_ior silver
ext_medium glass
Pr 0.25
xthinfilm range 100.0 1000.0 ior diamond image ../textures/film.png
thinfilm range 200.0 800.0 ior diamond image ../textures/film.png

9 changes: 5 additions & 4 deletions bin/assets/spoons/materials.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Material Count: 4

newmtl None
material class coating
material class plastic
int_ior diamond
Pr 0.25
Ks 0.08 0.08 0.08
Ks 1.0 0.9 0.5
map_Kd ../textures/square_floor_diff_4k.png
normalmap image ../textures/square_floor_nor_gl_4k.png scale 0.75
normalmap image ../textures/square_floor_nor_gl_4k.png scale 0.5

newmtl Golden_spoon
material class conductor
Expand All @@ -20,7 +21,7 @@ int_ior plastic
Pr 0.025
thinfilm range 600.0 800.0 ior 1.76 image ../textures/film.png

newmtl Woonde_spoon
newmtl woonde_spoon
material class conductor
int_ior copper
thinfilm range 100.0 360.0 ior 2.41 image ../textures/film.png
53 changes: 49 additions & 4 deletions sources/etx/render/host/scene_loader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,59 @@ void SceneRepresentation::write_materials(const char* filename) {
return;
}

for (const auto& em : _private->scene.emitters) {
switch (em.cls) {
case Emitter::Class::Directional: {
float3 e = em.emission.spectrum.to_xyz();
fprintf(fout, "newmtl et::dir\n");
fprintf(fout, "color %.3f %.3f %.3f\n", e.x, e.y, e.z);
fprintf(fout, "direction %.3f %.3f %.3f\n", em.direction.x, em.direction.y, em.direction.z);
fprintf(fout, "angular_diameter %.3f\n", em.angular_size * 180.0f / kPi);
fprintf(fout, "\n");
break;
}
case Emitter::Class::Environment: {
float3 e = em.emission.spectrum.to_xyz();
fprintf(fout, "newmtl et::env\n");
fprintf(fout, "color %.3f %.3f %.3f\n", e.x, e.y, e.z);
fprintf(fout, "\n");
break;
}
default:
break;
}
}

for (const auto& mmap : _private->material_mapping) {
const auto& material = _private->scene.materials[mmap.second];

// TODO : support anisotripic roughness
fprintf(fout, "newmtl %s\n", mmap.first.c_str());
fprintf(fout, "material class %s\n", material_class_to_string(material.cls));
// TODO : support anisotripic roughness
fprintf(fout, "Pr %.3f\n", sqrtf(0.5f * (sqr(material.roughness.x) + sqr(material.roughness.y))));
{
float3 kd = spectrum::xyz_to_rgb(material.diffuse.spectrum.to_xyz());
fprintf(fout, "Kd %.3f %.3f %.3f\n", kd.x, kd.y, kd.z);
}
{
float3 ks = spectrum::xyz_to_rgb(material.specular.spectrum.to_xyz());
fprintf(fout, "Ks %.3f %.3f %.3f\n", ks.x, ks.y, ks.z);
}
{
float3 kt = spectrum::xyz_to_rgb(material.transmittance.spectrum.to_xyz());
fprintf(fout, "Kt %.3f %.3f %.3f\n", kt.x, kt.y, kt.z);
}

if (material.emission.spectrum.is_zero() == false) {
float3 ke = spectrum::xyz_to_rgb(material.emission.spectrum.to_xyz());
fprintf(fout, "Ke %.3f %.3f %.3f\n", ke.x, ke.y, ke.z);
}

if (material.subsurface.scattering_distance.is_zero() == false) {
float3 ss = spectrum::xyz_to_rgb(material.subsurface.scattering_distance.to_xyz());
fprintf(fout, "subsurface %.3f %.3f %.3f\n", ss.x, ss.y, ss.z);
}

fprintf(fout, "\n");
}

Expand Down Expand Up @@ -1065,10 +1111,11 @@ void SceneRepresentationImpl::parse_obj_materials(const char* base_dir, const st
uint32_t material_index = material_mapping[material.name];
auto& mtl = materials[material_index];

mtl.cls = Material::Class::Diffuse;
mtl.diffuse.spectrum = rgb::make_reflectance_spd(to_float3(material.diffuse), spectrums());
mtl.specular.spectrum = rgb::make_reflectance_spd(to_float3(material.specular), spectrums());
mtl.transmittance.spectrum = rgb::make_reflectance_spd(to_float3(material.transmittance), spectrums());

mtl.emission.spectrum = rgb::make_reflectance_spd(to_float3(material.emission), spectrums());
mtl.roughness = {material.roughness, material.roughness};
mtl.metalness = material.metallic;

Expand Down Expand Up @@ -1106,8 +1153,6 @@ void SceneRepresentationImpl::parse_obj_materials(const char* base_dir, const st
i += 1;
}
}
} else {
mtl.cls = Material::Class::Diffuse;
}

if (get_param(material, "int_ior", data_buffer)) {
Expand Down
1 change: 1 addition & 0 deletions sources/etx/render/shared/material.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct ETX_ALIGNED Material {
SpectralImage diffuse;
SpectralImage specular;
SpectralImage transmittance;
SpectralImage emission;

uint32_t int_medium = kInvalidIndex;
uint32_t ext_medium = kInvalidIndex;
Expand Down

0 comments on commit 5690e9a

Please sign in to comment.