there still remains another error, i just cant get it to work :doh:
// 2. exchange start index with fragment index
uint next_index = imageAtomicExchange(StartIndices, ivec2(gl_FragCoord.xy), 20); // works!
//uint next_index = imageAtomicExchange(StartIndices, ivec2(gl_FragCoord.xy), fragment_index); // ERROR
somehow this atomic exchange will not work with a variable, but with constants it compiles (???)
0(81) : error C1115: unable to find compatible overloaded function “imageAtomicExchange(struct iimage2D1x32_bindless, ivec2, uint)”
#version 450 core
//layout (early_fragment_tests) in;
struct Material {
vec3 Kd; // diffuse
vec3 Ks; // specular
float Ns; // shininess
};
struct DirectionalLight {
vec3 Intensity;
vec3 Direction;
};
in VS_FS_INTERFACE {
vec3 position;
vec3 normal;
} vertex;
// example material and other lighting properties
uniform Material material = Material ( vec3(0, 0, 0), vec3(0, 0, 0), 0 );
uniform vec3 AmbientIntensity = vec3(0, 0, 0);
uniform vec3 CameraPosition = vec3(0, 0, 0);
struct Fragment {
int Next;
uint Color;
float Depth;
int unused;
};
layout (std430, binding = 1) buffer FragmentBufferBlock { Fragment Fragments[]; };
layout (binding = 1, r32i) uniform iimage2D StartIndices;
layout (binding = 1) uniform atomic_uint FragmentCounter;
void main ()
{
// material
vec3 Kd = material.Kd;
vec3 Ks = material.Ks;
float Ns = material.Ns;
// light parts
vec3 Ia = AmbientIntensity;
vec3 Id = vec3(0, 0, 0);
vec3 Is = vec3(0, 0, 0);
// process light sources here ...
DirectionalLight light = DirectionalLight( vec3(1, 1, 1), vec3(2, -1, -5) );
vec3 N = normalize(vertex.normal);
vec3 L = normalize(-light.Direction);
vec3 R = normalize(reflect(light.Direction, N));
vec3 V = normalize(CameraPosition - vertex.position);
// diffuse Intensity
Id = Id + light.Intensity * max(0, dot(N, L));
// specular intensity
Is = Is + light.Intensity * max(0, pow(max(0, dot(R, V)), max(1, Ns)));
// final fragment color
vec3 color = Kd * (Ia + Id) + Ks * Is;
// OIT
/************************************************************************/
// 1. get fragment index
uint fragment_index = atomicCounterIncrement(FragmentCounter);
// 2. exchange start index with fragment index
uint next_index = imageAtomicExchange(StartIndices, ivec2(gl_FragCoord.xy), 20); // works!
//uint next_index = imageAtomicExchange(StartIndices, ivec2(gl_FragCoord.xy), fragment_index); // ERROR
// 3. set next index to exchanged value
Fragments[fragment_index].Next = int(next_index);
Fragments[fragment_index].Color = packUnorm4x8(vec4(color, 1));
Fragments[fragment_index].Depth = gl_FragDepth;
//Fragments[fragment_index].unused = ...;
/************************************************************************/
}