# Changeset View

Changeset View

# Standalone View

Standalone View

# intern/cycles/kernel/kernel_differential.h

Show All 12 Lines | |||||

* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||

* limitations under the License. | * limitations under the License. | ||||

*/ | */ | ||||

CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||

/* See "Tracing Ray Differentials", Homan Igehy, 1999. */ | /* See "Tracing Ray Differentials", Homan Igehy, 1999. */ | ||||

ccl_device void differential_transfer(differential3 *dP_, const differential3 dP, float3 D, const differential3 dD, float3 Ng, float t) | ccl_device void differential_transfer(ccl_addr_space differential3 *dP_, const differential3 dP, float3 D, const differential3 dD, float3 Ng, float t) | ||||

{ | { | ||||

/* ray differential transfer through homogeneous medium, to | /* ray differential transfer through homogeneous medium, to | ||||

* compute dPdx/dy at a shading point from the incoming ray */ | * compute dPdx/dy at a shading point from the incoming ray */ | ||||

float3 tmp = D/dot(D, Ng); | float3 tmp = D/dot(D, Ng); | ||||

float3 tmpx = dP.dx + t*dD.dx; | float3 tmpx = dP.dx + t*dD.dx; | ||||

float3 tmpy = dP.dy + t*dD.dy; | float3 tmpy = dP.dy + t*dD.dy; | ||||

dP_->dx = tmpx - dot(tmpx, Ng)*tmp; | dP_->dx = tmpx - dot(tmpx, Ng)*tmp; | ||||

dP_->dy = tmpy - dot(tmpy, Ng)*tmp; | dP_->dy = tmpy - dot(tmpy, Ng)*tmp; | ||||

} | } | ||||

ccl_device void differential_incoming(differential3 *dI, const differential3 dD) | ccl_device void differential_incoming(ccl_addr_space differential3 *dI, const differential3 dD) | ||||

{ | { | ||||

/* compute dIdx/dy at a shading point, we just need to negate the | /* compute dIdx/dy at a shading point, we just need to negate the | ||||

* differential of the ray direction */ | * differential of the ray direction */ | ||||

dI->dx = -dD.dx; | dI->dx = -dD.dx; | ||||

dI->dy = -dD.dy; | dI->dy = -dD.dy; | ||||

} | } | ||||

ccl_device void differential_dudv(differential *du, differential *dv, float3 dPdu, float3 dPdv, differential3 dP, float3 Ng) | ccl_device void differential_dudv(ccl_addr_space differential *du, ccl_addr_space differential *dv, float3 dPdu, float3 dPdv, differential3 dP, float3 Ng) | ||||

{ | { | ||||

/* now we have dPdx/dy from the ray differential transfer, and dPdu/dv | /* now we have dPdx/dy from the ray differential transfer, and dPdu/dv | ||||

* from the primitive, we can compute dudx/dy and dvdx/dy. these are | * from the primitive, we can compute dudx/dy and dvdx/dy. these are | ||||

* mainly used for differentials of arbitrary mesh attributes. */ | * mainly used for differentials of arbitrary mesh attributes. */ | ||||

/* find most stable axis to project to 2D */ | /* find most stable axis to project to 2D */ | ||||

float xn = fabsf(Ng.x); | float xn = fabsf(Ng.x); | ||||

float yn = fabsf(Ng.y); | float yn = fabsf(Ng.y); | ||||

▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |