Skip to content

Conversation

devshgraphicsprogramming
Copy link
Member

Description

Continuing #811 due to GH UI messing up diffs again

Testing

TODO list:

Comment on lines +21 to +89
namespace impl
{
struct sincos_accumulator
{
using this_t = sincos_accumulator;

static this_t create()
{
this_t retval;
retval.tmp0 = 0;
retval.tmp1 = 0;
retval.tmp2 = 0;
retval.tmp3 = 0;
retval.tmp4 = 0;
retval.tmp5 = 0;
return retval;
}

static this_t create(float cosA, float cosB, float cosC, float sinA, float sinB, float sinC)
{
this_t retval;
retval.tmp0 = cosA;
retval.tmp1 = cosB;
retval.tmp2 = cosC;
retval.tmp3 = sinA;
retval.tmp4 = sinB;
retval.tmp5 = sinC;
return retval;
}

float getArccosSumofABC_minus_PI()
{
const bool AltminusB = tmp0 < (-tmp1);
const float cosSumAB = tmp0 * tmp1 - tmp3 * tmp4;
const bool ABltminusC = cosSumAB < (-tmp2);
const bool ABltC = cosSumAB < tmp2;
// apply triple angle formula
const float absArccosSumABC = acos<float>(clamp<float>(cosSumAB * tmp2 - (tmp0 * tmp4 + tmp3 * tmp1) * tmp5, -1.f, 1.f));
return ((AltminusB ? ABltC : ABltminusC) ? (-absArccosSumABC) : absArccosSumABC) + ((AltminusB || ABltminusC) ? numbers::pi<float> : (-numbers::pi<float>));
}

static void combineCosForSumOfAcos(float cosA, float cosB, float biasA, float biasB, NBL_REF_ARG(float) out0, NBL_REF_ARG(float) out1)
{
const float bias = biasA + biasB;
const float a = cosA;
const float b = cosB;
const bool reverse = abs<float>(min<float>(a, b)) > max<float>(a, b);
const float c = a * b - sqrt<float>((1.0f - a * a) * (1.0f - b * b));

if (reverse)
{
out0 = -c;
out1 = bias + numbers::pi<float>;
}
else
{
out0 = c;
out1 = bias;
}
}

float tmp0;
float tmp1;
float tmp2;
float tmp3;
float tmp4;
float tmp5;
};
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #899 (comment)

Also no need for this to stay in impl

Comment on lines +57 to +64
static vector_t3 generate(vector_t3 _sample)
{
vector_t3 retval = hemisphere_t::generate(_sample.xy);
const bool chooseLower = _sample.z > T(0.5);
retval.z = chooseLower ? (-retval.z) : retval.z;
if (chooseLower)
_sample.z -= T(0.5);
_sample.z *= T(2.0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this to work the _sample needs to be taken as NBL_REF_ARG

@devshgraphicsprogramming devshgraphicsprogramming merged commit b39c937 into master Aug 29, 2025
13 of 14 checks passed
@devshgraphicsprogramming devshgraphicsprogramming deleted the hlsl_bxdfs branch August 29, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants