CJT
July 4, 2016, 2:46pm
1
Hello, I’m trying to implement Screen Space Ambient Occlusion in Panda.
When I try to pass a LVecBase3f array SSAOsamples
self.SSAOsamples = []
for i in range(64):
sample = LVecBase3f(random.random() * 2 - 1, random.random() * 2 - 1, random.random())
sample_length = math.sqrt(sample.x * sample.x + sample.y * sample.y + sample.z * sample.z)
sample /= sample_length
sample *= random.random()
self.SSAOsamples.append(sample)
to a uniform vec3 array samples[] in fragment shader
uniform vec3 samples[64];
by setShaderInput() , it comes the error.
Assertion failed: Shader input samples is not present.
I tried several way but none of it works.
for i in range(64):
tmpnode.setShaderInput("samples[%d]" % i, self.SSAOsamples[i])
tmpnode.setShaderInput("samples", self.SSAOsamples[0])
tmpnode.setShaderInput("samples[0]", self.SSAOsamples[0])
So how should I do to pass the array to shader correctly?
wezu
July 4, 2016, 3:11pm
2
I’m not sure if this is the only way to do it, but I know it is one way to do it that works:
(I’m not 100% sure PTA_LVecBase3f and UnalignedLVecBase3f exist , if not you might need to use PTA_LVecBase4f and UnalignedLVecBase4f, because they do exist for sure -at least in the dev branch of p3d)
self.SSAOsamples = PTA_LVecBase3f()
for i in range(64):
sample = UnalignedLVecBase3f(random.random() * 2 - 1, random.random() * 2 - 1, random.random())
sample_length = math.sqrt(sample.x * sample.x + sample.y * sample.y + sample.z * sample.z)
sample /= sample_length
sample *= random.random()
self.SSAOsamples.pushBack(sample)
render.setShaderInput('samples', self.SSAOsamples)
CJT
July 4, 2016, 3:45pm
3
Thank you wezu !
I made it works by using PTA_LVecBase4f and UnalignedLVecBase4f.
There is no UnalignedLVecBase3f in Panda
NameError: global name 'UnalignedLVecBase3f' is not defined
so I pass an dummy 0.0 instead
self.SSAOsamples.push_back(UnalignedLVecBase4f(sample.x, sample.y, sample.z, 0.0))
Thanks for the help
rdb
July 6, 2016, 9:16pm
4
PTA_LVecBase3f should work here (LVecBase3f is always unaligned, so there’s no special unaligned version), although it will probably get padded internally to vec4 by the driver anyway, so there’s probably no big savings here.