Skip to content

Instantly share code, notes, and snippets.

@devshgraphicsprogramming
Created November 19, 2020 17:43
Show Gist options
  • Save devshgraphicsprogramming/d093214fea881009f4f9a4d4baadac00 to your computer and use it in GitHub Desktop.
Save devshgraphicsprogramming/d093214fea881009f4f9a4d4baadac00 to your computer and use it in GitHub Desktop.
Raytraced BALLS
#version 460
struct Sphere
{
vec3 position;
float radius2;
uint bsdfLightIDs;
};
struct Rectangle
{
vec3 offset;
uint bsdfLightIDs;
vec3 edge0;
uint padding0;
vec3 edge1;
uint padding1;
};
struct BSDFNode
{
uvec4 data[2];
};
struct Light
{
vec3 radiance;
uint objectID;
};
struct irr_glsl_DirAndDifferential
{
vec3 dir;
mat2x3 dPosdScreen;
};
struct irr_glsl_IsotropicViewSurfaceInteraction
{
irr_glsl_DirAndDifferential V;
vec3 N;
float NdotV;
float NdotV_squared;
};
struct irr_glsl_AnisotropicViewSurfaceInteraction
{
irr_glsl_IsotropicViewSurfaceInteraction isotropic;
vec3 T;
vec3 B;
float TdotV;
float BdotV;
};
struct irr_glsl_LightSample
{
vec3 L;
float VdotL;
float TdotL;
float BdotL;
float NdotL;
float NdotL2;
};
struct irr_glsl_IsotropicMicrofacetCache
{
float VdotH;
float LdotH;
float NdotH;
float NdotH2;
};
struct irr_glsl_AnisotropicMicrofacetCache
{
irr_glsl_IsotropicMicrofacetCache isotropic;
float TdotH;
float BdotH;
};
struct ImmutableRay_t
{
vec3 origin;
float maxT;
vec3 direction;
int typeDepthSampleIx;
vec3 normalAtOrigin;
bool wasBSDFAtOrigin;
};
struct MutableRay_t
{
float intersectionT;
uint objectID;
};
struct Payload_t
{
vec3 accumulation;
float otherTechniqueHeuristic;
vec3 throughput;
};
struct Ray_t
{
ImmutableRay_t _immutable;
MutableRay_t _mutable;
Payload_t _payload;
};
#ifndef SPIRV_CROSS_CONSTANT_ID_0
#define SPIRV_CROSS_CONSTANT_ID_0 3
#endif
const int MAX_DEPTH_LOG2 = SPIRV_CROSS_CONSTANT_ID_0;
#ifndef SPIRV_CROSS_CONSTANT_ID_1
#define SPIRV_CROSS_CONSTANT_ID_1 10
#endif
const int MAX_SAMPLES_LOG2 = SPIRV_CROSS_CONSTANT_ID_1;
const int _2984 = (7 >> MAX_DEPTH_LOG2);
const bool _2985 = (_2984 > 0);
const bool _2986 = (!_2985);
const int _2990 = (31 >> MAX_SAMPLES_LOG2);
const bool _2991 = (_2990 > 0);
struct irr_glsl_SBasicViewParameters
{
mat4 MVP;
mat4x3 MV;
mat4x3 NormalMatAndEyePos;
};
layout(binding = 0, std140) uniform UBO
{
layout(row_major) irr_glsl_SBasicViewParameters params;
} cameraData;
layout(binding = 1) uniform usamplerBuffer sampleSequence;
layout(binding = 2) uniform usampler2D scramblebuf;
layout(binding = 0) uniform sampler2D envMap;
layout(location = 0) out vec4 pixelColor;
layout(location = 0) in vec2 TexCoord;
BSDFNode bsdfs[7];
int stackPtr;
Sphere spheres[8];
Rectangle rectangles[1];
Light lights[1];
Ray_t rayStack[1];
mat4 SPIRV_Cross_workaround_load_row_major(mat4 wrap) { return wrap; }
Sphere Sphere_Sphere(vec3 position, float radius, uint bsdfID, uint lightID)
{
Sphere sphere;
sphere.position = position;
sphere.radius2 = radius * radius;
sphere.bsdfLightIDs = bitfieldInsert(bsdfID, lightID, 16, 16);
return sphere;
}
Rectangle Rectangle_Rectangle(vec3 offset, vec3 edge0, vec3 edge1, uint bsdfID, uint lightID)
{
Rectangle rect;
rect.offset = offset;
rect.edge0 = edge0;
rect.edge1 = edge1;
rect.bsdfLightIDs = bitfieldInsert(bsdfID, lightID, 16, 16);
return rect;
}
uint irr_glsl_rotl(uint x, uint k)
{
return (x << k) | (x >> (32u - k));
}
void irr_glsl_xoroshiro64_state_advance(inout uvec2 state)
{
state.y ^= state.x;
uint param = state.x;
uint param_1 = 26u;
state.x = (irr_glsl_rotl(param, param_1) ^ state.y) ^ (state.y << 9u);
uint param_2 = state.y;
uint param_3 = 13u;
state.y = irr_glsl_rotl(param_2, param_3);
}
uint irr_glsl_xoroshiro64star(inout uvec2 state)
{
uint result = state.x * 2654435771u;
uvec2 param = state;
irr_glsl_xoroshiro64_state_advance(param);
state = param;
return result;
}
vec3 rand3d(uint protoDimension, uint _sample, inout uvec2 scramble_state)
{
uint address = bitfieldInsert(protoDimension, _sample, MAX_DEPTH_LOG2, MAX_SAMPLES_LOG2);
uvec3 seqVal = texelFetch(sampleSequence, int(address)).xyz;
uvec2 param = scramble_state;
uint _2963 = irr_glsl_xoroshiro64star(param);
scramble_state = param;
uvec2 param_1 = scramble_state;
uint _2967 = irr_glsl_xoroshiro64star(param_1);
scramble_state = param_1;
uvec2 param_2 = scramble_state;
uint _2971 = irr_glsl_xoroshiro64star(param_2);
scramble_state = param_2;
seqVal ^= uvec3(_2963, _2967, _2971);
return vec3(seqVal) * uintBitsToFloat(796917764u);
}
void irr_glsl_sincos(float theta, inout float s, inout float c)
{
c = cos(theta);
s = sqrt(1.0 - (c * c));
float _899;
if (theta < 0.0)
{
_899 = -s;
}
else
{
_899 = s;
}
s = _899;
}
vec2 irr_glsl_BoxMullerTransform(vec2 xi, float stddev)
{
float param = (6.283185482025146484375 * xi.y) - 3.1415927410125732421875;
float param_1;
float param_2;
irr_glsl_sincos(param, param_1, param_2);
float sinPhi = param_1;
float cosPhi = param_2;
return (vec2(cosPhi, sinPhi) * sqrt((-2.0) * log(xi.x))) * stddev;
}
float Sphere_intersect(Sphere sphere, vec3 origin, vec3 direction)
{
vec3 relOrigin = origin - sphere.position;
float relOriginLen2 = dot(relOrigin, relOrigin);
float radius2 = sphere.radius2;
float dirDotRelOrigin = dot(direction, relOrigin);
float det = (radius2 - relOriginLen2) + (dirDotRelOrigin * dirDotRelOrigin);
float detsqrt = sqrt(det);
float _1102;
if (relOriginLen2 > radius2)
{
_1102 = -detsqrt;
}
else
{
_1102 = detsqrt;
}
return (-dirDotRelOrigin) + _1102;
}
float Rectangle_intersect(Rectangle rect, vec3 origin, vec3 direction)
{
vec3 h = cross(direction, rect.edge1);
float a = dot(rect.edge0, h);
vec3 relOrigin = origin - rect.offset;
float u = dot(relOrigin, h) / a;
vec3 q = cross(relOrigin, rect.edge0);
float v = dot(direction, q) / a;
float t = dot(rect.edge1, q) / a;
bool intersection = ((((t > 0.0) && (u >= 0.0)) && (v >= 0.0)) && (u <= 1.0)) && (v <= 1.0);
float _1195;
if (intersection)
{
_1195 = t;
}
else
{
_1195 = uintBitsToFloat(4294967295u);
}
return _1195;
}
bool traceRay(ImmutableRay_t _immutable)
{
bool anyHit = bitfieldExtract(_immutable.typeDepthSampleIx, 31, 1) != 0;
int objectID = -1;
float intersectionT = _immutable.maxT;
for (int i = 0; i < 8; i++)
{
Sphere param = spheres[i];
vec3 param_1 = _immutable.origin;
vec3 param_2 = _immutable.direction;
float t = Sphere_intersect(param, param_1, param_2);
bool closerIntersection = (t > 0.0) && (t < intersectionT);
objectID = closerIntersection ? i : objectID;
intersectionT = closerIntersection ? t : intersectionT;
}
int _3272;
for (int i_1 = 0; i_1 < 1; i_1++)
{
Rectangle param_3 = rectangles[i_1];
vec3 param_4 = _immutable.origin;
vec3 param_5 = _immutable.direction;
float t_1 = Rectangle_intersect(param_3, param_4, param_5);
bool closerIntersection_1 = (t_1 > 0.0) && (t_1 < intersectionT);
if (closerIntersection_1)
{
_3272 = i_1 + 8;
}
else
{
_3272 = objectID;
}
objectID = _3272;
intersectionT = closerIntersection_1 ? t_1 : intersectionT;
}
rayStack[stackPtr]._mutable.objectID = uint(objectID);
rayStack[stackPtr]._mutable.intersectionT = intersectionT;
return anyHit;
}
void missProgram()
{
vec3 finalContribution = rayStack[stackPtr]._payload.throughput;
if (rayStack[stackPtr]._immutable.maxT >= 3.4028234663852885981170418348452e+38)
{
finalContribution *= vec3(0.1500000059604644775390625, 0.20999999344348907470703125, 0.300000011920928955078125);
}
else
{
finalContribution *= rayStack[stackPtr]._payload.otherTechniqueHeuristic;
}
rayStack[stackPtr]._payload.accumulation += finalContribution;
}
vec3 Sphere_getNormal(Sphere sphere, vec3 position)
{
float radiusRcp = inversesqrt(sphere.radius2);
return (position - sphere.position) * radiusRcp;
}
vec3 Rectangle_getNormalTimesArea(Rectangle rect)
{
return cross(rect.edge0, rect.edge1);
}
mat2x3 irr_glsl_frisvad(vec3 n)
{
float a = 1.0 / (1.0 + n.z);
float b = ((-n.x) * n.y) * a;
mat2x3 _926;
if (n.z < (-0.99999988079071044921875))
{
_926 = mat2x3(vec3(0.0, -1.0, 0.0), vec3(-1.0, 0.0, 0.0));
}
else
{
_926 = mat2x3(vec3(vec3(1.0 - ((n.x * n.x) * a), b, -n.x)), vec3(vec3(b, 1.0 - ((n.y * n.y) * a), -n.y)));
}
return _926;
}
irr_glsl_AnisotropicViewSurfaceInteraction irr_glsl_calcAnisotropicInteraction(irr_glsl_IsotropicViewSurfaceInteraction isotropic, vec3 T, vec3 B)
{
irr_glsl_AnisotropicViewSurfaceInteraction inter;
inter.isotropic = isotropic;
inter.T = T;
inter.B = B;
inter.TdotV = dot(inter.isotropic.V.dir, inter.T);
inter.BdotV = dot(inter.isotropic.V.dir, inter.B);
return inter;
}
irr_glsl_AnisotropicViewSurfaceInteraction irr_glsl_calcAnisotropicInteraction(irr_glsl_IsotropicViewSurfaceInteraction isotropic)
{
vec3 param = isotropic.N;
mat2x3 TB = irr_glsl_frisvad(param);
irr_glsl_IsotropicViewSurfaceInteraction param_1 = isotropic;
vec3 param_2 = TB[0];
vec3 param_3 = TB[1];
return irr_glsl_calcAnisotropicInteraction(param_1, param_2, param_3);
}
float scene_getLightChoicePdf(Light light)
{
return 1.0;
}
uint Light_getObjectID(Light light)
{
return light.objectID;
}
vec3 Light_getRadiance(Light light)
{
return light.radiance;
}
vec3 irr_glsl_light_deferred_eval_and_prob(inout float pdf, Light light, vec3 L, float intersectionT)
{
Light param = light;
pdf = scene_getLightChoicePdf(param);
Light param_1 = light;
Rectangle rect = rectangles[Light_getObjectID(param_1)];
Rectangle param_2 = rect;
pdf *= ((intersectionT * intersectionT) / abs(dot(Rectangle_getNormalTimesArea(param_2), L)));
Light param_3 = light;
return Light_getRadiance(param_3);
}
uint BSDFNode_getType(BSDFNode node)
{
return bitfieldExtract(node.data[0].w, 0, 2);
}
float BSDFNode_getRoughness(BSDFNode node)
{
return uintBitsToFloat(node.data[1].w);
}
bool BSDFNode_isNotDiffuse(BSDFNode node)
{
BSDFNode param = node;
return BSDFNode_getType(param) != 0u;
}
float BSDFNode_getMISWeight(BSDFNode bsdf)
{
BSDFNode param = bsdf;
float alpha = BSDFNode_getRoughness(param);
BSDFNode param_1 = bsdf;
bool notDiffuse = BSDFNode_isNotDiffuse(param_1);
float _1391;
if (notDiffuse)
{
_1391 = mix(1.0, 0.5, alpha);
}
else
{
_1391 = 0.5;
}
return _1391;
}
bool irr_glsl_partitionRandVariable(float leftProb, inout float xi, inout float rcpChoiceProb)
{
float NEXT_ULP_AFTER_UNITY = uintBitsToFloat(1065353217u);
bool pickRight = xi >= (leftProb * NEXT_ULP_AFTER_UNITY);
xi -= (pickRight ? leftProb : 0.0);
float _986;
if (pickRight)
{
_986 = 1.0 - leftProb;
}
else
{
_986 = leftProb;
}
rcpChoiceProb = 1.0 / _986;
xi *= rcpChoiceProb;
return pickRight;
}
bool BSDFNode_isBSDF(BSDFNode node)
{
BSDFNode param = node;
return BSDFNode_getType(param) == 2u;
}
float getTolerance_common(int depth)
{
float depthRcp = 1.0 / float(depth);
return -8.0;
}
float getEndTolerance(int depth)
{
int param = depth;
return 1.0 - exp2(getTolerance_common(param) + 1.0);
}
irr_glsl_LightSample irr_glsl_createLightSample(vec3 L, float VdotL, vec3 T, vec3 B, vec3 N)
{
irr_glsl_LightSample s;
s.L = L;
s.VdotL = VdotL;
s.TdotL = dot(T, L);
s.BdotL = dot(B, L);
s.NdotL = dot(N, L);
s.NdotL2 = s.NdotL * s.NdotL;
return s;
}
irr_glsl_LightSample irr_glsl_createLightSample(vec3 L, irr_glsl_AnisotropicViewSurfaceInteraction interaction)
{
vec3 param = L;
float param_1 = dot(interaction.isotropic.V.dir, L);
vec3 param_2 = interaction.T;
vec3 param_3 = interaction.B;
vec3 param_4 = interaction.isotropic.N;
return irr_glsl_createLightSample(param, param_1, param_2, param_3, param_4);
}
irr_glsl_LightSample irr_glsl_light_generate_and_remainder_and_pdf(out vec3 remainder, out float pdf, out float newRayMaxT, vec3 origin, irr_glsl_AnisotropicViewSurfaceInteraction interaction, bool isBSDF, vec3 u, int depth)
{
Light light = lights[0];
Light param = light;
float choicePdf = scene_getLightChoicePdf(param);
Light param_1 = light;
Rectangle rect = rectangles[Light_getObjectID(param_1)];
vec3 point = (rect.offset + (rect.edge0 * u.x)) + (rect.edge1 * u.y);
vec3 L = point - origin;
float distanceSq = dot(L, L);
float rcpDistance = inversesqrt(distanceSq);
L *= rcpDistance;
float dist = 1.0 / rcpDistance;
Rectangle param_2 = rect;
float rcpPdf = abs(dot(Rectangle_getNormalTimesArea(param_2), L)) / (distanceSq * choicePdf);
Light param_3 = light;
remainder = Light_getRadiance(param_3) * rcpPdf;
pdf = 1.0 / rcpPdf;
int param_4 = depth;
newRayMaxT = getEndTolerance(param_4) * dist;
vec3 param_5 = L;
irr_glsl_AnisotropicViewSurfaceInteraction param_6 = interaction;
return irr_glsl_createLightSample(param_5, param_6);
}
vec3 BSDFNode_getRealEta(BSDFNode node)
{
return uintBitsToFloat(node.data[0].xyz);
}
vec3 BSDFNode_getImaginaryEta(BSDFNode node)
{
return uintBitsToFloat(node.data[1].xyz);
}
mat2x3 BSDFNode_getEta(BSDFNode node)
{
BSDFNode param = node;
BSDFNode param_1 = node;
return mat2x3(vec3(BSDFNode_getRealEta(param)), vec3(BSDFNode_getImaginaryEta(param_1)));
}
bool irr_glsl_isTransmissionPath(float NdotV, float NdotL)
{
return ((floatBitsToUint(NdotV) ^ floatBitsToUint(NdotL)) & 2147483648u) != 0u;
}
bool irr_glsl_getOrientedEtas(out float orientedEta, out float rcpOrientedEta, float NdotI, float eta)
{
bool backside = NdotI < 0.0;
float rcpEta = 1.0 / eta;
orientedEta = backside ? rcpEta : eta;
rcpOrientedEta = backside ? eta : rcpEta;
return backside;
}
vec3 irr_glsl_computeUnnormalizedMicrofacetNormal(bool _refract, vec3 V, vec3 L, float orientedEta)
{
float etaFactor = _refract ? orientedEta : 1.0;
vec3 tmpH = V + (L * etaFactor);
vec3 _850;
if (_refract)
{
_850 = -tmpH;
}
else
{
_850 = tmpH;
}
return _850;
}
vec3 irr_glsl_computeMicrofacetNormal(bool _refract, vec3 V, vec3 L, float orientedEta)
{
bool param = _refract;
vec3 param_1 = V;
vec3 param_2 = L;
float param_3 = orientedEta;
vec3 H = irr_glsl_computeUnnormalizedMicrofacetNormal(param, param_1, param_2, param_3);
float unnormRcpLen = inversesqrt(dot(H, H));
return H * unnormRcpLen;
}
bool irr_glsl_calcIsotropicMicrofacetCache(inout irr_glsl_IsotropicMicrofacetCache _cache, bool transmitted, vec3 V, vec3 L, vec3 N, float NdotL, float VdotL, float orientedEta, float rcpOrientedEta, inout vec3 H)
{
bool param = transmitted;
vec3 param_1 = V;
vec3 param_2 = L;
float param_3 = orientedEta;
H = irr_glsl_computeMicrofacetNormal(param, param_1, param_2, param_3);
_cache.VdotH = dot(V, H);
_cache.LdotH = dot(L, H);
_cache.NdotH = dot(N, H);
_cache.NdotH2 = _cache.NdotH * _cache.NdotH;
bool _1715;
if (transmitted)
{
bool _1707 = VdotL > (-min(orientedEta, rcpOrientedEta));
bool _1714;
if (!_1707)
{
_1714 = _cache.NdotH < 0.0;
}
else
{
_1714 = _1707;
}
_1715 = _1714;
}
else
{
_1715 = transmitted;
}
return !_1715;
}
bool irr_glsl_calcAnisotropicMicrofacetCache(inout irr_glsl_AnisotropicMicrofacetCache _cache, bool transmitted, vec3 V, vec3 L, vec3 T, vec3 B, vec3 N, float NdotL, float VdotL, float orientedEta, float rcpOrientedEta)
{
bool param_1 = transmitted;
vec3 param_2 = V;
vec3 param_3 = L;
vec3 param_4 = N;
float param_5 = NdotL;
float param_6 = VdotL;
float param_7 = orientedEta;
float param_8 = rcpOrientedEta;
irr_glsl_IsotropicMicrofacetCache param;
vec3 param_9;
bool _1739 = irr_glsl_calcIsotropicMicrofacetCache(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8, param_9);
_cache.isotropic = param;
vec3 H = param_9;
bool valid = _1739;
_cache.TdotH = dot(T, H);
_cache.BdotH = dot(B, H);
return valid;
}
bool irr_glsl_calcAnisotropicMicrofacetCache(out irr_glsl_AnisotropicMicrofacetCache _cache, irr_glsl_AnisotropicViewSurfaceInteraction interaction, irr_glsl_LightSample _sample, float eta)
{
float NdotV = interaction.isotropic.NdotV;
float NdotL = _sample.NdotL;
float param = NdotV;
float param_1 = NdotL;
bool transmitted = irr_glsl_isTransmissionPath(param, param_1);
float param_4 = NdotV;
float param_5 = eta;
float param_2;
float param_3;
bool _1775 = irr_glsl_getOrientedEtas(param_2, param_3, param_4, param_5);
float orientedEta = param_2;
float rcpOrientedEta = param_3;
bool backside = _1775;
vec3 V = interaction.isotropic.V.dir;
vec3 L = _sample.L;
float VdotL = dot(V, L);
bool param_7 = transmitted;
vec3 param_8 = V;
vec3 param_9 = L;
vec3 param_10 = interaction.T;
vec3 param_11 = interaction.B;
vec3 param_12 = interaction.isotropic.N;
float param_13 = NdotL;
float param_14 = VdotL;
float param_15 = orientedEta;
float param_16 = rcpOrientedEta;
irr_glsl_AnisotropicMicrofacetCache param_6;
bool _1812 = irr_glsl_calcAnisotropicMicrofacetCache(param_6, param_7, param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15, param_16);
_cache = param_6;
return _1812;
}
vec3 irr_glsl_getTangentSpaceV(irr_glsl_AnisotropicViewSurfaceInteraction interaction)
{
return vec3(interaction.TdotV, interaction.BdotV, interaction.isotropic.NdotV);
}
mat3 irr_glsl_getTangentFrame(irr_glsl_AnisotropicViewSurfaceInteraction interaction)
{
return mat3(vec3(interaction.T), vec3(interaction.B), vec3(interaction.isotropic.N));
}
vec3 irr_glsl_ggx_cos_generate(vec3 localV, vec2 u, float _ax, float _ay)
{
vec3 V = normalize(vec3(_ax * localV.x, _ay * localV.y, localV.z));
float lensq = (V.x * V.x) + (V.y * V.y);
vec3 _2227;
if (lensq > 0.0)
{
_2227 = vec3(-V.y, V.x, 0.0) * inversesqrt(lensq);
}
else
{
_2227 = vec3(1.0, 0.0, 0.0);
}
vec3 T1 = _2227;
vec3 T2 = cross(V, T1);
float r = sqrt(u.x);
float phi = 6.283185482025146484375 * u.y;
float t1 = r * cos(phi);
float t2 = r * sin(phi);
float s = 0.5 * (1.0 + V.z);
t2 = ((1.0 - s) * sqrt(1.0 - (t1 * t1))) + (s * t2);
vec3 H = ((T1 * t1) + (T2 * t2)) + (V * sqrt(max(0.0, (1.0 - (t1 * t1)) - (t2 * t2))));
return normalize(vec3(_ax * H.x, _ay * H.y, H.z));
}
float irr_glsl_fresnel_dielectric_common(float orientedEta2, float AbsCosTheta)
{
float SinTheta2 = 1.0 - (AbsCosTheta * AbsCosTheta);
float t0 = sqrt(max(orientedEta2 - SinTheta2, 0.0));
float rs = (AbsCosTheta - t0) / (AbsCosTheta + t0);
float t2 = orientedEta2 * AbsCosTheta;
float rp = (t0 - t2) / (t0 + t2);
return ((rs * rs) + (rp * rp)) * 0.5;
}
void irr_glsl_calcAnisotropicMicrofacetCache_common(inout irr_glsl_AnisotropicMicrofacetCache _cache, vec3 tangentSpaceV, vec3 tangentSpaceH)
{
_cache.isotropic.VdotH = dot(tangentSpaceV, tangentSpaceH);
_cache.isotropic.NdotH = tangentSpaceH.z;
_cache.isotropic.NdotH2 = tangentSpaceH.z * tangentSpaceH.z;
_cache.TdotH = tangentSpaceH.x;
_cache.BdotH = tangentSpaceH.y;
}
float irr_glsl_refract_compute_NdotT2(float NdotI2, float rcpOrientedEta2)
{
return ((rcpOrientedEta2 * NdotI2) + 1.0) - rcpOrientedEta2;
}
float irr_glsl_refract_compute_NdotT(bool backside, float NdotI2, float rcpOrientedEta2)
{
float param = NdotI2;
float param_1 = rcpOrientedEta2;
float abs_NdotT = sqrt(irr_glsl_refract_compute_NdotT2(param, param_1));
float _812;
if (backside)
{
_812 = abs_NdotT;
}
else
{
_812 = -abs_NdotT;
}
return _812;
}
vec3 irr_glsl_reflect_refract_impl(bool _refract, vec3 I, vec3 N, float NdotI, float NdotTorR, float rcpOrientedEta)
{
return (N * ((NdotI * (_refract ? rcpOrientedEta : 1.0)) + NdotTorR)) - (I * (_refract ? rcpOrientedEta : 1.0));
}
irr_glsl_AnisotropicMicrofacetCache irr_glsl_calcAnisotropicMicrofacetCache(bool transmitted, vec3 tangentSpaceV, vec3 tangentSpaceH, out vec3 tangentSpaceL, float rcpOrientedEta, float rcpOrientedEta2)
{
vec3 param_1 = tangentSpaceV;
vec3 param_2 = tangentSpaceH;
irr_glsl_AnisotropicMicrofacetCache param;
irr_glsl_calcAnisotropicMicrofacetCache_common(param, param_1, param_2);
irr_glsl_AnisotropicMicrofacetCache _cache = param;
float VdotH = _cache.isotropic.VdotH;
float _1869;
if (transmitted)
{
bool param_3 = VdotH < 0.0;
float param_4 = VdotH * VdotH;
float param_5 = rcpOrientedEta2;
_1869 = irr_glsl_refract_compute_NdotT(param_3, param_4, param_5);
}
else
{
_1869 = VdotH;
}
_cache.isotropic.LdotH = _1869;
bool param_6 = transmitted;
vec3 param_7 = tangentSpaceV;
vec3 param_8 = tangentSpaceH;
float param_9 = VdotH;
float param_10 = _cache.isotropic.LdotH;
float param_11 = rcpOrientedEta;
tangentSpaceL = irr_glsl_reflect_refract_impl(param_6, param_7, param_8, param_9, param_10, param_11);
return _cache;
}
irr_glsl_LightSample irr_glsl_createLightSampleTangentSpace(vec3 tangentSpaceV, vec3 tangentSpaceL, mat3 tangentFrame)
{
irr_glsl_LightSample s;
s.L = tangentFrame * tangentSpaceL;
s.VdotL = dot(tangentSpaceV, tangentSpaceL);
s.TdotL = tangentSpaceL.x;
s.BdotL = tangentSpaceL.y;
s.NdotL = tangentSpaceL.z;
s.NdotL2 = s.NdotL * s.NdotL;
return s;
}
irr_glsl_LightSample irr_glsl_ggx_dielectric_cos_generate_wo_clamps(vec3 localV, bool backside, vec3 upperHemisphereLocalV, mat3 m, inout vec3 u, float _ax, float _ay, float rcpOrientedEta, float orientedEta2, float rcpOrientedEta2, out irr_glsl_AnisotropicMicrofacetCache _cache)
{
vec3 param = upperHemisphereLocalV;
vec2 param_1 = u.xy;
float param_2 = _ax;
float param_3 = _ay;
vec3 H = irr_glsl_ggx_cos_generate(param, param_1, param_2, param_3);
float VdotH = dot(localV, H);
float param_4 = orientedEta2;
float param_5 = abs(VdotH);
float reflectance = irr_glsl_fresnel_dielectric_common(param_4, param_5);
float param_6 = reflectance;
float param_7 = u.z;
float param_8;
bool _2445 = irr_glsl_partitionRandVariable(param_6, param_7, param_8);
u.z = param_7;
float rcpChoiceProb = param_8;
bool transmitted = _2445;
bool param_9 = transmitted;
vec3 param_10 = localV;
vec3 param_11 = H;
float param_13 = rcpOrientedEta;
float param_14 = rcpOrientedEta2;
vec3 param_12;
irr_glsl_AnisotropicMicrofacetCache _2461 = irr_glsl_calcAnisotropicMicrofacetCache(param_9, param_10, param_11, param_12, param_13, param_14);
vec3 localL = param_12;
_cache = _2461;
vec3 param_15 = localV;
vec3 param_16 = localL;
mat3 param_17 = m;
return irr_glsl_createLightSampleTangentSpace(param_15, param_16, param_17);
}
irr_glsl_LightSample irr_glsl_ggx_dielectric_cos_generate(irr_glsl_AnisotropicViewSurfaceInteraction interaction, vec3 u, float ax, float ay, float eta, out irr_glsl_AnisotropicMicrofacetCache _cache)
{
irr_glsl_AnisotropicViewSurfaceInteraction param = interaction;
vec3 localV = irr_glsl_getTangentSpaceV(param);
float param_3 = interaction.isotropic.NdotV;
float param_4 = eta;
float param_1;
float param_2;
bool _2486 = irr_glsl_getOrientedEtas(param_1, param_2, param_3, param_4);
float orientedEta = param_1;
float rcpOrientedEta = param_2;
bool backside = _2486;
vec3 _2491;
if (backside)
{
_2491 = -localV;
}
else
{
_2491 = localV;
}
vec3 upperHemisphereV = _2491;
irr_glsl_AnisotropicViewSurfaceInteraction param_5 = interaction;
mat3 m = irr_glsl_getTangentFrame(param_5);
vec3 param_6 = localV;
bool param_7 = backside;
vec3 param_8 = upperHemisphereV;
mat3 param_9 = m;
vec3 param_10 = u;
float param_11 = ax;
float param_12 = ay;
float param_13 = rcpOrientedEta;
float param_14 = orientedEta * orientedEta;
float param_15 = rcpOrientedEta * rcpOrientedEta;
irr_glsl_AnisotropicMicrofacetCache param_16;
irr_glsl_LightSample _2528 = irr_glsl_ggx_dielectric_cos_generate_wo_clamps(param_6, param_7, param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15, param_16);
_cache = param_16;
return _2528;
}
vec2 irr_glsl_concentricMapping(vec2 _u)
{
vec2 u = (_u * 2.0) - vec2(1.0);
vec2 p;
if (all(equal(u, vec2(0.0))))
{
p = vec2(0.0);
}
else
{
float r;
float theta;
if (abs(u.x) > abs(u.y))
{
r = u.x;
theta = 0.785398185253143310546875 * (u.y / u.x);
}
else
{
r = u.y;
theta = 1.57079637050628662109375 - (0.785398185253143310546875 * (u.x / u.y));
}
p = vec2(cos(theta), sin(theta)) * r;
}
return p;
}
vec3 irr_glsl_projected_hemisphere_generate(vec2 _sample)
{
vec2 param = _sample;
vec2 p = irr_glsl_concentricMapping(param);
float z = sqrt(max(0.0, (1.0 - (p.x * p.x)) - (p.y * p.y)));
return vec3(p.x, p.y, z);
}
irr_glsl_LightSample irr_glsl_lambertian_cos_generate_wo_clamps(vec3 tangentSpaceV, mat3 m, vec2 u)
{
vec2 param = u;
vec3 L = irr_glsl_projected_hemisphere_generate(param);
vec3 param_1 = tangentSpaceV;
vec3 param_2 = L;
mat3 param_3 = m;
return irr_glsl_createLightSampleTangentSpace(param_1, param_2, param_3);
}
irr_glsl_LightSample irr_glsl_oren_nayar_cos_generate_wo_clamps(vec3 tangentSpaceV, mat3 m, vec2 u)
{
vec3 param = tangentSpaceV;
mat3 param_1 = m;
vec2 param_2 = u;
return irr_glsl_lambertian_cos_generate_wo_clamps(param, param_1, param_2);
}
irr_glsl_LightSample irr_glsl_oren_nayar_cos_generate(irr_glsl_AnisotropicViewSurfaceInteraction interaction, vec2 u, float a2)
{
irr_glsl_AnisotropicViewSurfaceInteraction param = interaction;
irr_glsl_AnisotropicViewSurfaceInteraction param_1 = interaction;
vec3 param_2 = irr_glsl_getTangentSpaceV(param);
mat3 param_3 = irr_glsl_getTangentFrame(param_1);
vec2 param_4 = u;
return irr_glsl_oren_nayar_cos_generate_wo_clamps(param_2, param_3, param_4);
}
vec3 irr_glsl_reflect(vec3 I, vec3 N, float NdotI)
{
return ((N * 2.0) * NdotI) - I;
}
irr_glsl_AnisotropicMicrofacetCache irr_glsl_calcAnisotropicMicrofacetCache(vec3 tangentSpaceV, vec3 tangentSpaceH, out vec3 tangentSpaceL)
{
vec3 param_1 = tangentSpaceV;
vec3 param_2 = tangentSpaceH;
irr_glsl_AnisotropicMicrofacetCache param;
irr_glsl_calcAnisotropicMicrofacetCache_common(param, param_1, param_2);
irr_glsl_AnisotropicMicrofacetCache _cache = param;
_cache.isotropic.LdotH = _cache.isotropic.VdotH;
vec3 param_3 = tangentSpaceV;
vec3 param_4 = tangentSpaceH;
float param_5 = _cache.isotropic.VdotH;
tangentSpaceL = irr_glsl_reflect(param_3, param_4, param_5);
return _cache;
}
irr_glsl_LightSample irr_glsl_ggx_cos_generate_wo_clamps(vec3 localV, mat3 m, vec2 u, float _ax, float _ay, out irr_glsl_AnisotropicMicrofacetCache _cache)
{
vec3 param = localV;
vec2 param_1 = u;
float param_2 = _ax;
float param_3 = _ay;
vec3 H = irr_glsl_ggx_cos_generate(param, param_1, param_2, param_3);
vec3 param_4 = localV;
vec3 param_5 = H;
vec3 param_6;
irr_glsl_AnisotropicMicrofacetCache _2332 = irr_glsl_calcAnisotropicMicrofacetCache(param_4, param_5, param_6);
vec3 localL = param_6;
_cache = _2332;
vec3 param_7 = localV;
vec3 param_8 = localL;
mat3 param_9 = m;
return irr_glsl_createLightSampleTangentSpace(param_7, param_8, param_9);
}
irr_glsl_LightSample irr_glsl_ggx_cos_generate(irr_glsl_AnisotropicViewSurfaceInteraction interaction, vec2 u, float _ax, float _ay, out irr_glsl_AnisotropicMicrofacetCache _cache)
{
irr_glsl_AnisotropicViewSurfaceInteraction param = interaction;
vec3 localV = irr_glsl_getTangentSpaceV(param);
irr_glsl_AnisotropicViewSurfaceInteraction param_1 = interaction;
mat3 m = irr_glsl_getTangentFrame(param_1);
vec3 param_2 = localV;
mat3 param_3 = m;
vec2 param_4 = u;
float param_5 = _ax;
float param_6 = _ay;
irr_glsl_AnisotropicMicrofacetCache param_7;
irr_glsl_LightSample _2362 = irr_glsl_ggx_cos_generate_wo_clamps(param_2, param_3, param_4, param_5, param_6, param_7);
_cache = param_7;
return _2362;
}
irr_glsl_LightSample irr_glsl_bsdf_cos_generate(irr_glsl_AnisotropicViewSurfaceInteraction interaction, vec3 u, BSDFNode bsdf, float monochromeEta, inout irr_glsl_AnisotropicMicrofacetCache _cache)
{
BSDFNode param = bsdf;
float a = BSDFNode_getRoughness(param);
BSDFNode param_1 = bsdf;
mat2x3 ior = BSDFNode_getEta(param_1);
float param_4 = interaction.isotropic.NdotV;
float param_5 = monochromeEta;
float param_2;
float param_3;
bool _2700 = irr_glsl_getOrientedEtas(param_2, param_3, param_4, param_5);
float orientedEta = param_2;
float rcpOrientedEta = param_3;
bool viewerInsideMedium = _2700;
BSDFNode param_6 = bsdf;
irr_glsl_LightSample smpl;
switch (BSDFNode_getType(param_6))
{
case 0u:
{
irr_glsl_AnisotropicViewSurfaceInteraction param_7 = interaction;
vec2 param_8 = u.xy;
float param_9 = a * a;
smpl = irr_glsl_oren_nayar_cos_generate(param_7, param_8, param_9);
break;
}
case 1u:
{
irr_glsl_AnisotropicViewSurfaceInteraction param_10 = interaction;
vec2 param_11 = u.xy;
float param_12 = a;
float param_13 = a;
irr_glsl_AnisotropicMicrofacetCache param_14;
irr_glsl_LightSample _2732 = irr_glsl_ggx_cos_generate(param_10, param_11, param_12, param_13, param_14);
_cache = param_14;
smpl = _2732;
break;
}
default:
{
irr_glsl_AnisotropicViewSurfaceInteraction param_15 = interaction;
vec3 param_16 = u;
float param_17 = a;
float param_18 = a;
float param_19 = monochromeEta;
irr_glsl_AnisotropicMicrofacetCache param_20;
irr_glsl_LightSample _2746 = irr_glsl_ggx_dielectric_cos_generate(param_15, param_16, param_17, param_18, param_19, param_20);
_cache = param_20;
smpl = _2746;
break;
}
}
return smpl;
}
float irr_glsl_conditionalAbsOrMax(bool cond, float x, float limit)
{
float condAbs = uintBitsToFloat(floatBitsToUint(x) & (cond ? 2147483647u : 4294967295u));
return max(condAbs, limit);
}
vec3 irr_glsl_fresnel_conductor(vec3 Eta, vec3 Etak, float CosTheta)
{
float CosTheta2 = CosTheta * CosTheta;
float SinTheta2 = 1.0 - CosTheta2;
vec3 EtaLen2 = (Eta * Eta) + (Etak * Etak);
vec3 etaCosTwice = (Eta * CosTheta) * 2.0;
vec3 rs_common = EtaLen2 + vec3(CosTheta2);
vec3 rs2 = (rs_common - etaCosTwice) / (rs_common + etaCosTwice);
vec3 rp_common = (EtaLen2 * CosTheta2) + vec3(1.0);
vec3 rp2 = (rp_common - etaCosTwice) / (rp_common + etaCosTwice);
return (rs2 + rp2) * 0.5;
}
vec3 BSDFNode_getReflectance(BSDFNode node, float VdotH)
{
vec3 albedoOrRealIoR = uintBitsToFloat(node.data[0].xyz);
BSDFNode param = node;
if (BSDFNode_isNotDiffuse(param))
{
BSDFNode param_1 = node;
vec3 param_2 = albedoOrRealIoR;
vec3 param_3 = BSDFNode_getImaginaryEta(param_1);
float param_4 = VdotH;
return irr_glsl_fresnel_conductor(param_2, param_3, param_4);
}
else
{
return albedoOrRealIoR;
}
}
float irr_glsl_ggx_trowbridge_reitz(float a2, float NdotH2)
{
float denom = (NdotH2 * (a2 - 1.0)) + 1.0;
return (a2 * 0.3183098733425140380859375) / (denom * denom);
}
float irr_glsl_smith_ggx_devsh_part(float NdotX2, float a2, float one_minus_a2)
{
return sqrt(a2 + (one_minus_a2 * NdotX2));
}
float irr_glsl_GGXSmith_G1_wo_numerator(float NdotX, float devsh_part)
{
return 1.0 / (NdotX + devsh_part);
}
float irr_glsl_smith_VNDF_pdf_wo_clamps(float ndf, float G1_over_2NdotV, float absNdotV, bool transmitted, float VdotH, float LdotH, float VdotHLdotH, float orientedEta, float reflectance)
{
float _2109;
if (transmitted)
{
_2109 = 1.0 - reflectance;
}
else
{
_2109 = reflectance;
}
float FNG = (_2109 * ndf) * G1_over_2NdotV;
float factor = 0.5;
if (transmitted)
{
float VdotH_etaLdotH = VdotH + (orientedEta * LdotH);
factor *= (((-2.0) * VdotHLdotH) / (VdotH_etaLdotH * VdotH_etaLdotH));
}
return FNG * factor;
}
float irr_glsl_ggx_dielectric_pdf_wo_clamps(bool transmitted, float reflectance, float ndf, float devsh_v, float absNdotV, float VdotH, float LdotH, float VdotHLdotH, float orientedEta)
{
float param = absNdotV;
float param_1 = devsh_v;
float param_2 = ndf;
float param_3 = irr_glsl_GGXSmith_G1_wo_numerator(param, param_1);
float param_4 = absNdotV;
bool param_5 = transmitted;
float param_6 = VdotH;
float param_7 = LdotH;
float param_8 = VdotHLdotH;
float param_9 = orientedEta;
float param_10 = reflectance;
return irr_glsl_smith_VNDF_pdf_wo_clamps(param_2, param_3, param_4, param_5, param_6, param_7, param_8, param_9, param_10);
}
float irr_glsl_ggx_smith_G2_over_G1_devsh(float NdotL, float NdotL2, float NdotV, float devsh_v, float a2, float one_minus_a2)
{
float G2_over_G1 = NdotL * (devsh_v + NdotV);
float param = NdotL2;
float param_1 = a2;
float param_2 = one_minus_a2;
G2_over_G1 /= ((NdotV * irr_glsl_smith_ggx_devsh_part(param, param_1, param_2)) + (NdotL * devsh_v));
return G2_over_G1;
}
float irr_glsl_ggx_dielectric_cos_remainder_and_pdf_wo_clamps(out float pdf, float ndf, bool transmitted, float absNdotL, float NdotL2, float absNdotV, float NdotV2, float VdotH, float LdotH, float VdotHLdotH, float reflectance, float orientedEta, float a2)
{
float one_minus_a2 = 1.0 - a2;
float param = NdotV2;
float param_1 = a2;
float param_2 = one_minus_a2;
float devsh_v = irr_glsl_smith_ggx_devsh_part(param, param_1, param_2);
bool param_3 = transmitted;
float param_4 = reflectance;
float param_5 = ndf;
float param_6 = devsh_v;
float param_7 = absNdotV;
float param_8 = VdotH;
float param_9 = LdotH;
float param_10 = VdotHLdotH;
float param_11 = orientedEta;
pdf = irr_glsl_ggx_dielectric_pdf_wo_clamps(param_3, param_4, param_5, param_6, param_7, param_8, param_9, param_10, param_11);
float param_12 = absNdotL;
float param_13 = NdotL2;
float param_14 = absNdotV;
float param_15 = devsh_v;
float param_16 = a2;
float param_17 = one_minus_a2;
return irr_glsl_ggx_smith_G2_over_G1_devsh(param_12, param_13, param_14, param_15, param_16, param_17);
}
float irr_glsl_ggx_dielectric_cos_remainder_and_pdf(out float pdf, irr_glsl_LightSample _sample, irr_glsl_IsotropicViewSurfaceInteraction interaction, irr_glsl_IsotropicMicrofacetCache _cache, float eta, float a2)
{
float param = a2;
float param_1 = _cache.NdotH2;
float ndf = irr_glsl_ggx_trowbridge_reitz(param, param_1);
float param_4 = _cache.VdotH;
float param_5 = eta;
float param_2;
float param_3;
bool _2619 = irr_glsl_getOrientedEtas(param_2, param_3, param_4, param_5);
float orientedEta = param_2;
float dummy = param_3;
bool backside = _2619;
float orientedEta2 = orientedEta * orientedEta;
float VdotHLdotH = _cache.VdotH * _cache.LdotH;
bool transmitted = VdotHLdotH < 0.0;
float param_6 = orientedEta2;
float param_7 = abs(_cache.VdotH);
float reflectance = irr_glsl_fresnel_dielectric_common(param_6, param_7);
float absNdotV = abs(interaction.NdotV);
float param_9 = ndf;
bool param_10 = transmitted;
float param_11 = abs(_sample.NdotL);
float param_12 = _sample.NdotL2;
float param_13 = absNdotV;
float param_14 = interaction.NdotV_squared;
float param_15 = _cache.VdotH;
float param_16 = _cache.LdotH;
float param_17 = VdotHLdotH;
float param_18 = reflectance;
float param_19 = orientedEta;
float param_20 = a2;
float param_8;
float _2678 = irr_glsl_ggx_dielectric_cos_remainder_and_pdf_wo_clamps(param_8, param_9, param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20);
pdf = param_8;
return _2678;
}
float irr_glsl_projected_hemisphere_remainder_and_pdf(out float pdf, float L_z)
{
pdf = L_z * 0.3183098733425140380859375;
return 1.0;
}
float irr_glsl_lambertian_pdf_wo_clamps(float maxNdotL)
{
float param_1 = maxNdotL;
float param;
float _2010 = irr_glsl_projected_hemisphere_remainder_and_pdf(param, param_1);
float pdf = param;
return pdf;
}
float irr_glsl_oren_nayar_pdf_wo_clamps(float maxNdotL)
{
float param = maxNdotL;
return irr_glsl_lambertian_pdf_wo_clamps(param);
}
float irr_glsl_oren_nayar_cos_rec_pi_factored_out_wo_clamps(float _a2, float VdotL, float maxNdotL, float maxNdotV)
{
float a2 = _a2 * 0.5;
vec2 AB = vec2(1.0, 0.0) + ((vec2(-0.5, 0.449999988079071044921875) * vec2(a2, a2)) / vec2(a2 + 0.3300000131130218505859375, a2 + 0.0900000035762786865234375));
float C = 1.0 / max(maxNdotL, maxNdotV);
float cos_phi_sin_theta = max(VdotL - (maxNdotL * maxNdotV), 0.0);
return AB.x + ((AB.y * cos_phi_sin_theta) * C);
}
float irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(out float pdf, float a2, float VdotL, float maxNdotL, float maxNdotV)
{
float param = maxNdotL;
pdf = irr_glsl_oren_nayar_pdf_wo_clamps(param);
float param_1 = a2;
float param_2 = VdotL;
float param_3 = maxNdotL;
float param_4 = maxNdotV;
return irr_glsl_oren_nayar_cos_rec_pi_factored_out_wo_clamps(param_1, param_2, param_3, param_4);
}
float irr_glsl_smith_VNDF_pdf_wo_clamps(float ndf, float G1_over_2NdotV)
{
return (ndf * 0.5) * G1_over_2NdotV;
}
float irr_glsl_ggx_pdf_wo_clamps(float ndf, float devsh_v, float maxNdotV)
{
float param = maxNdotV;
float param_1 = devsh_v;
float param_2 = ndf;
float param_3 = irr_glsl_GGXSmith_G1_wo_numerator(param, param_1);
return irr_glsl_smith_VNDF_pdf_wo_clamps(param_2, param_3);
}
vec3 irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(out float pdf, float ndf, float maxNdotL, float NdotL2, float maxNdotV, float NdotV2, vec3 reflectance, float a2)
{
float one_minus_a2 = 1.0 - a2;
float param = NdotV2;
float param_1 = a2;
float param_2 = one_minus_a2;
float devsh_v = irr_glsl_smith_ggx_devsh_part(param, param_1, param_2);
float param_3 = ndf;
float param_4 = devsh_v;
float param_5 = maxNdotV;
pdf = irr_glsl_ggx_pdf_wo_clamps(param_3, param_4, param_5);
float param_6 = maxNdotL;
float param_7 = NdotL2;
float param_8 = maxNdotV;
float param_9 = devsh_v;
float param_10 = a2;
float param_11 = one_minus_a2;
float G2_over_G1 = irr_glsl_ggx_smith_G2_over_G1_devsh(param_6, param_7, param_8, param_9, param_10, param_11);
return reflectance * G2_over_G1;
}
vec3 irr_glsl_bsdf_cos_remainder_and_pdf(inout float pdf, irr_glsl_LightSample _sample, irr_glsl_AnisotropicViewSurfaceInteraction interaction, BSDFNode bsdf, float monochromeEta, irr_glsl_AnisotropicMicrofacetCache _cache)
{
float param = interaction.isotropic.NdotV;
float param_1 = _sample.NdotL;
bool transmitted = irr_glsl_isTransmissionPath(param, param_1);
BSDFNode param_2 = bsdf;
bool transmissive = BSDFNode_isBSDF(param_2);
bool param_3 = transmissive;
float param_4 = _sample.NdotL;
float param_5 = 0.0;
float clampedNdotL = irr_glsl_conditionalAbsOrMax(param_3, param_4, param_5);
bool param_6 = transmissive;
float param_7 = interaction.isotropic.NdotV;
float param_8 = 0.0;
float clampedNdotV = irr_glsl_conditionalAbsOrMax(param_6, param_7, param_8);
vec3 remainder;
if ((clampedNdotV > 9.9999999392252902907785028219223e-09) && (clampedNdotL > 9.9999999392252902907785028219223e-09))
{
BSDFNode param_9 = bsdf;
mat2x3 ior = BSDFNode_getEta(param_9);
BSDFNode param_10 = bsdf;
float param_11 = _cache.isotropic.VdotH;
vec3 reflectance = BSDFNode_getReflectance(param_10, param_11);
float param_14 = interaction.isotropic.NdotV;
float param_15 = monochromeEta;
float param_12;
float param_13;
bool _2810 = irr_glsl_getOrientedEtas(param_12, param_13, param_14, param_15);
float orientedEta = param_12;
float rcpOrientedEta = param_13;
bool viewerInsideMedium = _2810;
float VdotL = dot(interaction.isotropic.V.dir, _sample.L);
BSDFNode param_16 = bsdf;
float a = max(BSDFNode_getRoughness(param_16), 0.00999999977648258209228515625);
float a2 = a * a;
BSDFNode param_17 = bsdf;
switch (BSDFNode_getType(param_17))
{
case 0u:
{
float param_19 = a * a;
float param_20 = VdotL;
float param_21 = clampedNdotL;
float param_22 = clampedNdotV;
float param_18;
float _2849 = irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(param_18, param_19, param_20, param_21, param_22);
pdf = param_18;
remainder = reflectance * _2849;
break;
}
case 1u:
{
float param_23 = a2;
float param_24 = _cache.isotropic.NdotH2;
float param_26 = irr_glsl_ggx_trowbridge_reitz(param_23, param_24);
float param_27 = clampedNdotL;
float param_28 = _sample.NdotL2;
float param_29 = clampedNdotV;
float param_30 = interaction.isotropic.NdotV_squared;
vec3 param_31 = reflectance;
float param_32 = a2;
float param_25;
vec3 _2875 = irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(param_25, param_26, param_27, param_28, param_29, param_30, param_31, param_32);
pdf = param_25;
remainder = _2875;
break;
}
default:
{
irr_glsl_LightSample param_34 = _sample;
irr_glsl_IsotropicViewSurfaceInteraction param_35 = interaction.isotropic;
irr_glsl_IsotropicMicrofacetCache param_36 = _cache.isotropic;
float param_37 = monochromeEta;
float param_38 = a * a;
float param_33;
float _2893 = irr_glsl_ggx_dielectric_cos_remainder_and_pdf(param_33, param_34, param_35, param_36, param_37, param_38);
pdf = param_33;
remainder = vec3(_2893);
break;
}
}
}
else
{
remainder = vec3(0.0);
}
return remainder;
}
vec3 irr_glsl_eotf_impl_shared_2_4(vec3 nonlinear, float vertex)
{
bvec3 right = greaterThan(nonlinear, vec3(vertex));
return mix(nonlinear / vec3(12.9200000762939453125), pow((nonlinear + vec3(0.054999999701976776123046875)) / vec3(1.05499994754791259765625), vec3(2.400000095367431640625)), right);
}
vec3 irr_glsl_eotf_sRGB(vec3 nonlinear)
{
bvec3 negatif = lessThan(nonlinear, vec3(0.0));
vec3 param = abs(nonlinear);
float param_1 = 0.040449999272823333740234375;
vec3 absVal = irr_glsl_eotf_impl_shared_2_4(param, param_1);
return mix(absVal, -absVal, negatif);
}
float getLuma(vec3 col)
{
return dot(transpose(mat3(vec3(0.41245639324188232421875, 0.21267290413379669189453125, 0.01933390088379383087158203125), vec3(0.3575761020183563232421875, 0.715152204036712646484375, 0.119191996753215789794921875), vec3(0.180437505245208740234375, 0.072175003588199615478515625, 0.950304090976715087890625)))[1], col);
}
float getStartTolerance(int depth)
{
int param = depth;
return exp2(getTolerance_common(param));
}
void closestHitProgram(ImmutableRay_t _immutable, inout uvec2 scramble_state)
{
MutableRay_t mutable = rayStack[stackPtr]._mutable;
vec3 intersection = _immutable.origin + (_immutable.direction * mutable.intersectionT);
uint objectID = mutable.objectID;
irr_glsl_IsotropicViewSurfaceInteraction isotropic;
isotropic.V.dir = -_immutable.direction;
uint bsdfLightIDs;
if (objectID < 8u)
{
Sphere sphere = spheres[objectID];
Sphere param = sphere;
vec3 param_1 = intersection;
isotropic.N = Sphere_getNormal(param, param_1);
bsdfLightIDs = sphere.bsdfLightIDs;
}
else
{
Rectangle rect = rectangles[objectID - 8u];
Rectangle param_2 = rect;
isotropic.N = normalize(Rectangle_getNormalTimesArea(param_2));
bsdfLightIDs = rect.bsdfLightIDs;
}
isotropic.NdotV = dot(isotropic.V.dir, isotropic.N);
isotropic.NdotV_squared = isotropic.NdotV * isotropic.NdotV;
irr_glsl_IsotropicViewSurfaceInteraction param_3 = isotropic;
irr_glsl_AnisotropicViewSurfaceInteraction interaction = irr_glsl_calcAnisotropicInteraction(param_3);
uint lightID = bitfieldExtract(bsdfLightIDs, 16, 16);
vec3 throughput = rayStack[stackPtr]._payload.throughput;
if (lightID != 65535u)
{
Light param_5 = lights[lightID];
vec3 param_6 = _immutable.direction;
float param_7 = mutable.intersectionT;
float param_4;
vec3 _3492 = irr_glsl_light_deferred_eval_and_prob(param_4, param_5, param_6, param_7);
float lightPdf = param_4;
vec3 lightVal = _3492;
rayStack[stackPtr]._payload.accumulation += ((throughput * lightVal) / vec3(1.0 + ((lightPdf * lightPdf) * rayStack[stackPtr]._payload.otherTechniqueHeuristic)));
}
int sampleIx = bitfieldExtract(_immutable.typeDepthSampleIx, 0, 23);
int depth = bitfieldExtract(_immutable.typeDepthSampleIx, 23, 8);
uint bsdfID = bitfieldExtract(bsdfLightIDs, 0, 16);
if ((depth < 8) && (bsdfID != 65535u))
{
BSDFNode bsdf = bsdfs[bsdfID];
BSDFNode param_8 = bsdf;
uint opType = BSDFNode_getType(param_8);
BSDFNode param_9 = bsdf;
float bsdfGeneratorProbability = BSDFNode_getMISWeight(param_9);
uint param_10 = uint(depth);
uint param_11 = uint(sampleIx);
uvec2 param_12 = scramble_state;
vec3 _3552 = rand3d(param_10, param_11, param_12);
scramble_state = param_12;
vec3 epsilon = _3552;
float param_13 = bsdfGeneratorProbability;
float param_14 = epsilon.z;
float param_15;
bool _3562 = irr_glsl_partitionRandVariable(param_13, param_14, param_15);
epsilon.z = param_14;
float rcpChoiceProb = param_15;
bool doNEE = _3562;
BSDFNode param_16 = bsdf;
bool isBSDF = BSDFNode_isBSDF(param_16);
irr_glsl_LightSample _sample;
float lightPdf_1;
float maxT;
if (doNEE)
{
vec3 param_20 = intersection;
irr_glsl_AnisotropicViewSurfaceInteraction param_21 = interaction;
bool param_22 = isBSDF;
vec3 param_23 = epsilon;
int param_24 = depth;
vec3 param_17;
float param_18;
float param_19;
irr_glsl_LightSample _3590 = irr_glsl_light_generate_and_remainder_and_pdf(param_17, param_18, param_19, param_20, param_21, param_22, param_23, param_24);
vec3 lightRemainder = param_17;
lightPdf_1 = param_18;
maxT = param_19;
_sample = _3590;
throughput *= lightRemainder;
}
bool validPath = true;
vec3 throughputCIE_Y = transpose(mat3(vec3(0.41245639324188232421875, 0.21267290413379669189453125, 0.01933390088379383087158203125), vec3(0.3575761020183563232421875, 0.715152204036712646484375, 0.119191996753215789794921875), vec3(0.180437505245208740234375, 0.072175003588199615478515625, 0.950304090976715087890625)))[1] * throughput;
BSDFNode param_25 = bsdf;
float monochromeEta = dot(throughputCIE_Y, BSDFNode_getEta(param_25)[0]) / ((throughputCIE_Y.x + throughputCIE_Y.y) + throughputCIE_Y.z);
irr_glsl_AnisotropicMicrofacetCache _cache;
if (doNEE)
{
irr_glsl_AnisotropicViewSurfaceInteraction param_27 = interaction;
irr_glsl_LightSample param_28 = _sample;
float param_29 = monochromeEta;
irr_glsl_AnisotropicMicrofacetCache param_26;
bool _3631 = irr_glsl_calcAnisotropicMicrofacetCache(param_26, param_27, param_28, param_29);
_cache = param_26;
validPath = _3631;
bool _3639;
if (validPath)
{
_3639 = _sample.NdotL > 0.0;
}
else
{
_3639 = validPath;
}
validPath = _3639;
}
else
{
maxT = 3.4028234663852885981170418348452e+38;
irr_glsl_AnisotropicViewSurfaceInteraction param_30 = interaction;
vec3 param_31 = epsilon;
BSDFNode param_32 = bsdf;
float param_33 = monochromeEta;
irr_glsl_AnisotropicMicrofacetCache param_34;
irr_glsl_LightSample _3650 = irr_glsl_bsdf_cos_generate(param_30, param_31, param_32, param_33, param_34);
_cache = param_34;
_sample = _3650;
}
float bsdfPdf;
if (validPath)
{
irr_glsl_LightSample param_36 = _sample;
irr_glsl_AnisotropicViewSurfaceInteraction param_37 = interaction;
BSDFNode param_38 = bsdf;
float param_39 = monochromeEta;
irr_glsl_AnisotropicMicrofacetCache param_40 = _cache;
float param_35;
vec3 _3667 = irr_glsl_bsdf_cos_remainder_and_pdf(param_35, param_36, param_37, param_38, param_39, param_40);
bsdfPdf = param_35;
throughput *= _3667;
}
else
{
throughput = vec3(0.0);
}
vec3 param_41 = vec3(0.0039215688593685626983642578125);
vec3 param_42 = irr_glsl_eotf_sRGB(param_41);
float bsdfPdfThreshold = getLuma(param_42);
float lumaThroughputThreshold = bsdfPdfThreshold;
bool _3683 = bsdfPdf > bsdfPdfThreshold;
bool _3691;
if (_3683)
{
vec3 param_43 = throughput;
_3691 = getLuma(param_43) > lumaThroughputThreshold;
}
else
{
_3691 = _3683;
}
if (_3691)
{
rayStack[stackPtr]._payload.throughput = throughput * rcpChoiceProb;
float heuristicFactor = rcpChoiceProb - 1.0;
heuristicFactor /= (doNEE ? lightPdf_1 : bsdfPdf);
heuristicFactor *= heuristicFactor;
if (doNEE)
{
heuristicFactor = 1.0 / ((1.0 / bsdfPdf) + (heuristicFactor * bsdfPdf));
}
rayStack[stackPtr]._payload.otherTechniqueHeuristic = heuristicFactor;
int param_44 = depth;
rayStack[stackPtr]._immutable.origin = intersection + ((_sample.L * (doNEE ? maxT : 1.0)) * getStartTolerance(param_44));
rayStack[stackPtr]._immutable.maxT = maxT;
rayStack[stackPtr]._immutable.direction = _sample.L;
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx, depth + 1, 23, 8) | (doNEE ? (-2147483648) : 0);
rayStack[stackPtr]._immutable.normalAtOrigin = interaction.isotropic.N;
rayStack[stackPtr]._immutable.wasBSDFAtOrigin = isBSDF;
stackPtr++;
}
}
}
void main()
{
bsdfs = BSDFNode[](BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(0.800000011920928955078125)), 0u), floatBitsToUint(vec4(0.0)))), BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(0.800000011920928955078125, 0.4000000059604644775390625, 0.4000000059604644775390625)), 0u), floatBitsToUint(vec4(0.0)))), BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(0.4000000059604644775390625, 0.800000011920928955078125, 0.4000000059604644775390625)), 0u), floatBitsToUint(vec4(0.0)))), BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(1.019999980926513671875, 1.019999980926513671875, 1.2999999523162841796875)), 1u), floatBitsToUint(vec4(1.0, 1.0, 2.0, 0.0)))), BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(1.019999980926513671875, 1.2999999523162841796875, 1.019999980926513671875)), 1u), floatBitsToUint(vec4(1.0, 2.0, 1.0, 0.0)))), BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(1.019999980926513671875, 1.2999999523162841796875, 1.019999980926513671875)), 1u), floatBitsToUint(vec4(1.0, 2.0, 1.0, 0.1500000059604644775390625)))), BSDFNode(uvec4[](uvec4(floatBitsToUint(vec3(1.39999997615814208984375, 1.4500000476837158203125, 1.5)), 2u), floatBitsToUint(vec4(0.0, 0.0, 0.0, 0.0625)))));
stackPtr = 0;
vec3 param = vec3(0.0, -100.5, -1.0);
float param_1 = 100.0;
uint param_2 = 0u;
uint param_3 = 65535u;
vec3 param_4 = vec3(2.0, 0.0, -1.0);
float param_5 = 0.5;
uint param_6 = 1u;
uint param_7 = 65535u;
vec3 param_8 = vec3(0.0, 0.0, -1.0);
float param_9 = 0.5;
uint param_10 = 2u;
uint param_11 = 65535u;
vec3 param_12 = vec3(-2.0, 0.0, -1.0);
float param_13 = 0.5;
uint param_14 = 3u;
uint param_15 = 65535u;
vec3 param_16 = vec3(2.0, 0.0, 1.0);
float param_17 = 0.5;
uint param_18 = 4u;
uint param_19 = 65535u;
vec3 param_20 = vec3(0.0, 0.0, 1.0);
float param_21 = 0.5;
uint param_22 = 4u;
uint param_23 = 65535u;
vec3 param_24 = vec3(-2.0, 0.0, 1.0);
float param_25 = 0.5;
uint param_26 = 5u;
uint param_27 = 65535u;
vec3 param_28 = vec3(0.5, 1.0, 0.5);
float param_29 = 0.5;
uint param_30 = 6u;
uint param_31 = 65535u;
spheres = Sphere[](Sphere_Sphere(param, param_1, param_2, param_3), Sphere_Sphere(param_4, param_5, param_6, param_7), Sphere_Sphere(param_8, param_9, param_10, param_11), Sphere_Sphere(param_12, param_13, param_14, param_15), Sphere_Sphere(param_16, param_17, param_18, param_19), Sphere_Sphere(param_20, param_21, param_22, param_23), Sphere_Sphere(param_24, param_25, param_26, param_27), Sphere_Sphere(param_28, param_29, param_30, param_31));
vec3 param_32 = vec3(-1.7999999523162841796875, 0.3499999940395355224609375, 0.300000011920928955078125);
vec3 param_33 = vec3(0.60000002384185791015625, 0.0, -0.300000011920928955078125);
vec3 param_34 = vec3(0.300000011920928955078125, 0.449999988079071044921875, -0.60000002384185791015625);
uint param_35 = 65535u;
uint param_36 = 0u;
rectangles = Rectangle[](Rectangle_Rectangle(param_32, param_33, param_34, param_35, param_36));
lights = Light[](Light(vec3(30.0, 25.0, 15.0), 0u));
bool _2992;
if (_2986)
{
_2992 = _2991;
}
else
{
_2992 = _2985;
}
if (_2992)
{
pixelColor = vec4(1.0, 0.0, 0.0, 1.0);
return;
}
uvec2 scramble_start_state = textureLod(scramblebuf, TexCoord, 0.0).xy;
vec2 pixOffsetParam = vec2(1.0) / vec2(textureSize(scramblebuf, 0));
mat4 invMVP = inverse(SPIRV_Cross_workaround_load_row_major(cameraData.params.MVP));
vec4 NDC = vec4((TexCoord * vec2(2.0, -2.0)) + vec2(-1.0, 1.0), 0.0, 1.0);
vec4 tmp = invMVP * NDC;
vec3 camPos = tmp.xyz / vec3(tmp.w);
NDC.z = 1.0;
vec3 color = vec3(0.0);
float meanLumaSquared = 0.0;
for (int i = 0; i < 32; i++)
{
uvec2 scramble_state = scramble_start_state;
stackPtr = 0;
rayStack[stackPtr]._immutable.origin = camPos;
rayStack[stackPtr]._immutable.maxT = 3.4028234663852885981170418348452e+38;
vec4 tmp_1 = NDC;
uint param_37 = 0u;
uint param_38 = uint(i);
uvec2 param_39 = scramble_state;
vec3 _3079 = rand3d(param_37, param_38, param_39);
scramble_state = param_39;
vec2 remappedRand = _3079.xy;
remappedRand.x *= 0.956063091754913330078125;
remappedRand.x += 0.0439369343221187591552734375;
vec2 param_40 = remappedRand;
float param_41 = 1.5;
vec2 _3100 = tmp_1.xy + (pixOffsetParam * irr_glsl_BoxMullerTransform(param_40, param_41));
tmp_1 = vec4(_3100.x, _3100.y, tmp_1.z, tmp_1.w);
tmp_1 = invMVP * tmp_1;
rayStack[stackPtr]._immutable.direction = normalize((tmp_1.xyz / vec3(tmp_1.w)) - camPos);
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(i, 1, 23, 8);
rayStack[stackPtr]._immutable.normalAtOrigin = vec3(0.0);
rayStack[stackPtr]._immutable.wasBSDFAtOrigin = false;
rayStack[stackPtr]._payload.accumulation = vec3(0.0);
rayStack[stackPtr]._payload.otherTechniqueHeuristic = 0.0;
rayStack[stackPtr]._payload.throughput = vec3(1.0);
while (stackPtr != (-1))
{
ImmutableRay_t _immutable = rayStack[stackPtr]._immutable;
ImmutableRay_t param_42 = _immutable;
bool _3151 = traceRay(param_42);
bool anyHitType = _3151;
if (rayStack[stackPtr]._mutable.intersectionT >= _immutable.maxT)
{
missProgram();
}
else
{
if (!anyHitType)
{
ImmutableRay_t param_43 = _immutable;
uvec2 param_44 = scramble_state;
closestHitProgram(param_43, param_44);
scramble_state = param_44;
}
}
stackPtr--;
}
vec3 accumulation = rayStack[0]._payload.accumulation;
float rcpSampleSize = 1.0 / float(i + 1);
color += ((accumulation - color) * rcpSampleSize);
}
pixelColor = vec4(color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment