• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.


  • Content count

  • Joined

  • Last visited

Community Reputation

132 Neutral

About OmniRa

  • Rank
  1. Thankyou   I thought the optimizer would just remove variables that didn't get referenced in the code, I didn't realise it was that good at removing unused things! I changed some variables to make sure they have influence on the result and it works now.   Ty
  2. Hi, i have this fragment shader and glGetUniformLocation is returning -1 for a few entries. one of which is "camera_position". Im not sure why this is happening, it's working for other variables like "num_directional_lights" & "num_point_lights". Is there any reason it would fail for that particular one. The shader doesn't appear to have an compilation errors.   This is the fragment shader: // // version // #version 330 // // constants // const int NAX_DIRECTIONAL_LIGHTS = 2; const int MAX_POINT_LIGHTS = 2; const int MAX_SPOT_LIGHTS = 2; // // structs // struct DIRECTIONAL_LIGHT { vec3 colour; float ambientIntensity; float diffuseIntensity; vec3 direction; }; struct POINT_LIGHT { vec3 colour; float ambientIntensity; float diffuseIntensity; float constantAttenuation; float linearAttenuation; float exponetialAttenuation; }; struct SPOT_LIGHT { vec3 colour; float ambientIntensity; float diffuseIntensity; float constantAttenuation; float linearAttenuation; float exponetialAttenuation; vec3 direction; float cutoff; }; // // uniforms // uniform vec3 camera_position; uniform sampler2D texture0; uniform int num_directional_lights; uniform int num_point_lights; uniform int num_spot_lights; uniform DIRECTIONAL_LIGHT directional_light [NAX_DIRECTIONAL_LIGHTS]; uniform POINT_LIGHT point_light [MAX_POINT_LIGHTS]; uniform SPOT_LIGHT spot_light [MAX_SPOT_LIGHTS]; // // in attributes // in vec4 frag_colour; in vec2 frag_texCoord0; in vec3 frag_normal; in vec3 frag_worldPos; // // out attributes // out vec4 out_colour; // // functions // vec4 CalculateDirectionalLight(void) { vec4 totalLight = vec4(0, 0, 0, 0); // temp // ==== float specularIntensity = 0.0; float specularPower = 0.0; // ==== for (int i = 0; i < num_directional_lights; ++i) { vec4 ambientColour = vec4(directional_light[i].colour, 1.0) * directional_light[i].ambientIntensity; float diffuseFactor = dot(frag_normal, -directional_light[i].direction); vec4 diffuseColour = vec4(0, 0, 0, 0); vec4 specularColour = vec4(0, 0, 0, 0); if (diffuseFactor > 0.0) { vec3 toEye = normalize(camera_position - frag_worldPos); vec3 lightReflect = normalize(reflect(directional_light[i].direction, frag_normal)); float specularFactor = pow(dot(toEye, lightReflect), specularPower); if (specularFactor > 0.0) specularColour = vec4(directional_light[i].colour, 1.0) * specularIntensity * specularFactor; } totalLight += (ambientColour + diffuseColour + specularColour); } return totalLight; } vec4 CalculatePointLight(void) { vec4 totalLight = vec4(0, 0, 0, 0); for (int i = 0; i < num_point_lights; ++i) { // ... // TODO } return totalLight; } vec4 CalculateSpotLight(void) { vec4 totalLight = vec4(0, 0, 0, 0); for (int i = 0; i < num_spot_lights; ++i) { // ... // TODO } return totalLight; } // // entry // void main(void) { vec4 totalLight = CalculateDirectionalLight(); totalLight += CalculatePointLight(); totalLight += CalculateSpotLight(); out_colour = texture(texture0, frag_texCoord0.st) * frag_colour * totalLight; } Will conintue looking myself, but time for bed :( TY for any help
  3. I figured it out, it was such a silly mistake :( When i first made my static models i flipped the vertex z and y's because the blender file i used had them flipped. I totally forgot I did this!! Ofc the vectors and quaternions i left the same for animation. Which meant all my transforms looked like the other program I was trying to match and it was my vertices were wrong!!!!!!!! So sorry :|
  4. Thanks I'll check that link out tommoz.   The locations are found when the shader is created // keep adding bones till it fails int i = 0; int location; while (_GetUniformInfo(FormattedString("bone_matrix[%d]", i), &location)) { m_boneLocation.push_back(location); ++i; } LOG->Send("Shader supports %d bones", m_boneLocation.size()); bool CShader::_GetUniformInfo(const std::string & name, int *pLocation) { ASSERT(pLocation != nullptr, "pLocation is NULL"); *pLocation = glGetUniformLocation(m_programID, name.c_str()); if (*pLocation == -1) return false; return true; } My bones are sent from the Mesh void CBonedMesh::Render(float alpha, const std::vector<CModelBone> *pBoneTrans) { CVideo *pVideo = GAME->GetVideoManager()->GetVideo(); m_pShader->UseShader(); m_pShader->SendMVPMatrix(pVideo->PassModelViewProjectionMatrix()); m_pShader->SendAlpha(alpha); m_pShader->SendTextureID(0); m_pShader->SendBoneTransforms(pBoneTrans); if (m_texSlot != NO_TEXTURE) GAME->GetVideoManager()->GetTextureController()->BindTexture(m_texSlot); glBindVertexArray(m_object); glDrawElements(GL_TRIANGLES, m_indices.size(), GL_UNSIGNED_INT, 0); glBindVertexArray(0); } to the shader, which sends each one void CShader::SendBoneTransforms(const std::vector<CModelBone> *pBoneTrans, bool transpose) { ASSERT(pBoneTrans->size() < m_boneLocation.size(), "This shader doesn't support this many bone transforms"); foreach ((*pBoneTrans), bone) _SendUniform(m_boneLocation[bone->GetID()], bone->GetFinalTrans().GetData(), transpose); } Sending of the uniform, transpose is defaulted to false void CShader::_SendUniform(int location, const float *pMatrix, bool transpose) { glUniformMatrix4fv(location, 1, transpose, pMatrix); } Ty again for link, hopefully I can find some info to use :)
  5. I set it to an identity matrix for non bonenodes so it wouldnt do anything anyway
  6.   Not sure which part you mean, the creation of the final transforms (that will be bone_matrix in the shader) or bone array (containing boneID+vertex).   During the converter, for each mesh the code // bones list if (pMesh->HasBones()) {     if (m_type == TYPE_ANIMATED)         m_type = TYPE_BONED;     mesh.boneList.resize(pMesh->mNumVertices);     for (unsigned int bone = 0; bone < pMesh->mNumBones; ++bone)     {         CBoneData boneData;         int boneID = 0;         std::string boneName = pMesh->mBones[bone]->mName.data;                  if (m_boneMapping.find(boneName) != m_boneMapping.end())         {             boneID = m_boneMapping[boneName];         }         else         {             boneID = m_boneInfo.size();             m_boneMapping[boneName] = boneID;                          BONED_MODEL_SKELETON_BONE boneInfo;             boneInfo.m_id = boneID;             strcpy(boneInfo.m_name, boneName.c_str());             CMatrix(pMesh->mBones[bone]->mOffsetMatrix).FillAsColMajor(boneInfo.m_boneOffset);             m_boneInfo.push_back(boneInfo);         }         for (unsigned int w = 0; w < pMesh->mBones[bone]->mNumWeights; ++w)             _AddBone(&mesh, pMesh->mBones[bone]->mWeights[w].mVertexId, boneID, pMesh->mBones[bone]->mWeights[w].mWeight);     } } // validate the boneslist (weights should total to 1.0) for (unsigned int i = 0; i < mesh.boneList.size(); ++i) {     float total = 0.0f;     for (int w = 0; w < MAX_BONES_PER_VERTEX; ++w)         total += mesh.boneList[i].weight[w];     if (total > 0.0f && total < 1.0f)         throw std::string("Total weights are not equal to 1.0"); } void CScene::_AddBone(CModelMesh *pMesh, unsigned int vertexID, int boneID, float weight) { for (int i = 0; i < MAX_BONES_PER_VERTEX; ++i) if (pMesh->boneList[vertexID].weight[i] == 0.0f) { pMesh->boneList[vertexID].id[i] = boneID; pMesh->boneList[vertexID].weight[i] = weight; return; } throw std::string("Cannot add more weights to this vertex"); } Above is the first part of collecting all the bone information. Here also the boneList is populated, through _AddBone. The boneList is defined as const int MAX_BONES_PER_VERTEX = 4; struct CBoneData { CBoneData(void); // init all entries to 0 int id[MAX_BONES_PER_VERTEX]; float weight[MAX_BONES_PER_VERTEX]; }; In my actual program where the data of the custom format is being read. The bone list is created by reading the data if (m_header.m_numBones > 0) pFileManager->ReadBytes(pFile, m_header.m_numBones * sizeof(CBone), &m_bones[0]); A buffer is generated and setup if (m_bones.size() > 0) { glGenBuffers(1, &m_boneBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_boneBuffer); glBufferData(GL_ARRAY_BUFFER, m_bones.size() * sizeof(CBone), &m_bones[0], GL_STATIC_DRAW); } Once a shader has been set for the mesh the following code is used if (m_bones.size() > 0) { glBindBuffer(GL_ARRAY_BUFFER, m_boneBuffer); glVertexAttribIPointer(m_pShader->GetBoneInID(), CBone::MAX_BONES_PER_VERTEX, GL_INT, sizeof(CBone), (const GLvoid*)CBone::OFFSET_TO_ID); glVertexAttribPointer(m_pShader->GetBoneWeightInID(), CBone::MAX_BONES_PER_VERTEX, GL_FLOAT, GL_FALSE, sizeof(CBone), (const GLvoid*)CBone::OFFSET_TO_WEIGHT); } The bone structure used in my main program (CBone) is defined as class CBone { public: static const int MAX_BONES_PER_VERTEX = 4; // based on order, since boneID then weight static const int OFFSET_TO_ID = 0; static const int OFFSET_TO_WEIGHT = sizeof(int) * MAX_BONES_PER_VERTEX; explicit CBone(void) { for (int i = 0; i < MAX_BONES_PER_VERTEX; ++i) { boneID[i] = 0; weight[i] = 0; } } int boneID[MAX_BONES_PER_VERTEX]; float weight[MAX_BONES_PER_VERTEX]; }; // =========================================================================================================== This is how the skeleton is created by the converter, which is eventually read by the main program. Just listed for reference. void CScene::BuildSkeleton(const aiNode *pNode) { int boneID = 0; std::string name = pNode->mName.C_Str(); // check if its a bone (will have its name in our already built bone list) // if its not there it will need creating, even if a camera etc, as it may contain children bones if (m_boneMapping.find(name) == m_boneMapping.end()) { boneID = m_boneInfo.size(); m_boneMapping[name] = boneID; BONED_MODEL_SKELETON_BONE boneInfo; boneInfo.m_id = boneID; strcpy(boneInfo.m_name, name.c_str()); CMatrix().LoadIdentity().FillAsColMajor(boneInfo.m_boneOffset); m_boneInfo.push_back(boneInfo); } else boneID = m_boneMapping[name]; // add to skeleton CMatrix(pNode->mTransformation).FillAsColMajor(m_boneInfo[boneID].m_transform); m_boneInfo[boneID].m_numChildren = pNode->mNumChildren; m_skeleton.push_back(m_boneInfo[boneID]); // handle all its children for (unsigned int i = 0; i < pNode->mNumChildren; ++i) BuildSkeleton(pNode->mChildren[i]); } Sorry for so much spam However f you meant how the bone tranforms are made, its void CModelBone::_ProcessTransforms(const CModelAnimator & animator, CModelBone *pBone, const aat::matrix4f & parentTransform, const aat::matrix4f & globalInverse) { aat::matrix4f transformation = pBone->m_transform; if (animator.HasAnimations() && animator.BoneHasKeyframes(pBone)) { aat::matrix4f translation = animator.GetInterpolatedTranslation(pBone); aat::matrix4f rotation = animator.GetInterpolatedRotation(pBone); aat::matrix4f scale = animator.GetInterpolatedScale(pBone); transformation = translation * rotation * scale; } transformation = parentTransform * transformation; pBone->m_finalTrans = globalInverse * transformation * pBone->m_offset; foreach (pBone->m_subBones, bone) _ProcessTransforms(animator, (*bone), transformation, globalInverse); } Called by void CModelBone::ProcessTransforms(const CModelAnimator & animator, const aat::matrix4f & globalInverse) { _ProcessTransforms(animator, this, aat::matrix4f().Identity(), globalInverse); } Which is called in the model update from the rootbone m_pRootBone->ProcessTransforms(m_animator, m_bonesGlobalInverse);
  7. Hi, i've been using Assimp to extract model information into a custom format and use in my program. However I havnt been able to render it correctly.   I have managed to get the vertices rendered without using the bones. This creates the basic pose of the guy (img 1) just holding his hands out. [attachment=21851:screenshot1.png] However once i get the animator creating bone matrices for it to use things get weird (img 2). [attachment=21852:screenshot2.png] I decided to use the assimp source code to check if some of my calculations were correct. First i checked the final transformations of each bone matched assimps at frametime 0. They are now matched, so I have the same final formations for each bone (except mine are column-major, and assimp is row-major).   Since my final formations seemed ok I decided to keep looking for my distortion problem. I checked my vertices contained the correct boneIDs and weights.   After checking those were correct I double checked my shader #version 330 const int MAX_BONES_PER_MESH = 50; uniform mat4 mvp_matrix; uniform float alpha; uniform mat4 bone_matrix[MAX_BONES_PER_MESH]; in vec3 in_vertex; in vec3 in_colour; in vec2 in_texCoord0; in vec3 in_normal; in ivec4 in_boneID; in vec4 in_boneWeight; out vec4 colour; out vec2 texCoord0; out vec3 normal; void main(void) { mat4 boneMatrix = bone_matrix[in_boneID[0]] * in_boneWeight[0]; boneMatrix += bone_matrix[in_boneID[1]] * in_boneWeight[1]; boneMatrix += bone_matrix[in_boneID[2]] * in_boneWeight[2]; boneMatrix += bone_matrix[in_boneID[3]] * in_boneWeight[3]; vec4 position = boneMatrix * vec4(in_vertex, 1.0); gl_Position = mvp_matrix * position; colour = vec4(in_colour, alpha); texCoord0 = in_texCoord0; normal = in_normal; } which I don't think contains any error.   So i was wondering is anyone has experienced distortion like these images and had the problem lay elsewhere. Is there something I should check next. I will double check my data in the meanwhile. I can give more information if u need, just ask!   Ty for any help
  8. Hi, I have a few questions and was hoping you could help point me in the right direction.   I basically want to create a 3D Model/Character in a game that can load different armours.   I'm thinking the best way is to use some kind of bone structure/system as keyframes on verticies would be a pain to update, if for example someone wanted to change the animation slightly all armour would need re-exporting too.   If I use bones I could load the bones and mesh seperately and have it calculated in-game. Then only the bone needs updating and all armours will update accordngly when used. (Im assuming I'm thinking of this correctly).   My problem is I don't really know where to start. It would be great if you had some resources/info on this subject. Preferably using Blender/openGL/C++.   Or if you don't have any resources perhaps you could answer some questions: Can bones be exported seperately from mesh in Blender (if so any idea how?) What is the best format to store all this information. I know .obj doesnt support bones so thats out Am i going about this the right way (for multiple armour/gear) or is there another way to think about this I'd really love a tutorial or something though. Anyway any kind of help is appreciated! So Thanks.