1
1

Compare commits

...

138 Commits

Author SHA1 Message Date
0090b39fe5 Cycles: Replace object index hack with actual checks for SD_TRANSFORM_APPLIED
Using ones complement for detecting if transform has been applied was confusing
and led to several bugs. With this proper checks are made. Also added a few
transforms where they were missing, mostly affecting baking and displacement
when `P` is used in the shader (previously `P` was in the wrong space for
these shaders)
2016-09-03 16:08:15 -04:00
65afa1b7d0 Cycles: Fix bump mapping to use object space when used with true displacement
Bump mapping was happening in world space while displacement happens in object
space, causing shading errors when displacement type was used with bump mapping.

To fix this the proper transforms are added to bump nodes. This is only done
for automatic bump mapping however, to avoid visual changes from other uses of
bump mapping. It would be nice to do this for all bump mapping to be consistent
but that will have to wait till we can break compatibility.
2016-09-03 16:07:49 -04:00
d2429d5244 Merge branch 'master' into temp-cycles-microdisplacement 2016-09-02 13:26:02 -04:00
71bdbac6a4 Cycles: Remove unused flag 2016-08-30 20:49:14 -04:00
98e9dfa2d6 Cycles: Transform undisplaced coordinates into world space for bump shader eval
Forgot to do this, shading should be correct now for transformed objects.
2016-08-30 20:27:28 -04:00
c43fb36927 Merge branch 'master' into temp-cycles-microdisplacement 2016-08-30 20:12:49 -04:00
5f1bf679bb Merge branch 'master' into temp-cycles-microdisplacement 2016-08-26 12:26:26 -04:00
4b606da5a6 Cycles microdisplacement: Improved automatic bump mapping
Object coordinates can now be used in the displacement shader and will give
correct results, where as before bump mapping was calculated from the displace
positions and resulted in incorrect shading.

This works by evaluating the shader in two parts, first bump then surface, and
setting the shader state to match what it would be if the surface was
undisplaced for the bump shader evaluation. Currently only `P` is set as if
undisplaced, but other shader variables could be set as well, such as `I` or
`time`. Since these aren't set to anything meaningful for displacement I left
them out of this patch, we can decide what to do with them separately.
2016-08-18 12:20:12 -04:00
f84e760aed Cycles microdisplacement: Store undisplaced coordinates for meshes when requested 2016-08-18 11:25:44 -04:00
f3dd1f7ac0 Cycles: don't crash if OSLRenderServices::osl_ts is unset 2016-08-18 11:23:49 -04:00
7b144e306b Cycles: remove duplicate shader storage
Storing multiple copies of a shader was needed when the displacement method was
a mesh option and could be different for each mesh. Now that its a shader option
this is unnecessary.
2016-08-18 11:23:39 -04:00
9b2b915b25 Merge branch 'master' into temp-cycles-microdisplacement 2016-08-18 11:22:29 -04:00
2a649b00c4 Merge branch 'master' into temp-cycles-microdisplacement 2016-08-16 18:23:46 -04:00
a9e52fd8ee Make Cycles creased subdivision match Blenders more closely
Sets vertex creases to match how Blender handles vertexes on the edge of a mesh.
There's probably more inconsistencies but I'll see about handling those later.
2016-08-04 05:21:45 -04:00
8f7311d080 Move displacement options from mesh settings to material settings
Displacement is now a per material setting, which means old files will have to
be updated if they had used displacement. Cool side effect of this change is
material previews now show displacement.
2016-08-02 06:22:34 -04:00
57020d5d15 Merge branch 'master' into temp-cycles-microdisplacement
Includes changes from review
2016-07-30 06:26:51 -04:00
109576083c More build fixes
Should be able to revert this one after OpenSubdiv version bump
2016-07-17 18:34:33 -04:00
1ec88c9a8f Fix some build errors in patch table code 2016-07-17 18:08:15 -04:00
267bb6556f Merge branch 'master' into temp-cycles-microdisplacement 2016-07-16 20:25:49 -04:00
444ef8f196 Fix multiple shaders on subdivision meshes 2016-07-16 17:34:10 -04:00
4c4d1d6b6d Merge branch 'master' into temp-cycles-microdisplacement 2016-07-13 22:41:30 -04:00
c57964d18c Move subd_triangle_* functions to own file 2016-07-13 21:13:20 -04:00
b2933ff141 Reduce number of calls to patch_eval_*
This alleviates a ~5% performance regression caused by calling patch_eval_*
functions multiple times to calculate differentials. Differentials for
subdivided attributes are now calculated directly from the limit.

