Skip to content

Commit 95d39da

Browse files
Example 22 finally compiles
1 parent 7a35e7f commit 95d39da

File tree

17 files changed

+391
-193
lines changed

17 files changed

+391
-193
lines changed

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.cpp

Lines changed: 133 additions & 105 deletions
Large diffs are not rendered by default.

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _EXTRA_CRAP_INCLUDED_
2-
#define _EXTRA_CRAP_INCLUDED_
1+
#ifndef _RENDERER_INCLUDED_
2+
#define _RENDERER_INCLUDED_
33

44
#include "irrlicht.h"
55

@@ -110,17 +110,15 @@ class Renderer : public irr::core::IReferenceCounted, public irr::core::Interfac
110110

111111
// persistent (intialized in constructor
112112
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSetLayout> m_cullDSLayout;
113-
irr::core::smart_refctd_ptr<const irr::video::IGPUPipelineLayout> m_cullPipelineLayout;
113+
irr::core::smart_refctd_ptr<irr::video::IGPUPipelineLayout> m_cullPipelineLayout;
114114
irr::core::smart_refctd_ptr<irr::video::IGPUComputePipeline> m_cullPipeline;
115115

116116
irr::core::smart_refctd_ptr<irr::asset::ICPUSpecializedShader> m_visibilityBufferFillShaders[2];
117117
irr::core::smart_refctd_ptr<irr::asset::ICPUPipelineLayout> m_visibilityBufferFillPipelineLayoutCPU;
118-
irr::core::smart_refctd_ptr<const irr::video::IGPUPipelineLayout> m_visibilityBufferFillPipelineLayoutGPU;
119-
irr::core::smart_refctd_ptr<const irr::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
118+
irr::core::smart_refctd_ptr<irr::video::IGPUPipelineLayout> m_visibilityBufferFillPipelineLayoutGPU;
119+
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
120120

121121
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSetLayout> m_commonRaytracingDSLayout, m_raygenDSLayout, m_resolveDSLayout;
122-
irr::core::smart_refctd_ptr<const irr::video::IGPUPipelineLayout> m_raygenPipelineLayout, m_resolvePipelineLayout;
123-
irr::core::smart_refctd_ptr<irr::video::IGPUComputePipeline> m_raygenPipeline, m_resolvePipeline;
124122

125123

126124
// scene specific data
@@ -147,7 +145,9 @@ class Renderer : public irr::core::IReferenceCounted, public irr::core::Interfac
147145
uint32_t m_cullWorkGroups;
148146

149147
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSet> m_perCameraRasterDS;
150-
148+
149+
irr::core::smart_refctd_ptr<irr::video::IGPUPipelineLayout> m_raygenPipelineLayout, m_resolvePipelineLayout;
150+
irr::core::smart_refctd_ptr<irr::video::IGPUComputePipeline> m_raygenPipeline, m_resolvePipeline;
151151
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSet> m_globalBackendDataDS,m_commonRaytracingDS,m_raygenDS;
152152
uint32_t m_raygenWorkGroups[2];
153153

examples_tests/22.RaytracedAO/fillVisBuffer.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ layout(location = 0) flat in uint ObjectID;
77
layout(location = 1) in vec3 Normal;
88
layout(location = 2) in vec2 UV;
99

10-
layout(location = 0) out uvec2 objectTriangleFrontFacing;
10+
layout(location = 0) out uvec2 frontFacing_Object_Triangle;
1111
layout(location = 1) out vec2 encodedNormal;
1212
layout(location = 2) out vec2 uv;
1313

