Cycles microdisplacement: Move call to tessellate() from addon to Cycles
By calling `tessellate()` from the mesh manager in Cycles we can do pre/post processing or even threaded tessellation without concerning client side code with the details.
This commit is contained in:
@@ -806,7 +806,10 @@ static void create_subd_mesh(Scene *scene,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set subd params */
|
/* set subd params */
|
||||||
SubdParams sdparams(mesh);
|
if(!mesh->subd_params) {
|
||||||
|
mesh->subd_params = new SubdParams(mesh);
|
||||||
|
}
|
||||||
|
SubdParams& sdparams = *mesh->subd_params;
|
||||||
|
|
||||||
PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");
|
PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");
|
||||||
|
|
||||||
@@ -816,10 +819,6 @@ static void create_subd_mesh(Scene *scene,
|
|||||||
scene->camera->update();
|
scene->camera->update();
|
||||||
sdparams.camera = scene->camera;
|
sdparams.camera = scene->camera;
|
||||||
sdparams.objecttoworld = get_transform(b_ob.matrix_world());
|
sdparams.objecttoworld = get_transform(b_ob.matrix_world());
|
||||||
|
|
||||||
/* tesselate */
|
|
||||||
DiagSplit dsplit(sdparams);
|
|
||||||
mesh->tessellate(&dsplit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sync */
|
/* Sync */
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "osl_globals.h"
|
#include "osl_globals.h"
|
||||||
|
|
||||||
|
#include "subd_split.h"
|
||||||
#include "subd_patch_table.h"
|
#include "subd_patch_table.h"
|
||||||
|
|
||||||
#include "util_foreach.h"
|
#include "util_foreach.h"
|
||||||
@@ -172,6 +173,7 @@ Mesh::Mesh()
|
|||||||
num_ngons = 0;
|
num_ngons = 0;
|
||||||
|
|
||||||
subdivision_type = SUBDIVISION_NONE;
|
subdivision_type = SUBDIVISION_NONE;
|
||||||
|
subd_params = NULL;
|
||||||
|
|
||||||
patch_table = NULL;
|
patch_table = NULL;
|
||||||
}
|
}
|
||||||
@@ -180,6 +182,7 @@ Mesh::~Mesh()
|
|||||||
{
|
{
|
||||||
delete bvh;
|
delete bvh;
|
||||||
delete patch_table;
|
delete patch_table;
|
||||||
|
delete subd_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::resize_mesh(int numverts, int numtris)
|
void Mesh::resize_mesh(int numverts, int numtris)
|
||||||
@@ -1659,6 +1662,42 @@ void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tessellate meshes that are using subdivision */
|
||||||
|
size_t total_tess_needed = 0;
|
||||||
|
foreach(Mesh *mesh, scene->meshes) {
|
||||||
|
if(mesh->need_update &&
|
||||||
|
mesh->subdivision_type != Mesh::SUBDIVISION_NONE &&
|
||||||
|
mesh->num_subd_verts == 0 &&
|
||||||
|
mesh->subd_params)
|
||||||
|
{
|
||||||
|
total_tess_needed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
foreach(Mesh *mesh, scene->meshes) {
|
||||||
|
if(mesh->need_update &&
|
||||||
|
mesh->subdivision_type != Mesh::SUBDIVISION_NONE &&
|
||||||
|
mesh->num_subd_verts == 0 &&
|
||||||
|
mesh->subd_params)
|
||||||
|
{
|
||||||
|
string msg = "Tessellating ";
|
||||||
|
if(mesh->name == "")
|
||||||
|
msg += string_printf("%u/%u", (uint)(i+1), (uint)total_tess_needed);
|
||||||
|
else
|
||||||
|
msg += string_printf("%s %u/%u", mesh->name.c_str(), (uint)(i+1), (uint)total_tess_needed);
|
||||||
|
|
||||||
|
progress.set_status("Updating Mesh", msg);
|
||||||
|
|
||||||
|
DiagSplit dsplit(*mesh->subd_params);
|
||||||
|
mesh->tessellate(&dsplit);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if(progress.get_cancel()) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Update images needed for true displacement. */
|
/* Update images needed for true displacement. */
|
||||||
bool true_displacement_used = false;
|
bool true_displacement_used = false;
|
||||||
bool old_need_object_flags_update = false;
|
bool old_need_object_flags_update = false;
|
||||||
@@ -1719,7 +1758,7 @@ void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scen
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Update bvh. */
|
/* Update bvh. */
|
||||||
size_t i = 0, num_bvh = 0;
|
size_t num_bvh = 0;
|
||||||
foreach(Mesh *mesh, scene->meshes) {
|
foreach(Mesh *mesh, scene->meshes) {
|
||||||
if(mesh->need_update && mesh->need_build_bvh()) {
|
if(mesh->need_update && mesh->need_build_bvh()) {
|
||||||
num_bvh++;
|
num_bvh++;
|
||||||
@@ -1728,6 +1767,7 @@ void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scen
|
|||||||
|
|
||||||
TaskPool pool;
|
TaskPool pool;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
foreach(Mesh *mesh, scene->meshes) {
|
foreach(Mesh *mesh, scene->meshes) {
|
||||||
if(mesh->need_update) {
|
if(mesh->need_update) {
|
||||||
pool.push(function_bind(&Mesh::compute_bvh,
|
pool.push(function_bind(&Mesh::compute_bvh,
|
||||||
|
@@ -39,6 +39,7 @@ class Progress;
|
|||||||
class Scene;
|
class Scene;
|
||||||
class SceneParams;
|
class SceneParams;
|
||||||
class AttributeRequest;
|
class AttributeRequest;
|
||||||
|
struct SubdParams;
|
||||||
class DiagSplit;
|
class DiagSplit;
|
||||||
struct PackedPatchTable;
|
struct PackedPatchTable;
|
||||||
|
|
||||||
@@ -156,6 +157,8 @@ public:
|
|||||||
|
|
||||||
array<SubdEdgeCrease> subd_creases;
|
array<SubdEdgeCrease> subd_creases;
|
||||||
|
|
||||||
|
SubdParams *subd_params;
|
||||||
|
|
||||||
vector<Shader*> used_shaders;
|
vector<Shader*> used_shaders;
|
||||||
AttributeSet attributes;
|
AttributeSet attributes;
|
||||||
AttributeSet curve_attributes;
|
AttributeSet curve_attributes;
|
||||||
|
@@ -22,6 +22,7 @@ set(SRC
|
|||||||
set(SRC_HEADERS
|
set(SRC_HEADERS
|
||||||
subd_dice.h
|
subd_dice.h
|
||||||
subd_patch.h
|
subd_patch.h
|
||||||
|
subd_patch_table.h
|
||||||
subd_split.h
|
subd_split.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user