Cycles Hair: refactoring to store curves with the index of the first key and the
number of keys in the curve, rather than curve segments with the indices of two keys. ShaderData.segment now stores the segment number in the curve.
This commit is contained in:
@@ -24,19 +24,21 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
__device float curve_attribute_float(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float *dx, float *dy)
|
||||
{
|
||||
if(elem == ATTR_ELEMENT_CURVE_SEGMENT) {
|
||||
if(elem == ATTR_ELEMENT_CURVE) {
|
||||
#ifdef __RAY_DIFFERENTIALS__
|
||||
if(dx) *dx = 0.0f;
|
||||
if(dy) *dy = 0.0f;
|
||||
#endif
|
||||
|
||||
return kernel_tex_fetch(__attributes_float, offset + sd->curve_seg);
|
||||
return kernel_tex_fetch(__attributes_float, offset + sd->prim);
|
||||
}
|
||||
else if(elem == ATTR_ELEMENT_CURVE_KEY) {
|
||||
float4 segment = kernel_tex_fetch(__curve_segments, sd->curve_seg);
|
||||
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
|
||||
int k0 = __float_as_int(curvedata.x) + sd->segment;
|
||||
int k1 = k0 + 1;
|
||||
|
||||
float f0 = kernel_tex_fetch(__attributes_float, offset + __float_as_int(segment.x));
|
||||
float f1 = kernel_tex_fetch(__attributes_float, offset + __float_as_int(segment.y));
|
||||
float f0 = kernel_tex_fetch(__attributes_float, offset + k0);
|
||||
float f1 = kernel_tex_fetch(__attributes_float, offset + k1);
|
||||
|
||||
#ifdef __RAY_DIFFERENTIALS__
|
||||
if(dx) *dx = sd->du.dx*(f1 - f0);
|
||||
@@ -57,7 +59,7 @@ __device float curve_attribute_float(KernelGlobals *kg, const ShaderData *sd, At
|
||||
|
||||
__device float3 curve_attribute_float3(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float3 *dx, float3 *dy)
|
||||
{
|
||||
if(elem == ATTR_ELEMENT_CURVE_SEGMENT) {
|
||||
if(elem == ATTR_ELEMENT_CURVE) {
|
||||
/* idea: we can't derive any useful differentials here, but for tiled
|
||||
* mipmap image caching it would be useful to avoid reading the highest
|
||||
* detail level always. maybe a derivative based on the hair density
|
||||
@@ -67,13 +69,15 @@ __device float3 curve_attribute_float3(KernelGlobals *kg, const ShaderData *sd,
|
||||
if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f);
|
||||
#endif
|
||||
|
||||
return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + sd->curve_seg));
|
||||
return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + sd->prim));
|
||||
}
|
||||
else if(elem == ATTR_ELEMENT_CURVE_KEY) {
|
||||
float4 segment = kernel_tex_fetch(__curve_segments, sd->curve_seg);
|
||||
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
|
||||
int k0 = __float_as_int(curvedata.x) + sd->segment;
|
||||
int k1 = k0 + 1;
|
||||
|
||||
float3 f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(segment.x)));
|
||||
float3 f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(segment.y)));
|
||||
float3 f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + k0));
|
||||
float3 f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + k1));
|
||||
|
||||
#ifdef __RAY_DIFFERENTIALS__
|
||||
if(dx) *dx = sd->du.dx*(f1 - f0);
|
||||
@@ -96,19 +100,16 @@ __device float3 curve_attribute_float3(KernelGlobals *kg, const ShaderData *sd,
|
||||
|
||||
__device float curve_thickness(KernelGlobals *kg, ShaderData *sd)
|
||||
{
|
||||
int prim = sd->curve_seg;
|
||||
float u = sd->u;
|
||||
float r = 0.0f;
|
||||
|
||||
if(prim != -1) {
|
||||
float4 v00 = kernel_tex_fetch(__curve_segments, prim);
|
||||
if(sd->segment != ~0) {
|
||||
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
|
||||
int k0 = __float_as_int(curvedata.x) + sd->segment;
|
||||
int k1 = k0 + 1;
|
||||
|
||||
int v1 = __float_as_int(v00.x);
|
||||
int v2 = __float_as_int(v00.y);
|
||||
|
||||
float4 P1 = kernel_tex_fetch(__curve_keys, v1);
|
||||
float4 P2 = kernel_tex_fetch(__curve_keys, v2);
|
||||
r = (P2.w - P1.w) * u + P1.w;
|
||||
float4 P1 = kernel_tex_fetch(__curve_keys, k0);
|
||||
float4 P2 = kernel_tex_fetch(__curve_keys, k1);
|
||||
r = (P2.w - P1.w) * sd->u + P1.w;
|
||||
}
|
||||
|
||||
return r*2.0f;
|
||||
@@ -118,7 +119,7 @@ __device float3 curve_tangent_normal(KernelGlobals *kg, ShaderData *sd)
|
||||
{
|
||||
float3 tgN = make_float3(0.0f,0.0f,0.0f);
|
||||
|
||||
if(sd->curve_seg != ~0) {
|
||||
if(sd->segment != ~0) {
|
||||
float normalmix = kernel_data.curve_kernel_data.normalmix;
|
||||
|
||||
tgN = -(-sd->I - sd->dPdu * (dot(sd->dPdu,-sd->I) * normalmix / len_squared(sd->dPdu)));
|
||||
|
Reference in New Issue
Block a user