1414
void main()
1515
{
16-
objectTriangleFrontFacing = uvec2(ObjectID^(gl_FrontFacing ? 0x0u:0x80000000u),gl_PrimitiveID);
16+
frontFacing_Object_Triangle = uvec2(ObjectID^(gl_FrontFacing ? 0x0u:0x80000000u),gl_PrimitiveID);
1717
// these will disappear once we finally have MeshPackerV2 and settle on a way to obtain barycentrics
1818
encodedNormal = irr_glsl_NormalEncode_signedSpherical(normalize(Normal));
1919
uv = UV;

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 164 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,137 @@
11
#version 430 core
22
#include "raytraceCommon.glsl"
33

4-
4+
// for per pixel inputs
55
#include <irr/builtin/glsl/utils/normal_decode.glsl>
6+
#include <irr/builtin/glsl/random/xoroshiro.glsl>
7+
68
// rng
79
layout(set = 2, binding = 0) uniform usamplerBuffer sampleSequence;
810
layout(set = 2, binding = 1) uniform usampler2D scramblebuf;
911
// vis buffer
1012
layout(set = 2, binding = 2) uniform sampler2D depthbuf;
11-
layout(set = 2, binding = 3) uniform usampler2D objectTriangleFrontFacing;
13+
layout(set = 2, binding = 3) uniform usampler2D frontFacing_Object_Triangle;
1214
layout(set = 2, binding = 4) uniform sampler2D encodedNormal;
13-
layout(set = 2, binding = 5) uniform sampler2D uv;
15+
layout(set = 2, binding = 5) uniform sampler2D uvCoords;
16+
17+
18+
// for materials
19+
// dummies needed because of the functions for fragment shader surface intersections
20+
vec3 dFdx(in vec3 r) {return vec3(0.0/0.0);}
21+
vec3 dFdy(in vec3 r) {return vec3(0.0/0.0);}
22+
// no idea yet
23+
#define sizeof_bsdf_data 1u
24+
#include <irr/builtin/material_compiler/glsl/common_declarations.glsl>
25+
vec3 normalizedV;
26+
vec3 irr_glsl_MC_getNormalizedWorldSpaceV()
27+
{
28+
return normalizedV;
29+
}
30+
vec3 normalizedN;
31+
vec3 irr_glsl_MC_getNormalizedWorldSpaceN()
32+
{
33+
return normalizedN;
34+
}
35+
vec3 worldPosition;
36+
vec3 irr_glsl_MC_WorldSpacePosition()
37+
{
38+
return worldPosition;
39+
}
40+
/*
41+
#define _IRR_USER_PROVIDED_MATERIAL_COMPILER_GLSL_BACKEND_FUNCTIONS_
42+
instr_stream_t getEvalStream(in MC_precomputed_t precomp)
43+
{
44+
instr_stream_t stream;
45+
if (precomp.frontface)
46+
{
47+
stream.offset = InstData.data[InstanceIndex].front_instr_offset;
48+
stream.count = InstData.data[InstanceIndex].front_rem_pdf_count;
49+
}
50+
else
51+
{
52+
stream.offset = InstData.data[InstanceIndex].back_instr_offset;
53+
stream.count = InstData.data[InstanceIndex].back_rem_pdf_count;
54+
}
55+
return stream;
56+
}
57+
instr_t nbl_glsl_MC_fetchInstr(in uint ix)
58+
{
59+
return instr_buf.data[ix];
60+
}
61+
prefetch_instr_t nbl_glsl_MC_fetchPrefetchInstr(in uint ix)
62+
{
63+
return prefetch_instr_buf.data[ix];
64+
}
65+
bsdf_data_t nbl_glsl_MC_fetchBSDFData(in uint ix)
66+
{
67+
return bsdf_buf.data[ix];
68+
}
69+
///
70+
//rem'n'pdf and eval use the same instruction stream
71+
instr_stream_t getRemAndPdfStream(in MC_precomputed_t precomp)
72+
{
73+
return getEvalStream(precomp);
74+
}
75+
instr_stream_t getGenChoiceStream(in MC_precomputed_t precomp)
76+
{
77+
instr_stream_t stream;
78+
if (precomp.frontface)
79+
{
80+
stream.offset = InstData.data[InstanceIndex].front_instr_offset + InstData.data[InstanceIndex].front_rem_pdf_count;
81+
stream.count = InstData.data[InstanceIndex].front_genchoice_count;
82+
}
83+
else
84+
{
85+
stream.offset = InstData.data[InstanceIndex].back_instr_offset + InstData.data[InstanceIndex].back_rem_pdf_count;
86+
stream.count = InstData.data[InstanceIndex].back_genchoice_count;
87+
}
88+
return stream;
89+
}
90+
instr_stream_t getTexPrefetchStream(in MC_precomputed_t precomp)
91+
{
92+
instr_stream_t stream;
93+
if (precomp.frontface)
94+
{
95+
stream.offset = InstData.data[InstanceIndex].front_prefetch_offset;
96+
stream.count = InstData.data[InstanceIndex].front_prefetch_count;
97+
}
98+
else
99+
{
100+
stream.offset = InstData.data[InstanceIndex].back_prefetch_offset;
101+
stream.count = InstData.data[InstanceIndex].back_prefetch_count;
102+
}
103+
return stream;
104+
}
105+
instr_stream_t getNormalPrecompStream(in MC_precomputed_t precomp)
106+
{
107+
instr_stream_t stream;
108+
if (precomp.frontface)
109+
{
110+
stream.offset = InstData.data[InstanceIndex].front_instr_offset + InstData.data[InstanceIndex].front_rem_pdf_count + InstData.data[InstanceIndex].front_genchoice_count;
111+
stream.count = InstData.data[InstanceIndex].front_nprecomp_count;
112+
}
113+
else
114+
{
115+
stream.offset = InstData.data[InstanceIndex].back_instr_offset + InstData.data[InstanceIndex].back_rem_pdf_count + InstData.data[InstanceIndex].back_genchoice_count;
116+
stream.count = InstData.data[InstanceIndex].back_nprecomp_count;
117+
}
118+
return stream;
119+
}
120+
#include <irr/builtin/material_compiler/glsl/common.glsl>
121+
*/
14122

123+
//
124+
///
15125

16126

127+
// functions
128+
vec3 rand3d(in uint _sample, inout irr_glsl_xoroshiro64star_state_t scramble_state)
129+
{
130+
uvec3 seqVal = texelFetch(sampleSequence,int(_sample)).xyz;
131+
seqVal ^= uvec3(irr_glsl_xoroshiro64star(scramble_state),irr_glsl_xoroshiro64star(scramble_state),irr_glsl_xoroshiro64star(scramble_state));
132+
return vec3(seqVal)*uintBitsToFloat(0x2f800004u);
133+
}
134+
17135
float linearizeZBufferVal(in float nonLinearZBufferVal)
18136
{
19137
// 1-(Ax+B)/(Cx) = y
@@ -151,42 +269,64 @@ void main()
151269
uvec2 outputLocation = gl_GlobalInvocationID.xy;
152270
if (all(lessThan(outputLocation,staticViewData.imageDimensions)))
153271
{
154-
ivec2 uv = ivec2(outputLocation);
155-
float revdepth = texelFetch(depthbuf,uv,0).r;
272+
ivec2 pixelCoord = ivec2(outputLocation);
273+
float revdepth = texelFetch(depthbuf,pixelCoord,0).r;
156274

157275
const uint outputID = outputLocation.y*staticViewData.samplesPerRowPerDispatch+outputLocation.x*staticViewData.samplesPerPixelPerDispatch;
158276

159277
SamplingData_t samplingData;
160-
// unproject
161-
vec3 viewDir;
162-
vec3 position;
163-
{
164-
const mat4x3 frustumCorners = pc.cummon.frustumCorners;
165-
const vec2 NDC = vec2(outputLocation)*staticViewData.rcpPixelSize+staticViewData.rcpHalfPixelSize;
166-
167-
viewDir = mix(frustumCorners[0]*NDC.x+frustumCorners[1],frustumCorners[2]*NDC.x+frustumCorners[3],NDC.yyy);
168-
position = viewDir*linearizeZBufferVal(revdepth)+pc.cummon.normalMatrixAndCameraPos[3];
169-
}
170278

171279
bool alive = false;
172-
uint scramble,objectID,triangleID;
173-
bool backfacing;
174-
vec3 normal = vec3(0.0);
175-
vec2 uvCoord;
280+
MC_precomputed_t precomputed;
281+
irr_glsl_xoroshiro64star_state_t start_scramble;
282+
vec2 uv;
176283
if (revdepth>0.0)
177-
{
178-
scramble = texelFetch(scramblebuf,uv,0).r;
284+
{
285+
// vis buffer read
286+
const uvec2 visBuffer = texelFetch(frontFacing_Object_Triangle,pixelCoord,0).rg;
287+
// init scramble
288+
start_scramble = texelFetch(scramblebuf,pixelCoord,0).rg;
289+
// tmp gbuffer reads
290+
const vec2 normalBuffer = texelFetch(encodedNormal,pixelCoord,0).rg;
291+
uv = texelFetch(uvCoords,pixelCoord,0).xy;
292+
293+
// unproject
294+
{
295+
const mat4x3 frustumCorners = pc.cummon.frustumCorners;
296+
const vec2 NDC = vec2(outputLocation)*staticViewData.rcpPixelSize+staticViewData.rcpHalfPixelSize;
297+
298+
const vec3 viewDir = mix(frustumCorners[0]*NDC.x+frustumCorners[1],frustumCorners[2]*NDC.x+frustumCorners[3],NDC.yyy);
299+
worldPosition = viewDir*linearizeZBufferVal(revdepth)+pc.cummon.normalMatrixAndCameraPos[3];
300+
normalizedV = normalize(viewDir);
301+
}
179302

303+
// decode vis buffer
304+
bool frontfacing;
305+
{
306+
frontfacing = visBuffer[0]<0x80000000u;
307+
const uint objectID = visBuffer[0]&0x7fffffffu;
308+
const uint triangleID = visBuffer[1];
309+
}
310+
311+
// normally we'd use MeshPackerV2's vertex attribute data for this, but now we read from temporary GBuffer
312+
{
313+
normalizedN = irr_glsl_NormalDecode_signedSpherical(normalBuffer);
314+
}
315+
316+
// TODO: once we merge the material compiler with the raygen
317+
//precomputed = precomputeData(frontfacing);
318+
319+
//
180320
const vec3 emissive = vec3(0.0,1.0,0.0);
181321
vec3 acc;
182322
if (pc.cummon.rcpFramesDispatched<1.0)
183-
acc = fetchFramebuffer(uv)+emissive/float(pc.cummon.framesDispatched-1u);
323+
acc = fetchAccumulation(pixelCoord)+emissive/float(pc.cummon.framesDispatched-1u);
184324
else
185325
acc = emissive;
186326

187327
//
188328

189-
storeFramebuffer(acc,uv);
329+
storeAccumulation(acc,pixelCoord);
190330
alive = true;
191331
}
192332
#ifdef USE_OPTIX_DENOISER
@@ -212,7 +352,7 @@ void main()
212352
{
213353
throughput /= float(staticViewData.samplesPerPixelPerDispatch);
214354

215-
rays[realOutputID].origin = position;/*+newray.direction*err?; TODO */
355+
rays[realOutputID].origin = irr_glsl_MC_WorldSpacePosition();/*+newray.direction*err?; TODO */
216356
rays[realOutputID].maxT = 0.0;
217357
rays[realOutputID].direction = direction;
218358
rays[realOutputID].mask = -1;

include/irr/builtin/glsl/bxdf/common.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ irr_glsl_IsotropicViewSurfaceInteraction irr_glsl_calcFragmentShaderSurfaceInter
135135
{
136136
irr_glsl_IsotropicViewSurfaceInteraction interaction;
137137
interaction.V.dir = _View;
138-
interaction.V.dPosdScreen[0] = dFdx(_SurfacePos);
138+
interaction.V.dPosdScreen[0] = dFdx(_SurfacePos);// TODO: require the user to feed us the derivatives
139139
interaction.V.dPosdScreen[1] = dFdy(_SurfacePos);
140140
interaction.N = _Normal;
141141
float invlenV2 = inversesqrt(dot(interaction.V.dir, interaction.V.dir));

include/irr/builtin/glsl/ext/RadeonRays/intersection.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __IRR_EXT_RADEON_RAYS_INTERSECTION_INCLUDED__
2-
#define __IRR_EXT_RADEON_RAYS_INTERSECTION_INCLUDED__
1+
#ifndef _IRR_EXT_RADEON_RAYS_INTERSECTION_INCLUDED_
2+
#define _IRR_EXT_RADEON_RAYS_INTERSECTION_INCLUDED_
33

44
// for the love of god, lets optimize this into 16 bytes
55
struct irr_glsl_ext_RadeonRays_Intersection

include/irr/builtin/glsl/ext/RadeonRays/ray.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __IRR_EXT_RADEON_RAYS_RAY_INCLUDED__
2-
#define __IRR_EXT_RADEON_RAYS_RAY_INCLUDED__
1+
#ifndef _IRR_EXT_RADEON_RAYS_RAY_INCLUDED_
2+
#define _IRR_EXT_RADEON_RAYS_RAY_INCLUDED_
33

44
struct irr_glsl_ext_RadeonRays_ray
55
{

include/irr/builtin/glsl/format/constants.glsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,14 @@
66
#define irr_glsl_RGB19E7_MANTISSA_MASK 0x7ffff
77
#define irr_glsl_RGB19E7_EXPONENT_BITS 7
88
#define irr_glsl_RGB19E7_EXP_BIAS 63
9+
#define irr_glsl_MAX_RGB19E7_EXP (irr_glsl_RGB19E7_EXP_BIAS+1)
10+
11+
#define MAX_RGB19E7_MANTISSA_VALUES (0x1<<irr_glsl_RGB19E7_MANTISSA_BITS)
12+
#define MAX_RGB19E7_MANTISSA (MAX_RGB19E7_MANTISSA_VALUES-1)
13+
#define irr_glsl_MAX_RGB19E7 float(MAX_RGB19E7_MANTISSA)/float(MAX_RGB19E7_MANTISSA_VALUES)*exp2(float(irr_glsl_MAX_RGB19E7_EXP-irr_glsl_RGB19E7_MANTISSA_BITS))
14+
15+
#define irr_glsl_RGB19E7_COMPONENT_INDICES ivec4(0,0,1,1)
16+
#define irr_glsl_RGB19E7_COMPONENT_BITOFFSETS ivec4(0,irr_glsl_RGB19E7_MANTISSA_BITS,(2*irr_glsl_RGB19E7_MANTISSA_BITS)&31,(3*irr_glsl_RGB19E7_MANTISSA_BITS)&31)
17+
#define irr_glsl_RGB19E7_G_COMPONENT_SPLIT (32-irr_glsl_RGB19E7_MANTISSA_BITS)
918

1019
#endif

include/irr/builtin/glsl/format/decode.glsl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55

66
vec3 irr_glsl_decodeRGB19E7(in uvec2 x)
77
{
8-
int exp = int(bitfieldExtract(x.y, 3*irr_glsl_RGB19E7_MANTISSA_BITS-32, irr_glsl_RGB19E7_EXPONENT_BITS) - irr_glsl_RGB19E7_EXP_BIAS - irr_glsl_RGB19E7_MANTISSA_BITS);
9-
float scale = exp2(float(exp));//uintBitsToFloat((uint(exp)+127u)<<23u)
8+
int exp = int(bitfieldExtract(x[irr_glsl_RGB19E7_COMPONENT_INDICES[3]], irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[3], irr_glsl_RGB19E7_EXPONENT_BITS) - irr_glsl_RGB19E7_EXP_BIAS - irr_glsl_RGB19E7_MANTISSA_BITS);
9+
float scale = exp2(float(exp));
1010

1111
vec3 v;
12-
v.x = int(bitfieldExtract(x.x, 0, irr_glsl_RGB19E7_MANTISSA_BITS))*scale;
13-
v.y = int(
14-
bitfieldExtract(x.x, irr_glsl_RGB19E7_MANTISSA_BITS, 32-irr_glsl_RGB19E7_MANTISSA_BITS) |
15-
(bitfieldExtract(x.y, 0, irr_glsl_RGB19E7_MANTISSA_BITS-(32-irr_glsl_RGB19E7_MANTISSA_BITS))<<(32-irr_glsl_RGB19E7_MANTISSA_BITS))
16-
) * scale;
17-
v.z = int(bitfieldExtract(x.y, irr_glsl_RGB19E7_MANTISSA_BITS-(32-irr_glsl_RGB19E7_MANTISSA_BITS), irr_glsl_RGB19E7_MANTISSA_BITS)) * scale;
12+
v.x = float(bitfieldExtract(x[irr_glsl_RGB19E7_COMPONENT_INDICES[0]], irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[0], irr_glsl_RGB19E7_MANTISSA_BITS));
13+
v.y = float(bitfieldInsert(
14+
bitfieldExtract(x[irr_glsl_RGB19E7_COMPONENT_INDICES[1]], irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[1], irr_glsl_RGB19E7_G_COMPONENT_SPLIT),
15+
bitfieldExtract(x[irr_glsl_RGB19E7_COMPONENT_INDICES[2]], 0, irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[2]),
16+
irr_glsl_RGB19E7_G_COMPONENT_SPLIT,
17+
irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[2]
18+
));
19+
v.z = float(bitfieldExtract(x[irr_glsl_RGB19E7_COMPONENT_INDICES[2]], irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[2], irr_glsl_RGB19E7_MANTISSA_BITS));
1820

19-
return v;
21+
return v*scale;
2022
}
2123

2224
vec4 irr_glsl_decodeRGB10A2(in uint x)

include/irr/builtin/glsl/format/encode.glsl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44
#include <irr/builtin/glsl/format/constants.glsl>
55

6-
uvec2 irr_glsl_encodeRGB19E7(in vec4 col)
6+
uvec2 irr_glsl_encodeRGB19E7(in vec3 col)
77
{
8-
int exp = int(bitfieldExtract(x.y, 3*irr_glsl_RGB19E7_MANTISSA_BITS-32, irr_glsl_RGB19E7_EXPONENT_BITS) - irr_glsl_RGB19E7_EXP_BIAS - irr_glsl_RGB19E7_MANTISSA_BITS);
9-
float scale = exp2(float(exp));//uintBitsToFloat((uint(exp)+127u)<<23u)
10-
11-
vec3 v;
12-
v.x = int(bitfieldExtract(x.x, 0, irr_glsl_RGB19E7_MANTISSA_BITS))*scale;
13-
v.y = int(
14-
bitfieldExtract(x.x, irr_glsl_RGB19E7_MANTISSA_BITS, 32-irr_glsl_RGB19E7_MANTISSA_BITS) |
15-
(bitfieldExtract(x.y, 0, irr_glsl_RGB19E7_MANTISSA_BITS-(32-irr_glsl_RGB19E7_MANTISSA_BITS))<<(32-irr_glsl_RGB19E7_MANTISSA_BITS))
16-
) * scale;
17-
v.z = int(bitfieldExtract(x.y, irr_glsl_RGB19E7_MANTISSA_BITS-(32-irr_glsl_RGB19E7_MANTISSA_BITS), irr_glsl_RGB19E7_MANTISSA_BITS)) * scale;
18-
19-
return v;
8+
const vec3 clamped = clamp(col,vec3(0.0),vec3(irr_glsl_MAX_RGB19E7));
9+
const float maxrgb = max(max(clamped.r,clamped.g),clamped.b);
10+
11+
const int f32_exp = bitfieldExtract(floatBitsToInt(maxrgb),23,8)-127;
12+
const int shared_exp = clamp(f32_exp,-irr_glsl_RGB19E7_EXP_BIAS,irr_glsl_MAX_RGB19E7_EXP);
13+
14+
const uvec3 mantissas = uvec3(clamped*exp2(irr_glsl_RGB19E7_MANTISSA_BITS-shared_exp));
15+
16+
uvec2 encoded;
17+
encoded.x = bitfieldInsert(mantissas.x,mantissas.y,irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[1],irr_glsl_RGB19E7_G_COMPONENT_SPLIT);
18+
encoded.y = bitfieldInsert(mantissas.y>>irr_glsl_RGB19E7_G_COMPONENT_SPLIT,mantissas.z,irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[2],irr_glsl_RGB19E7_MANTISSA_BITS)|uint((shared_exp+irr_glsl_RGB19E7_EXP_BIAS)<<irr_glsl_RGB19E7_COMPONENT_BITOFFSETS[3]);
19+
20+
return encoded;
2021
}
2122

2223
uint irr_glsl_encodeRGB10A2(in vec4 col)

0 commit comments

Comments
 (0)