Thanks to Lukas Stockner for checking my math.
2016-07-13 20:38:49 -04:00
3269c9e137 Merge branch 'master' into temp-cycles-microdisplacement 2016-07-10 21:12:01 -04:00
ba59ae9411 Prepare for merge with master
Sergey's bvh work made use of and removed the same unused bytes that
were being used for storing patch info, so this info now has to be
moved elsewhere. Unfortunately we use up two more textures for this.
2016-07-10 20:04:43 -04:00
21d4c9e649 Fix performance regression during mesh sync
The switch from std::vector to ccl::array in Mesh caused quite a big slowdown
during mesh sync. Using a quick fix for now. Proper thing to do would be to
avoid most memory allocation in subd code.
2016-07-10 19:12:13 -04:00
526ac84f3c Fix typo in assert 2016-07-10 19:06:43 -04:00
5a91a020a8 Add patch tables and interpolate subdivision attributes in kernel
This implements and packs OpenSubdiv's patch tables and patch maps into
Cycles own representation to allow the kernel to interpolate subdivided
attributes, which means generated coordinates are now correct for subdivided
meshes. Support for subdivided uv coordinates will be added once OpenSubdiv
has complete support for face varying interpolation.
2016-07-09 23:28:36 -04:00
c97c0e89ea Change type of __patches array from uint4 to uint
Will need finer indexing granularity when patch tables are added and packed
into __patches.
2016-07-09 23:28:25 -04:00
e4776760f5 Subdivide flagged attributes
Attribute data is now subdivided when requested, tho the subdivided data is
not accessed yet.
2016-07-09 23:28:09 -04:00
97b24d82c6 Free TopologyRefiner
Missed this somehow, was leaking memory.
2016-07-09 23:27:56 -04:00
0335c34e00 Flag attributes that need to be subdivided during export 2016-07-09 23:27:48 -04:00
912acdbb8b Add attribute flags
Extend AttributeDescriptor with a field for flags. These flags will be used to
describe how an attribute interacts with subdivision code.
2016-07-09 23:27:41 -04:00
d38a21996d Avoid triggering assert if there are no creases 2016-07-09 23:27:30 -04:00
231e5452ca Add AttributeDescriptor
Adds a descriptor for attributes that can easily be passed around and extended
to contain more data. Will be needed for attributes on subdivision meshes.
2016-07-09 23:27:17 -04:00
5545fa2488 Fix OSL not finding attributes on subdivision meshes 2016-07-09 23:25:51 -04:00
6d128d81af Move Cycles subdivision options to subsurf modifier
Subdivision options can now be set per object rather than per mesh. The
subsurface modifier must be the last in the stack or Cycles will ignore
the option.
2016-06-27 05:27:51 -04:00
405c2dde88 Support creases on subdivision meshes 2016-06-26 16:16:58 -04:00
5eeea18fe3 Fix build error on older compilers 2016-06-25 10:11:24 -04:00
7e7eaf46ed Initial OpenSubdiv support
Catmull-Clark subdivision option is now functional. Creases and uv subdivision
will be implemented later.
2016-06-25 09:46:15 -04:00
004ab8859e Move Mesh::tessellate to mesh_subdivision.cpp
Adding OpenSubdiv support will require a lot of code, to keep things organized
subdivision related things are being moved to their own file.
2016-06-25 09:45:48 -04:00
71b8903e22 Add OpenSubdiv build options for Cycles
This adds a WITH_CYCLES_OPENSUBDIV build option which will enable Catmull-Clark
subdivision meshes via OpenSubdiv. This option will be turned on automatically
if WITH_OPENSUBDIV has been turned on. Right now this option doesn't
actually do anything.
2016-06-25 09:45:48 -04:00
eaaef81aa8 Merge branch 'master' into temp-cycles-microdisplacement 2016-06-25 07:31:22 -04:00
683c195fef Ensure split quads line up with split ngons 2016-06-24 13:22:48 -04:00
bcc84007dd Improved splitting
Split subpatches such that the ratio of T for opposite edges doesn't
exceed 1.5, this reduces over tessellation for some patches
2016-06-24 13:22:41 -04:00
781271b595 Remove subd_mesh.cpp and subd_mesh.h
Old code that's not needed anymore
2016-06-24 13:22:37 -04:00
8b1daab90b Remove triangles from DiagSplit implementation
Not needed now that we have ngons
2016-06-24 13:20:27 -04:00
42090adabf Disable curves on subdivision meshes for now
Attributes on curves seems broken even without subdivision, but is even
worse with. Will investigate re-enabling later.
2016-06-24 13:20:16 -04:00
7faeed57c3 Split vertex normals on ngons 2016-06-24 13:20:08 -04:00
92404a092f Keep size of vert_patch_uv in sync to avoid triggering assert 2016-06-24 13:20:03 -04:00
eb8376bcbe Sync ngons and attributes from Blender to Cycles 2016-06-24 13:19:56 -04:00
d118d74ba3 Attribute interpolation for ngons 2016-06-24 13:19:47 -04:00
4dd2d7b619 Copy ptex faces to device memory
Kernel now has access to ptex faces and ptex face mapping
2016-06-24 13:19:35 -04:00
cbcbf97620 Store ptex offset for faces
Each ngon is split into multiple faces, need to keep track of how they relate.
2016-06-24 13:19:20 -04:00
5d4c8c35d6 Split ngons into quads 2016-06-24 13:19:12 -04:00
6c6fa7905d Replace Patch with SubdFace with inital ngon support
This renames most mentions of patches to subd faces, old way of naming was
confusing. Also start supporting ngons, which will be needed for proper
Catmull-Clark subdivision surfaces. Right now this is mostly just changing
how data is passed around, actual ngon support will come later.
2016-06-24 13:17:49 -04:00
328e65afb1 Simplify how primitive counts are passed to Attribute
Refactor Attribute so that primitives counts don't need to be passed around
everywhere and can be calculated from one place.
2016-06-24 13:17:32 -04:00
b565bffaea Remove extra image texture from kernel_textures.h 2016-06-24 13:17:19 -04:00
b3aeb1756d Merge branch 'master' into temp-cycles-microdisplacement 2016-06-20 06:55:14 -04:00
876bdc231f Fix building of OpenCL kernel 2016-06-12 08:26:54 -04:00
7e9f29a897 Merge branch 'master' into temp-cycles-microdisplacement 2016-06-12 08:08:14 -04:00
bf8c67ed48 Reduce maximum number of image textures on Fermi architecture
The new __patches texture takes up a slot and goes past the limit on Fermi
cards which was causing the kernel to fail to build. To fix this there is now
one less image texture available.
2016-06-12 07:25:28 -04:00
fd254892bb Read subdivision attributes in kernel
We can now store and retrieve attributes for subdivision meshes, tho in some
places behavior of attributes may not be entirely correct yet.
2016-06-09 06:05:23 -04:00
a6405e73f1 Generate attributes for subdivision meshes 2016-06-09 06:05:12 -04:00
6c0f79b6ca Add support for storing subdivision attributes in Mesh 2016-06-09 06:05:02 -04:00
2724a95f06 Copy patches to device memory 2016-06-09 06:04:53 -04:00
eec09a1470 Pack patch info into triangle data
Pack data for finding the originating patch of a triangle into unused bytes
in __tri_verts, __tri_vnormal and __tri_vindex. Since these bytes weren't
being used there's no increase in memory usage and we avoid more complicated
logic that would be necessary if this data was stored in attributes.
2016-06-09 06:01:23 -04:00
0adac9bb46 Remove Mesh::forms_quad array
No longer needed now that we can have quad patches
2016-06-09 06:01:08 -04:00
6bbcb661e8 Sync patches from Blender to Cycles 2016-06-09 06:01:02 -04:00
c182fe5c40 Add patch primitive to Mesh
Needed for subdivision and proper attribute interpolation
2016-06-09 06:00:26 -04:00
a9675f7b8b Merge branch 'master' into temp-cycles-microdisplacement 2016-06-08 04:02:31 -04:00
f297153267 Revert geometry cache
Reverting the geometry cache for now, there's still a lot of work to be done on
the other parts of the subdivision code and the added complexity of the cache
is slowing down development. Will add it back later after things are more
functional. For now this means scenes will potentially use much more memory, so
care should be taken when using the feature.
2016-06-08 03:27:14 -04:00
357bbd5801 Merge branch 'microdisp' into temp-cycles-microdisplacement 2016-05-14 14:50:31 -04:00
ff552580bb Change default geometry cache size to 1 GB
256 MB was a little small, and a larger cache will preform better. This will
probably change at some point in the future but for now its better to have a
larger default cache size.
2016-05-12 19:34:57 -04:00
c21aa1d689 Lower default max_T from 128 to 12
This improves cache performance by reducing the maximum size of subpatches,
making tessellation both less likely to occur and faster. Difference in
performance is theoretically 100 times faster during thrashing as maximum
subpatch surface area is 100 time smaller, tho actual performance will vary.
2016-05-12 19:14:55 -04:00
a1447e96be Merge remote-tracking branch 'origin/master' into temp-cycles-microdisplacement
Conflicts:
	intern/cycles/kernel/kernel_globals.h
