[Bf-blender-cvs] [4dd2d7b] temp-cycles-microdisplacement: Copy ptex faces to device memory
Mai Lavelle
noreply at git.blender.org
Fri Jun 24 19:26:42 CEST 2016
Commit: 4dd2d7b6191e8995d228617334458f084c65925d
Author: Mai Lavelle
Date: Mon Jun 20 06:43:35 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rB4dd2d7b6191e8995d228617334458f084c65925d
Copy ptex faces to device memory
Kernel now has access to ptex faces and ptex face mapping
===================================================================
M intern/cycles/kernel/geom/geom_triangle.h
M intern/cycles/render/mesh.cpp
M intern/cycles/render/mesh.h
===================================================================
diff --git a/intern/cycles/kernel/geom/geom_triangle.h b/intern/cycles/kernel/geom/geom_triangle.h
index 862f889..0d57d02 100644
--- a/intern/cycles/kernel/geom/geom_triangle.h
+++ b/intern/cycles/kernel/geom/geom_triangle.h
@@ -205,11 +205,15 @@ ccl_device float3 triangle_attribute_float3(KernelGlobals *kg, const ShaderData
}
}
+/* Patch index for triangle, -1 if not subdivision triangle */
+
ccl_device_inline int subd_triangle_patch(KernelGlobals *kg, const ShaderData *sd)
{
return __float_as_int(kernel_tex_fetch(__tri_vindex, ccl_fetch(sd, prim)).w);
}
+/* UV coords of triangle within patch */
+
ccl_device_inline void subd_triangle_patch_uv(KernelGlobals *kg, const ShaderData *sd, float2 uv[3])
{
float4 tri_vindex = kernel_tex_fetch(__tri_vindex, ccl_fetch(sd, prim));
@@ -224,24 +228,43 @@ ccl_device_inline void subd_triangle_patch_uv(KernelGlobals *kg, const ShaderDat
uv[2].y = kernel_tex_fetch(__tri_vnormal, __float_as_int(tri_vindex.z)).w;
}
-ccl_device_inline uint4 subd_triangle_patch_indices(KernelGlobals *kg, const ShaderData *sd)
+/* Vertex indices of patch */
+
+ccl_device_inline uint4 subd_triangle_patch_indices(KernelGlobals *kg, int patch)
{
- int patch = subd_triangle_patch(kg, sd);
return kernel_tex_fetch(__patches, patch);
}
+/* Originating face for patch */
+
+ccl_device_inline uint subd_triangle_patch_face(KernelGlobals *kg, int patch)
+{
+ return kernel_tex_fetch(__patches, patch+1).x;
+}
+
+/* Number of corners on originating face */
+
+ccl_device_inline uint subd_triangle_patch_num_corners(KernelGlobals *kg, int patch)
+{
+ return kernel_tex_fetch(__patches, patch+1).y;
+}
+
+/* Reading attributes on various subdivision triangle elements */
+
ccl_device float subd_triangle_attribute_float(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float *dx, float *dy)
{
+ int patch = subd_triangle_patch(kg, sd);
+
if(elem == ATTR_ELEMENT_FACE) {
if(dx) *dx = 0.0f;
if(dy) *dy = 0.0f;
- return kernel_tex_fetch(__attributes_float, offset + subd_triangle_patch(kg, sd));
+ return kernel_tex_fetch(__attributes_float, offset + subd_triangle_patch_face(kg, patch));
}
else if(elem == ATTR_ELEMENT_VERTEX || elem == ATTR_ELEMENT_VERTEX_MOTION) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
- uint4 v = subd_triangle_patch_indices(kg, sd);
+ uint4 v = subd_triangle_patch_indices(kg, patch);
float a, b, c;
@@ -249,7 +272,7 @@ ccl_device float subd_triangle_attribute_float(KernelGlobals *kg, const ShaderDa
float f1 = kernel_tex_fetch(__attributes_float, offset + v.y);
float f2 = kernel_tex_fetch(__attributes_float, offset + v.z);
- if(v.w != ~0) {
+ if(subd_triangle_patch_num_corners(kg, patch) == 4) {
float f3 = kernel_tex_fetch(__attributes_float, offset + v.w);
a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
@@ -270,20 +293,19 @@ ccl_device float subd_triangle_attribute_float(KernelGlobals *kg, const ShaderDa
return ccl_fetch(sd, u)*a + ccl_fetch(sd, v)*b + (1.0f - ccl_fetch(sd, u) - ccl_fetch(sd, v))*c;
}
else if(elem == ATTR_ELEMENT_CORNER) {
- int patch = offset + subd_triangle_patch(kg, sd)*4;
+ int p = offset + subd_triangle_patch_face(kg, patch)*4;
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
- uint4 v = subd_triangle_patch_indices(kg, sd);
float a, b, c;
- float f0 = kernel_tex_fetch(__attributes_float, patch + 0);
- float f1 = kernel_tex_fetch(__attributes_float, patch + 1);
- float f2 = kernel_tex_fetch(__attributes_float, patch + 2);
+ float f0 = kernel_tex_fetch(__attributes_float, p + 0);
+ float f1 = kernel_tex_fetch(__attributes_float, p + 1);
+ float f2 = kernel_tex_fetch(__attributes_float, p + 2);
- if(v.w != ~0) {
- float f3 = kernel_tex_fetch(__attributes_float, patch + 3);
+ if(subd_triangle_patch_num_corners(kg, patch) == 4) {
+ float f3 = kernel_tex_fetch(__attributes_float, p + 3);
a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
@@ -312,16 +334,18 @@ ccl_device float subd_triangle_attribute_float(KernelGlobals *kg, const ShaderDa
ccl_device float3 subd_triangle_attribute_float3(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float3 *dx, float3 *dy)
{
+ int patch = subd_triangle_patch(kg, sd);
+
if(elem == ATTR_ELEMENT_FACE) {
if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);
if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f);
- return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + subd_triangle_patch(kg, sd)));
+ return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + subd_triangle_patch_face(kg, patch)));
}
else if(elem == ATTR_ELEMENT_VERTEX || elem == ATTR_ELEMENT_VERTEX_MOTION) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
- uint4 v = subd_triangle_patch_indices(kg, sd);
+ uint4 v = subd_triangle_patch_indices(kg, patch);
float3 a, b, c;
@@ -329,7 +353,7 @@ ccl_device float3 subd_triangle_attribute_float3(KernelGlobals *kg, const Shader
float3 f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + v.y));
float3 f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + v.z));
- if(v.w != ~0) {
+ if(subd_triangle_patch_num_corners(kg, patch) == 4) {
float3 f3 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + v.w));
a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
@@ -350,32 +374,31 @@ ccl_device float3 subd_triangle_attribute_float3(KernelGlobals *kg, const Shader
return ccl_fetch(sd, u)*a + ccl_fetch(sd, v)*b + (1.0f - ccl_fetch(sd, u) - ccl_fetch(sd, v))*c;
}
else if(elem == ATTR_ELEMENT_CORNER || elem == ATTR_ELEMENT_CORNER_BYTE) {
- int patch = offset + subd_triangle_patch(kg, sd)*4;
+ int p = offset + subd_triangle_patch_face(kg, patch)*4;
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
- uint4 v = subd_triangle_patch_indices(kg, sd);
float3 a, b, c;
float3 f0, f1, f2, f3;
if(elem == ATTR_ELEMENT_CORNER) {
- f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, patch + 0));
- f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, patch + 1));
- f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, patch + 2));
+ f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, p + 0));
+ f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, p + 1));
+ f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, p + 2));
}
else {
- f0 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, patch + 0));
- f1 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, patch + 1));
- f2 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, patch + 2));
+ f0 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, p + 0));
+ f1 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, p + 1));
+ f2 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, p + 2));
}
- if(v.w != ~0) {
+ if(subd_triangle_patch_num_corners(kg, patch) == 4) {
if(elem == ATTR_ELEMENT_CORNER) {
- f3 = float4_to_float3(kernel_tex_fetch(__attributes_float3, patch + 3));
+ f3 = float4_to_float3(kernel_tex_fetch(__attributes_float3, p + 3));
}
else {
- f3 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, patch + 3));
+ f3 = color_byte_to_float(kernel_tex_fetch(__attributes_uchar4, p + 3));
}
a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
@@ -396,10 +419,10 @@ ccl_device float3 subd_triangle_attribute_float3(KernelGlobals *kg, const Shader
return ccl_fetch(sd, u)*a + ccl_fetch(sd, v)*b + (1.0f - ccl_fetch(sd, u) - ccl_fetch(sd, v))*c;
}
else {
- if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);;
- if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f);;
+ if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);
+ if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f);
- return make_float3(0.0f, 0.0f, 0.0f);;
+ return make_float3(0.0f, 0.0f, 0.0f);
}
}
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 87467d2..3c5eacc 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -131,6 +131,7 @@ Mesh::Mesh()
curvekey_offset = 0;
patch_offset = 0;
+ face_offset = 0;
attributes.triangle_mesh = this;
curve_attributes.curve_mesh = this;
@@ -312,7 +313,7 @@ void Mesh::add_subd_face(int* corners, int num_corners, int shader_, bool smooth
if(subd_faces.size()) {
SubdFace& s = subd_faces[subd_faces.size()-1];
- ptex_offset = s.ptex_offset + (s.num_corners == 4 ? 1 : s.num_corners);
+ ptex_offset = s.ptex_offset + s.num_ptex_faces();
}
subd_faces.push_back_reserved({start_corner, num_corners, shader_, smooth_, ptex_offset});
@@ -561,7 +562,7 @@ void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset)
if(triangles_size) {
for(size_t i = 0; i < triangles_size; i++) {
Triangle t = get_triangle(i);
- uint patch_index = (!subd_faces.size()) ? -1 : (triangle_patch[i] + patch_offset);
+ uint patch_index = (!subd_faces.size()) ? -1 : (triangle_patch[i]*2 + patch_offset);
tri_vindex[i] = make_float4(
__int_as_float(t.v[0] + vert_offset),
@@ -605,21 +606,44 @@ void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, s
}
}
-void Mesh::pack_patches(uint4 *patch_data, uint vert_offset)
+void Mesh::pack_patches(uint4 *patch_data, uint vert_offset, uint face_offset)
{
- size_t patches_size = subd_faces.size();
+ size_t num_faces = subd_faces.size();
- if(patches_size) {
- for(size_t i = 0; i < patches_size; i++) {
- SubdFace p = subd_faces[i];
+ if(num_faces) {
+ for(size_t f = 0; f < num_faces; f++) {
+ SubdFace face = subd_faces[f];
- int c[4];
- memcpy(c, &subd_face_corners[p.start_corner], sizeof(int)*p.num_corners);
+ if(face.is_quad()) {
+ int c[4];
+ memcpy(c, &subd_face_corners[face.start_corner], sizeof(int)*face.num_corners);
- patch_data[i] = {c[0] + vert_offset,
- c[1] + vert_offset,
- c[2] + vert_offset,
- p.num_corners > 3 ? c[3] + vert_offset : -1};
+ *(patch_data++) = {c[0] + vert_off
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list