Fix T98163: Cycles OSL rendering normal maps differently

Match SVM and ensure valid reflection when setting up BSDFs.
This commit is contained in:
Brecht Van Lommel 2022-05-17 16:27:37 +02:00
parent 0609b4bb49
commit 8fdd3aad9b
Notes: blender-bot 2023-02-14 01:11:05 +01:00
Referenced by issue #98163, Regression: Rendering object with normal map differs in Cycles and Cycles + OSL
5 changed files with 32 additions and 0 deletions

View File

@ -17,6 +17,7 @@
#include "kernel/types.h"
#include "kernel/closure/alloc.h"
#include "kernel/closure/bsdf_diffuse_ramp.h"
#include "kernel/closure/bsdf_util.h"
// clang-format on
CCL_NAMESPACE_BEGIN
@ -30,6 +31,8 @@ class DiffuseRampClosure : public CBSDFClosure {
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
DiffuseRampBsdf *bsdf = (DiffuseRampBsdf *)bsdf_alloc_osl(
sd, sizeof(DiffuseRampBsdf), weight, &params);

View File

@ -17,6 +17,7 @@
#include "kernel/types.h"
#include "kernel/closure/alloc.h"
#include "kernel/closure/bsdf_phong_ramp.h"
#include "kernel/closure/bsdf_util.h"
// clang-format on
CCL_NAMESPACE_BEGIN
@ -30,6 +31,8 @@ class PhongRampClosure : public CBSDFClosure {
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
PhongRampBsdf *bsdf = (PhongRampBsdf *)bsdf_alloc_osl(
sd, sizeof(PhongRampBsdf), weight, &params);

View File

@ -44,6 +44,8 @@ class CBSSRDFClosure : public CClosurePrimitive {
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
if (method == u_burley) {
alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
}

View File

@ -180,6 +180,8 @@ class PrincipledSheenClosure : public CBSDFClosure {
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
if (!skip(sd, path_flag, LABEL_DIFFUSE)) {
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
PrincipledSheenBsdf *bsdf = (PrincipledSheenBsdf *)bsdf_alloc_osl(
sd, sizeof(PrincipledSheenBsdf), weight, &params);
sd->flag |= (bsdf) ? bsdf_principled_sheen_setup(sd, bsdf) : 0;
@ -223,6 +225,8 @@ class PrincipledHairClosure : public CBSDFClosure {
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
if (!skip(sd, path_flag, LABEL_GLOSSY)) {
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
PrincipledHairBSDF *bsdf = (PrincipledHairBSDF *)alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -282,6 +286,7 @@ class PrincipledClearcoatClosure : public CBSDFClosure {
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -503,6 +508,8 @@ class MicrofacetClosure : public CBSDFClosure {
return;
}
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = (MicrofacetBsdf *)bsdf_alloc_osl(
sd, sizeof(MicrofacetBsdf), weight, &params);
@ -601,6 +608,8 @@ class MicrofacetGGXFresnelClosure : public MicrofacetFresnelClosure {
public:
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -630,6 +639,8 @@ class MicrofacetGGXAnisoFresnelClosure : public MicrofacetFresnelClosure {
public:
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -695,6 +706,8 @@ class MicrofacetMultiGGXClosure : public MicrofacetMultiClosure {
public:
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -723,6 +736,8 @@ class MicrofacetMultiGGXAnisoClosure : public MicrofacetMultiClosure {
public:
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -755,6 +770,8 @@ class MicrofacetMultiGGXGlassClosure : public MicrofacetMultiClosure {
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -819,6 +836,8 @@ class MicrofacetMultiGGXFresnelClosure : public MicrofacetMultiFresnelClosure {
public:
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -849,6 +868,8 @@ class MicrofacetMultiGGXAnisoFresnelClosure : public MicrofacetMultiFresnelClosu
public:
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;
@ -883,6 +904,8 @@ class MicrofacetMultiGGXGlassFresnelClosure : public MicrofacetMultiFresnelClosu
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
{
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if (!bsdf) {
return;

View File

@ -114,6 +114,7 @@ class CBSDFClosure : public CClosurePrimitive {
void setup(ShaderData *sd, uint32_t path_flag, float3 weight) \
{ \
if (!skip(sd, path_flag, TYPE)) { \
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N); \
structname *bsdf = (structname *)bsdf_alloc_osl(sd, sizeof(structname), weight, &params); \
sd->flag |= (bsdf) ? bsdf_##lower##_setup(bsdf) : 0; \
} \