2016-05-12 18:00:42 +02:00
25bb41e27d Fix logic that caused attribute offset correction to be skipped for all attributes on subdivision meshes
Attribute offset correction is still needed on subdivision meshes for all attributes except ATTR_ELEMENT_FACE and
ATTR_ELEMENT_CORNER(_BYTE)
2016-05-08 16:15:28 -04:00
493a8d572d Merge remote-tracking branch 'origin/master' into temp-cycles-microdisplacement
Conflicts:
	intern/cycles/render/nodes.cpp
2016-05-08 00:19:32 +02:00
d9ec0b158f Merge remote-tracking branch 'maiself/microdisp' into temp-cycles-microdisplacement 2016-05-08 00:13:37 +02:00
8f5f0aaabe Allow building without OpenSubdiv
This makes cycles subdivision code respect build options, disabling OSD code paths when desired. Since Catmull-Clark
subdivision requires OSD this subdivision type is unavailable with OSD disabled and linear subdivision will be used as a
fallback.
2016-04-28 13:30:03 -04:00
08c20d8515 Merge branch 'master' into microdisp 2016-04-26 15:55:48 -04:00
84f21eb876 Fix possible overflow when setting geometry cache size 2016-04-18 14:47:48 -04:00
f357c9dc44 Merge branch 'microdisp' of https://github.com/maiself/blender into microdisp 2016-04-18 14:45:48 +02:00
b1b799e97c Merge branch 'master' into microdisp 2016-04-18 08:41:10 -04:00
9b93deb614 Add a few changes from master that got missed 2016-04-16 14:51:19 -04:00
edd8899abc Fix pointiness attribute not getting stored for subdivision meshes 2016-04-16 13:58:02 -04:00
82745f299d Fix OSLRenderServices not finding attributes when subdivision is enabled 2016-04-12 15:17:01 -04:00
77e4edef44 Use size_t in LRU to allow cache sizes larger than 4gb 2016-04-12 13:10:44 -04:00
cede8bccee Merge remote-tracking branch 'maiself/microdisp' into microdisp 2016-04-12 18:12:28 +02:00
fa84f6e029 Revert local commits to allow merging Mai's branch in 2016-04-12 18:11:16 +02:00
6080e43e0b Fix bug in offset calculation of attributes for subdivision patches 2016-04-12 11:10:27 -04:00
d71a7f79bd Add compilation fixes for MSVC 2016-04-12 06:02:13 -04:00
67f19772c8 Fixing two out-of-bounds bugs in the SubPatch code
Credit for the actual fixes goes to Mai Lavelle.
2016-04-12 06:02:02 -04:00
1f394f294f Add a preprocessor flag for all the kernel changes
This way, CUDA and OpenCL continue to work (still without micropolygon support, though).
2016-04-12 06:01:36 -04:00
bdc94e57c3 Fix typo that got copied around 2016-04-12 05:58:41 -04:00
e0fc155cd6 Merge branch 'master' into microdisp 2016-04-12 05:54:21 -04:00
a66bea0a49 Add compilation fixes for MSVC 2016-04-11 22:52:49 +02:00
44c905268e Allow subpatch bounds computation to be canceled 2016-04-11 16:23:46 -04:00
5bc5b2570d Fixing two out-of-bounds bugs in the SubPatch code
Credit for the actual fixes goes to Mai Lavelle.
2016-04-11 20:19:25 +02:00
d4cf8c1a7e Add a preprocessor flag for all the kernel changes
This way, CUDA and OpenCL continue to work (still without micropolygon support, though).
2016-04-11 15:58:52 +02:00
d0a21bc44b Approximate normals for "true" displacement 2016-04-11 14:52:37 +02:00
2ef58a1600 Attributes for subdivision 2016-04-11 14:52:37 +02:00
9ba8d06baf Enable displacement for geometry cache 2016-04-11 14:52:37 +02:00
34127e0564 Add bvh for subpatches 2016-04-11 14:52:36 +02:00
485ed01dc1 Adding a geometry cache
Squashed the following 7 commits:

