diff --git a/bin/assets/dragon/materials.mtl b/bin/assets/dragon/materials.mtl deleted file mode 100644 index 85b3523..0000000 --- a/bin/assets/dragon/materials.mtl +++ /dev/null @@ -1,19 +0,0 @@ -newmtl et::dir -direction 1 2.0 0.5 -color 2 2 2 -angular_diameter 1.0 - -newmtl dragon -material class plastic -int_ior sapphire -Kd 0.6 0.6 0.6 -Pr 0.03 -subsurface 2.0 0.5 0.125 - -newmtl plane -material class diffuse -Kd 0.5 0.5 0.5 - -newmtl no-light0 -material class diffuse -Ke 7 7 7 diff --git a/bin/assets/dragon/sss_dragon.json b/bin/assets/dragon/sss_dragon.json index c202119..2e8b097 100644 --- a/bin/assets/dragon/sss_dragon.json +++ b/bin/assets/dragon/sss_dragon.json @@ -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 + } +} \ No newline at end of file diff --git a/bin/assets/dragon/sss_dragon.obj.materials b/bin/assets/dragon/sss_dragon.obj.materials new file mode 100644 index 0000000..83f5af3 --- /dev/null +++ b/bin/assets/dragon/sss_dragon.obj.materials @@ -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 + diff --git a/bin/assets/empty/empty.json b/bin/assets/empty/empty.json deleted file mode 100644 index 3c29cd2..0000000 --- a/bin/assets/empty/empty.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "geometry" : "empty.obj", - "camera" : { - "viewport" : [1024, 1024], - "origin" : [5.0, 5.0, 5.0], - "fov" : 54.0 - } -} \ No newline at end of file diff --git a/bin/assets/feature-test/feature-test.json b/bin/assets/feature-test/feature-test.json index 570cf5d..6627075 100644 --- a/bin/assets/feature-test/feature-test.json +++ b/bin/assets/feature-test/feature-test.json @@ -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 } } \ No newline at end of file diff --git a/bin/assets/feature-test/materials.mtl b/bin/assets/feature-test/materials.mtl index 38c429c..81822ee 100644 --- a/bin/assets/feature-test/materials.mtl +++ b/bin/assets/feature-test/materials.mtl @@ -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 diff --git a/bin/assets/feature-test/reference.png b/bin/assets/feature-test/reference.png deleted file mode 100644 index f1c2699..0000000 Binary files a/bin/assets/feature-test/reference.png and /dev/null differ diff --git a/bin/assets/sds-test/sds-test.mtl b/bin/assets/sds-test/sds-test.mtl index 2c1931c..0e57f7c 100644 --- a/bin/assets/sds-test/sds-test.mtl +++ b/bin/assets/sds-test/sds-test.mtl @@ -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 @@ -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 diff --git a/bin/assets/spoons/materials.mtl b/bin/assets/spoons/materials.mtl index 2167ab3..679a95c 100644 --- a/bin/assets/spoons/materials.mtl +++ b/bin/assets/spoons/materials.mtl @@ -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 @@ -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 diff --git a/sources/etx/render/host/scene_loader.cxx b/sources/etx/render/host/scene_loader.cxx index ab0d0b3..2c9f64e 100644 --- a/sources/etx/render/host/scene_loader.cxx +++ b/sources/etx/render/host/scene_loader.cxx @@ -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"); } @@ -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; @@ -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)) { diff --git a/sources/etx/render/shared/material.hxx b/sources/etx/render/shared/material.hxx index fb44075..4dcada2 100644 --- a/sources/etx/render/shared/material.hxx +++ b/sources/etx/render/shared/material.hxx @@ -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;