I’m trying to create a feedback system using imageLoad, similar to what is used in the new ParticlesGPU comp. Although I’m struggling to get it to work with more complex code. Attached is a working .toe, which uses said method to simply increase the values of a texture. Although I’m not sure I’m doing it correctly, because it only works, or produces any output, for that matter, with line 43 implemented. If I don’t increment the value by 1 then the shader produces all zero values?
void Read(int index){
ivec2 texPos = Index2XY(index);
vec4 noise = imageLoad(mTDComputeOutputs[0], texPos);
s.normState = float(noise);
s.oldState = float(noise * 5);
s.index = index;
}
void Code() {
//ADDING ONE, ONLY WAY IT WORKS?????????
s.oldState = s.oldState + 1;
//THIS BREAKS CODE?????????1
//s.oldState = s.oldState;
s.normState = float(s.oldState) / float(5);
}
void Write()
{
ivec2 texPos = Index2XY(s.index);
vec3 outOne = vec3(s.normState);
vec3 outTwo = vec3(s.oldState);
imageStore(mTDComputeOutputs[0], texPos, vec4(outOne,1));
imageStore(mTDComputeOutputs[1], texPos, vec4(outTwo, 1));
}
void main()
{
int index = int(gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x);
if(uReset == 1) {
ivec2 texPos = Index2XY(index);
imageStore(mTDComputeOutputs[0], texPos, vec4(0));
imageStore(mTDComputeOutputs[1], texPos, vec4(0));
}
else
{
//ivec2 texPos = Index2XY(index);
Read(index);
Code();
Write();
}
}
Thanks for any assistance.
myCourse-imageLoad-forum22.toe (493.7 KB)