- Add geometry cache ; geom cache

- Add geometry cache ; geom

- Add geometry cache ; bvh

- Add geometry cache ; mesh

- Add geometry cache ; sync

- Add geometry cache ; subd

- Add geometry cache ; geom bvh
2016-04-11 14:52:36 +02:00
c7cd1455e9 Add basic OpenSubDiv support 2016-04-11 14:52:36 +02:00
6a7f6b1ca1 Seperate dice and split for subdivision meshes 2016-04-11 14:52:36 +02:00
48f9190fb9 Add max subdivision setting to subdivision meshes 2016-04-11 14:52:36 +02:00
d14db239b0 Fix support for triangles in DiagSplit implementation 2016-04-11 14:52:36 +02:00
878a315880 Add displacement scale option to displaced meshes 2016-04-11 14:52:36 +02:00
ecb8796264 Add preview dice rate for displacement 2016-04-11 14:52:35 +02:00
81fb15312b Change Cycles displacement UI to split column 2016-04-11 14:52:35 +02:00
6e4c39805b Set normals properly for subdivision meshes 2016-04-11 14:52:35 +02:00
cc9f1e27ce Migrate away from ccl::SubdMesh for tessellation 2016-04-11 14:52:35 +02:00
5ffb152ca4 Change use subdivision bool to subdivision type enum 2016-04-11 14:52:35 +02:00
c71dd0c23e Have dicing happen in screen space 2016-04-11 14:52:35 +02:00
00bdb3c9c9 Approximate normals for "true" displacement 2016-04-09 12:56:28 -04:00
bb5c0e6393 Attributes for subdivision 2016-04-09 12:56:23 -04:00
aa7f326a9f Enable displacement for geometry cache 2016-04-09 12:56:18 -04:00
e47864b593 Add bvh for subpatches 2016-04-09 12:56:14 -04:00
9b5612867e Add geometry cache ; geom bvh 2016-04-09 12:56:14 -04:00
230111d11e Add geometry cache ; subd 2016-04-09 12:56:13 -04:00
0a4da23524 Add geometry cache ; sync 2016-04-09 12:56:12 -04:00
67b4f56050 Add geometry cache ; mesh 2016-04-09 12:56:12 -04:00
e6538ac8bb Add geometry cache ; bvh 2016-04-09 12:56:11 -04:00
68593ab7bf Add geometry cache ; geom 2016-04-09 12:56:10 -04:00
2ec75023af Add geometry cache ; geom cache 2016-04-09 12:55:52 -04:00
c78414cefa Add basic OpenSubDiv support 2016-04-09 12:55:49 -04:00
90301728ce Seperate dice and split for subdivision meshes 2016-04-09 12:55:30 -04:00
762db91439 Add max subdivision setting to subdivision meshes 2016-04-09 12:55:25 -04:00
d25fb5191e Fix support for triangles in DiagSplit implementation 2016-04-09 12:55:23 -04:00
2385a5c314 Add displacement scale option to displaced meshes 2016-04-09 12:55:21 -04:00
f7029f8d86 Add preview dice rate for displacement 2016-04-09 12:55:19 -04:00
1daf5e80c3 Change Cycles displacement UI to split column 2016-04-09 12:55:04 -04:00
4b7e3d4a33 Set normals properly for subdivision meshes 2016-04-09 12:54:38 -04:00
384bf91476 Migrate away from ccl::SubdMesh for tessellation 2016-04-09 12:54:35 -04:00
e361a7dabc Change use subdivision bool to subdivision type enum 2016-04-09 12:54:20 -04:00
aa678bdcf1 Have dicing happen in screen space 2016-04-09 12:54:01 -04:00
17 changed files with 98 additions and 53 deletions

