Jump to content
  • Advertisement
Sign in to follow this  
slicer4ever

OpenGL Encoding data into texture2D...

This topic is 2329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello everone, i'm having a bit of an issue with encoding data into a texture.

essentially, i was using a texture buffer to store raw data for skeletal deformations, but this means supporting roughly openGL 3.0 to be succesfully supported, and i'd rather support openGL 2.0 if possible, so i though i'd encode the data into a texture.

this is how i encode it in my program for the texture:



unsigned int TotalSize = FrameCount*BoneCount*3;
unsigned int TexelWidth = FrameCount>4?BoneCount*3*4:TotalSize;
unsigned int TexelHeight = FrameCount/4+1;
m_SkeletonMap = (new NVTexture)->AddRef();
float *Data = (float*)m_SkeletonMap->NewTexels(TexelWidth, TexelHeight, NVTEXPACK_RGBAF);
unsigned int d=0;
float Buffer[3];
float Inv64 = 1.0f/64.0f;
for(unsigned int i=0;i<S->GetAnimation()->Length();i++){
S->GetAnimation()->SetActiveAnimation(i);
while(1){
S->UpdatedBones();
S->SwapBuffers();
for(unsigned int x=0;x<BoneCount;x++){
float *D = Data+d;
NVJoint *J = S->GetChildAtIdx(x);
memcpy(D, J->GetDrawRelRot(), sizeof(float)*4);
Buffer[0] = (J->GetDrawRelPos()[0]+32.0f)*Inv64;
Buffer[1] = (J->GetDrawRelPos()[1]+32.0f)*Inv64;
Buffer[2] = (J->GetDrawRelPos()[2]+32.0f)*Inv64;
memcpy(D+4, Buffer, sizeof(float)*3);
Buffer[0] = (J->GetDrawBindPos()[0]+32.0f)*Inv64;
Buffer[1] = (J->GetDrawBindPos()[1]+32.0f)*Inv64;
Buffer[2] = (J->GetDrawBindPos()[2]+32.0f)*Inv64;
memcpy(D+8, Buffer, sizeof(float)*3);

d+=12;
}
S->GetAnimation()->NextFrame();
if(S->GetAnimation()->GetCurrFrame()==S->GetAnimation()->GetActiveAnimation()->GetEndFrame() || S->GetAnimation()->GetCurrFrame()==S->GetAnimation()->GetActiveAnimation()->GetStartFrame()) break;
}
}

since none of the bone positions are planned to be greater than {-32, 32} (in truth it's between -16 and 16, but i felt doubling this would be safe.)
(note: rotations are in quaternion's).
here's how i decode in the shader:


//ip = initial position, x = bone index, w = weight
vec3 Deform(in vec3 ip, in int x, in float w){
ivec2 offset = ivec2((SkelFrame%4)*SkelBoneCount*3, SkelFrame/4);
vec4 RelRot = texelFetch (SkelBuffer,offset+ivec2(x*3, 0), 0);
vec3 RelPos = vec3(texelFetch(SkelBuffer,offset+ivec2(x*3+1, 0), 0))*64.0f-32.0f;
vec3 BindPos= vec3(texelFetch(SkelBuffer,offset+ivec2(x*3+2, 0), 0))*64.0f-32.0f;
return vec3(BindPos+RelPos+QRot(RelRot, ip-BindPos)-ip)*w;
}


this produces a decent effect:
f29gec.png

it's hard to convey the problem from the image, but essentially, as the animation plays, it looks...shifty, i suppose is the best word.

here's a version using texture buffer's, which looks perfectly fine when animated:

6dzpm8.png

i'm assuming this might be due to rounding issues, but i'd like some opinions on possible solutions? Edited by slicer4ever

Share this post


Link to post
Share on other sites
Advertisement
Hard to say. is your texture using GL_NEAREST? Also if you are encoding this every frame into a texture, why not just send them as a uniform to the shader. I still think it is only one opengl call where you send an array of matrices all at once.

Share this post


Link to post
Share on other sites

Hard to say. is your texture using GL_NEAREST? Also if you are encoding this every frame into a texture, why not just send them as a uniform to the shader. I still think it is only one opengl call where you send an array of matrices all at once.


it's not being sent each frame, the above encodes all possible frames into the texture and uploads that texture at initialization, then i simply send the frame to the shader/bind the texture, this gives me the ability to encode ton's of bones/animation's without having to do any huge uploads to the gpu. The only disadvantage is that i can't manually modify the bones, but that's fine for my purposes, as well, i'm not working with matrix's, i'm working with quaternions, and i'd rather not go through converting the bones to matrix's before upload.
.
also, from my understanding texelFetch is suppose to ignore filtering and give you the exact texel you requested.

I'm fairly certain this problem is due to rounding issues, since when i scale it between {-16 - 16}, the visible issue's in the animation get less severe. i'm hoping someone can give me pointers about how to overcome this, as for now i've reverted back to using texture buffers. Edited by slicer4ever

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!