Hello,
I’ve already asked for this in the IRC, but today is sunday (in my part of the world), so I think most people don’t read there today.
I was currently trying hardware instancing to improve the performance of my project. I have tried this simple test code found in the forum on my Intel HD4000 with (Arch) Linux, Kernel 3.12.
Python source:
from panda3d.core import loadPrcFileData
loadPrcFileData('', 'basic-shaders-only 0')
loadPrcFileData('', 'sync-video 0')
loadPrcFileData('', 'show-frame-rate-meter 1')
from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
from direct.interval.IntervalGlobal import Sequence
import direct.directbase.DirectStart
from panda3d.core import Point3, Vec4, PTA_LVecBase4f, Shader, UnalignedLVecBase4f
class World(DirectObject):
def __init__(self):
self.accept("escape", __import__("sys").exit, [0])
self.model = Actor('panda-model', {'walk': 'panda-walk4'})
self.model.setScale(0.005)
#self.model.flattenLight()
self.model.setPos(-2.7,300,-5)
self.model.loop('walk')
self.model.reparentTo(render)
interval = self.model.posInterval(20, Point3(-2.7, 200, -5), startPos=Point3(-2.7, 300, -5))
sequence = Sequence(interval)
sequence.loop()
k = 256
offsets = PTA_LVecBase4f.emptyArray(k);
count = 0
for i in range(10):
for j in range(k/10):
offsets[count] = UnalignedLVecBase4f(Vec4(i * 3, j * -8, 0, 0))
count += 1
self.model.setShaderInput('offsets', offsets)
self.model.setShader(Shader.load('instance.cg'))
self.model.setInstanceCount(k)
w = World()
run()
Shader:
//Cg
//Cg profile gp4vp gp4fp
void vshader(float4 vtx_position: POSITION,
float2 vtx_texcoord0: TEXCOORD0,
uniform float4x4 mat_modelproj,
int l_id: INSTANCEID,
uniform float4 offsets[256],
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0)
{
l_position = mul(mat_modelproj, vtx_position + offsets[l_id]);
l_texcoord0 = vtx_texcoord0;
}
void fshader(float2 l_texcoord0: TEXCOORD0,
uniform sampler2D tex_0: TEXUNIT0,
out float4 o_color: COLOR)
{
o_color = tex2D(tex_0, l_texcoord0);
}
When starting the program, only one panda is visible (I don’t know if multiple were drawn but I see just one when looking around).
The console output:
DirectStart: Starting the game.
Known pipe types:
glxGraphicsPipe
(all display modules loaded.)
:gobj(error): instance.cg: uniform in unknown offsets: unsupported array subclass.
:gobj(error): Shader encountered an error.
:gobj(error): instance.cg: (7) : error C5108: unknown semantics "INSTANCEID" specified for "l_id"
I’m not sure if this is a hardware or driver related problem, but according to glxinfo, instancing should be supported:
% glxinfo| grep instance
GL_ARB_ES3_compatibility, GL_ARB_base_instance,
GL_ARB_draw_instanced, GL_ARB_explicit_attrib_location,
GL_ARB_half_float_vertex, GL_ARB_instanced_arrays,
GL_EXT_draw_instanced, GL_EXT_framebuffer_blit,
GL_ARB_draw_elements_base_vertex, GL_ARB_draw_instanced,
GL_ARB_instanced_arrays, GL_ARB_internalformat_query,
GL_EXT_draw_instanced, GL_EXT_draw_range_elements, GL_EXT_fog_coord,
I think it might have something to do with the NVIDIA Cg compiler or panda itself (maybe does not make an instanced draw call?)
If you need some more system information (Kernel/Mesa version, glxinfo) or something else, just ask
best regards,
Socke