View File

@@ -681,8 +681,7 @@ void BlenderSession::bake(BL::Object& b_object,
}
}
/* when used, non-instanced convention: object = ~object */
int object = ~object_index;
int object = object_index;
BakeData *bake_data = scene->bake_manager->init(object, tri_offset, num_pixels);

View File

@@ -52,8 +52,8 @@ ccl_device_inline void triangle_point_normal(KernelGlobals *kg, int object, int
float t = 1.0f - u - v;
*P = (u*v0 + v*v1 + t*v2);
/* get object flags, instance-aware */
int object_flag = kernel_tex_fetch(__object_flag, object >= 0 ? object : ~object);
/* get object flags */
int object_flag = kernel_tex_fetch(__object_flag, object);
/* compute normal */
if(object_flag & SD_NEGATIVE_SCALE_APPLIED)

View File

@@ -313,6 +313,14 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
triangle_point_normal(kg, object, prim, u, v, &P, &Ng, &shader);
if(!(kernel_tex_fetch(__object_flag, object) & SD_TRANSFORM_APPLIED)) {
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
P = transform_point(&tfm, P);
tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
Ng = normalize(transform_direction_transposed(&tfm, Ng));
}
/* dummy initilizations copied from SHADER_EVAL_DISPLACE */
float3 I = Ng;
float t = 1.0f;
@@ -525,6 +533,9 @@ ccl_device void kernel_shader_evaluate(KernelGlobals *kg,
float3 P = sd.P;
shader_eval_displacement(kg, &sd, &state, SHADER_CONTEXT_MAIN);
out = sd.P - P;
Transform itfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
out = transform_direction(&itfm, out);
}
else { // SHADER_EVAL_BACKGROUND
/* setup ray */

View File

@@ -747,7 +747,7 @@ ccl_device void object_transform_light_sample(KernelGlobals *kg, LightSample *ls
{
#ifdef __INSTANCING__
/* instance transform */
if(object >= 0) {
if(!(kernel_tex_fetch(__object_flag, object) & SD_TRANSFORM_APPLIED)) {
# ifdef __OBJECT_MOTION__
Transform itfm;
Transform tfm = object_fetch_transform_motion_test(kg, object, time, &itfm);

View File

@@ -263,20 +263,6 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals *kg,
#endif
ccl_fetch(sd, ray_length) = t;
/* detect instancing, for non-instanced the object index is -object-1 */
#ifdef __INSTANCING__
bool instanced = false;
if(ccl_fetch(sd, prim) != PRIM_NONE) {
if(ccl_fetch(sd, object) >= 0)
instanced = true;
else
#endif
ccl_fetch(sd, object) = ~ccl_fetch(sd, object);
#ifdef __INSTANCING__
}
#endif
ccl_fetch(sd, flag) = kernel_tex_fetch(__shader_flag, (ccl_fetch(sd, shader) & SHADER_MASK)*2);
if(ccl_fetch(sd, object) != OBJECT_NONE) {
ccl_fetch(sd, flag) |= kernel_tex_fetch(__object_flag, ccl_fetch(sd, object));
@@ -296,8 +282,9 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals *kg,
ccl_fetch(sd, N) = triangle_smooth_normal(kg, ccl_fetch(sd, prim), ccl_fetch(sd, u), ccl_fetch(sd, v));
#ifdef __INSTANCING__
if(instanced)
if(!(ccl_fetch(sd, flag) & SD_TRANSFORM_APPLIED)) {
object_normal_transform_auto(kg, sd, &ccl_fetch(sd, N));
}
#endif
}
@@ -306,7 +293,7 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals *kg,
triangle_dPdudv(kg, ccl_fetch(sd, prim), &ccl_fetch(sd, dPdu), &ccl_fetch(sd, dPdv));
# ifdef __INSTANCING__
if(instanced) {
if(!(ccl_fetch(sd, flag) & SD_TRANSFORM_APPLIED)) {
object_dir_transform_auto(kg, sd, &ccl_fetch(sd, dPdu));
object_dir_transform_auto(kg, sd, &ccl_fetch(sd, dPdv));
}
@@ -354,11 +341,17 @@ ccl_device void shader_setup_from_displace(KernelGlobals *kg, ShaderData *sd,
triangle_point_normal(kg, object, prim, u, v, &P, &Ng, &shader);
if(!(kernel_tex_fetch(__object_flag, object) & SD_TRANSFORM_APPLIED)) {
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
P = transform_point(&tfm, P);
tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
Ng = normalize(transform_direction_transposed(&tfm, Ng));
}
/* force smooth shading for displacement */
shader |= SHADER_SMOOTH_NORMAL;
/* watch out: no instance transform currently */
shader_setup_from_sample(kg, sd, P, Ng, I, shader, object, prim, u, v, 0.0f, TIME_INVALID);
}

View File

@@ -21,6 +21,7 @@
surface node_bump(
int invert = 0,
int use_object_space = 0,
normal NormalIn = N,
float Strength = 0.1,
float Distance = 1.0,
@@ -29,12 +30,20 @@ surface node_bump(
float SampleY = 0.0,
output normal NormalOut = N)
{
/* get surface tangents from normal */
vector dPdx = Dx(P);
vector dPdy = Dy(P);
point Ptmp = P;
normal Normal = NormalIn;
vector Rx = cross(dPdy, NormalIn);
vector Ry = cross(NormalIn, dPdx);
if (use_object_space) {
Ptmp = transform("object", Ptmp);
Normal = normalize(transform("object", Normal));
}
/* get surface tangents from normal */
vector dPdx = Dx(Ptmp);
vector dPdy = Dy(Ptmp);
vector Rx = cross(dPdy, Normal);
vector Ry = cross(Normal, dPdx);
/* compute surface gradient and determinant */
float det = dot(dPdx, Rx);
@@ -49,7 +58,11 @@ surface node_bump(
dist *= -1.0;
/* compute and output perturbed normal */
NormalOut = normalize(absdet * NormalIn - dist * sign(det) * surfgrad);
NormalOut = normalize(strength * NormalOut + (1.0 - strength) * NormalIn);
NormalOut = normalize(absdet * Normal - dist * sign(det) * surfgrad);
NormalOut = normalize(strength * NormalOut + (1.0 - strength) * Normal);
if (use_object_space) {
NormalOut = normalize(transform("object", "world", NormalOut));
}
}

View File

@@ -18,6 +18,8 @@
displacement node_output_displacement(float Displacement = 0.0)
{
P += N * Displacement * 0.1; /* todo: get rid of this factor */
vector dP = normalize(transform("object", N));
dP *= Displacement * 0.1; /* todo: get rid of this factor */
P += transform("object", "world", dP);
}

View File

@@ -261,7 +261,7 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ccl_a
svm_node_geometry_bump_dy(kg, sd, stack, node.y, node.z);
break;
case NODE_SET_DISPLACEMENT:
svm_node_set_displacement(sd, stack, node.y);
svm_node_set_displacement(kg, sd, stack, node.y);
break;
# endif /* NODES_FEATURE(NODE_FEATURE_BUMP) */
# ifdef __TEXTURES__

View File

@@ -22,14 +22,23 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac
{
#ifdef __RAY_DIFFERENTIALS__
/* get normal input */
uint normal_offset, distance_offset, invert;
decode_node_uchar4(node.y, &normal_offset, &distance_offset, &invert, NULL);
uint normal_offset, distance_offset, invert, use_object_space;
decode_node_uchar4(node.y, &normal_offset, &distance_offset, &invert, &use_object_space);
float3 normal_in = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): ccl_fetch(sd, N);
float3 dPdx = ccl_fetch(sd, dP).dx;
float3 dPdy = ccl_fetch(sd, dP).dy;
if(use_object_space) {
object_inverse_normal_transform(kg, sd, &normal_in);
object_inverse_dir_transform(kg, sd, &dPdx);
object_inverse_dir_transform(kg, sd, &dPdy);
}
/* get surface tangents from normal */
float3 Rx = cross(ccl_fetch(sd, dP).dy, normal_in);
float3 Ry = cross(normal_in, ccl_fetch(sd, dP).dx);
float3 Rx = cross(dPdy, normal_in);
float3 Ry = cross(normal_in, dPdx);
/* get bump values */
uint c_offset, x_offset, y_offset, strength_offset;
@@ -40,7 +49,7 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac
float h_y = stack_load_float(stack, y_offset);
/* compute surface gradient and determinant */
float det = dot(ccl_fetch(sd, dP).dx, Rx);
float det = dot(dPdx, Rx);
float3 surfgrad = (h_x - h_c)*Rx + (h_y - h_c)*Ry;
float absdet = fabsf(det);
@@ -56,16 +65,29 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac
/* compute and output perturbed normal */
float3 normal_out = normalize(absdet*normal_in - distance*signf(det)*surfgrad);
normal_out = normalize(strength*normal_out + (1.0f - strength)*normal_in);
if(use_object_space) {
object_normal_transform(kg, sd, &normal_out);
}
stack_store_float3(stack, node.w, normal_out);
#endif
}
/* Displacement Node */
ccl_device void svm_node_set_displacement(ShaderData *sd, float *stack, uint fac_offset)
ccl_device void svm_node_set_displacement(KernelGlobals *kg, ShaderData *sd, float *stack, uint fac_offset)
{
float d = stack_load_float(stack, fac_offset);
ccl_fetch(sd, P) += ccl_fetch(sd, N)*d*0.1f; /* todo: get rid of this factor */
float3 dP = ccl_fetch(sd, N);
object_inverse_normal_transform(kg, sd, &dP);
dP *= d*0.1f; /* todo: get rid of this factor */
object_dir_transform(kg, sd, &dP);
ccl_fetch(sd, P) += dP;
}
CCL_NAMESPACE_END

View File

@@ -312,7 +312,8 @@ void ShaderGraph::relink(ShaderNode *node, ShaderOutput *from, ShaderOutput *to)
void ShaderGraph::finalize(Scene *scene,
bool do_bump,
bool do_osl,
bool do_simplify)
bool do_simplify,
bool bump_in_object_space)
{
/* before compiling, the shader graph may undergo a number of modifications.
* currently we set default geometry shader inputs, and create automatic bump
@@ -325,7 +326,7 @@ void ShaderGraph::finalize(Scene *scene,
refine_bump_nodes();
if(do_bump)
bump_from_displacement();
bump_from_displacement(bump_in_object_space);
ShaderInput *surface_in = output()->input("Surface");
ShaderInput *volume_in = output()->input("Volume");
@@ -793,7 +794,7 @@ void ShaderGraph::refine_bump_nodes()
}
}
void ShaderGraph::bump_from_displacement()
void ShaderGraph::bump_from_displacement(bool use_object_space)
{
/* generate bump mapping automatically from displacement. bump mapping is
* done using a 3-tap filter, computing the displacement at the center,
@@ -842,7 +843,8 @@ void ShaderGraph::bump_from_displacement()
ShaderNode *set_normal = add(new SetNormalNode());
/* add bump node and connect copied graphs to it */
ShaderNode *bump = add(new BumpNode());
BumpNode *bump = (BumpNode*)add(new BumpNode());
bump->use_object_space = use_object_space;
ShaderOutput *out = displacement_in->link;
ShaderOutput *out_center = nodes_center[out->parent]->output(out->name());

View File

@@ -258,7 +258,8 @@ public:
void finalize(Scene *scene,
bool do_bump = false,
bool do_osl = false,
bool do_simplify = false);
bool do_simplify = false,
bool bump_in_object_space = false);
int get_num_closures();
@@ -272,7 +273,7 @@ protected:
void copy_nodes(ShaderNodeSet& nodes, ShaderNodeMap& nnodemap);
void break_cycles(ShaderNode *node, vector<bool>& visited, vector<bool>& on_stack);
void bump_from_displacement();
void bump_from_displacement(bool use_object_space);
void refine_bump_nodes();
void default_inputs(bool do_osl);
void transform_multi_closure(ShaderNode *node, ShaderOutput *weight_out, bool volume);

View File

@@ -309,9 +309,6 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
int object_id = j;
int shader_flag = 0;
if(transform_applied)
object_id = ~object_id;
if(!(object->visibility & PATH_RAY_DIFFUSE)) {
shader_flag |= SHADER_EXCLUDE_DIFFUSE;
use_light_visibility = true;

View File

@@ -86,8 +86,7 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me
done[t.v[j]] = true;
/* set up object, primitive and barycentric coordinates */
/* when used, non-instanced convention: object = ~object */
int object = ~object_index;
int object = object_index;
int prim = mesh->tri_offset + i;
float u, v;

View File

@@ -4762,6 +4762,7 @@ NODE_DEFINE(BumpNode)
NodeType* type = NodeType::add("bump", create, NodeType::SHADER);
SOCKET_BOOLEAN(invert, "Invert", false);
SOCKET_BOOLEAN(use_object_space, "UseObjectSpace", false);
/* this input is used by the user, but after graph transform it is no longer
* used and moved to sampler center/x/y instead */
@@ -4800,7 +4801,8 @@ void BumpNode::compile(SVMCompiler& compiler)
compiler.encode_uchar4(
compiler.stack_assign_if_linked(normal_in),
compiler.stack_assign(distance_in),
invert),
invert,
use_object_space),
compiler.encode_uchar4(
compiler.stack_assign(center_in),
compiler.stack_assign(dx_in),
@@ -4812,6 +4814,7 @@ void BumpNode::compile(SVMCompiler& compiler)
void BumpNode::compile(OSLCompiler& compiler)
{
compiler.parameter(this, "invert");
compiler.parameter(this, "use_object_space");
compiler.add(this, "node_bump");
}

View File

@@ -873,6 +873,7 @@ public:
}
bool invert;
bool use_object_space;
float height;
float sample_center;
float sample_x;

View File

@@ -1103,7 +1103,8 @@ void OSLCompiler::compile(Scene *scene, OSLGlobals *og, Shader *shader)
shader->graph_bump->finalize(scene,
true,
true,
shader->has_integrator_dependency);
shader->has_integrator_dependency,
shader->displacement_method == DISPLACE_BOTH);
}
current_shader = shader;

View File

@@ -760,7 +760,8 @@ void SVMCompiler::compile(Scene *scene,
shader->graph_bump->finalize(scene,
true,
false,
shader->has_integrator_dependency);
shader->has_integrator_dependency,
shader->displacement_method == DISPLACE_BOTH);
}
current_shader = shader;