• 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.

Michael Smith_49683

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Michael Smith_49683

  • Rank
    Newbie
  1. I think I have it figured out. I will post more soon if I get it working. That way, if others have problems with omni-directional shadow maps, or spot lights in general, it will hopefully help them. =) EDIT : It works now! =D [attachment=6864:SM_error_fixed_0.png] Basically, the problem was pretty isolated to a trigonometry problem, which was good. But, it was a silly mistake and I guess being over tired and rushing, I wasn't even thinking. The following code (and previous samples) are working for a basic spot-light effect with shadow mapping in XNA. There still needs to be changes to include range-distance decay, and obviously the code can be optimized and condensed, but it's a good starter point. =) [b]Code changes : [/b] [b](1) Added m_fInnerConeCos and m_fOuterConeCos variables[/b], which are calculated whenever m_fOuterConeAngle and m_fInnerConeAngle change. I simply find m_fOuterConeAngle and m_fInnerConeAngle normalized values easier to type in for an editor and visualize, but the shader needs the new variables. // Angle between light direction and cone edge. // Normalized between 0 and 1 for half-cone angle, where 0 is no angle and 1 is 90 degrees (full 180 spot-light). private float m_fInnerConeAngle = 0.0f; private float m_fOuterConeAngle = 0.0f; private float m_fInnerConeCos = 0.0f; // Cached value. To compare to a dot product value in a spot light shader. private float m_fOuterConeCos = 0.0f; [b]new variables are calculated like so, if/whenever the cone's change, on the CPU in XNA:[/b] m_fOuterConeCos = (float)Math.Cos(m_fOuterConeAngle * (float)MathHelper.PiOver2); m_fInnerConeCos = (float)Math.Cos(m_fInnerConeAngle * (float)MathHelper.PiOver2); These are given to the shader, which calculates the lighting shown in the first post, in replacement of the original inner-outer values. [b](2) Changes to the HLSL Effect shader - For calculating the lit-shadowed areas, shadow map already computed at this point and being used:[/b] #elif defined(SPOT) float4 lightingPosition = GetPositionFromLight(_psin.pos3D, gViewLight, gProjLight); // Get our position on the shadow map float4 lightPositionViewSpace = mul( _psin.pos3D, gViewLight ); float shadowdepth = GetShadowMapDepthValue(lightingPosition); float shadowsample = -(lightPositionViewSpace.z / gFarClipPlaneLight) - 0.03f; float fInShadow = (shadowsample < shadowdepth) ? 1.0f : 0.0f; float fInnerConeTest = 1.0f - saturate( dot(vLightToVertexNormalized, normalize(gLightDirection)) ); float fStepResult = 1.0f - smoothstep(1.0f - gLightInnerConeAngle, 1.0f - gLightOuterConeAngle, fInnerConeTest); diffuseLightingFactor = saturate( dot(-vLightToVertexNormalized, _psin.normal)) * fStepResult * fInShadow; #endif That's it, have a great day! - Michael
  2. Hello everyone, I am having an issue with shadow mapping with a spot light in XNA. The issue is, my shadow map area does not seem to coincide with the spot light area. I'm done a lot of internet searching. Found some tutorials and many forum topics, but am still unable to solve my issue. Perhaps an illustration will better show my problem =) [attachment=6859:SM_Error_0.jpg] The light (white blob in center) is positioned in the world and it's direction is (0, 0, -1). The error region (green square) seems incorrect, I would like the shadow map region to coincide with the (white square) region, "wrapping around" the spot-light. Here is the 1024x1024 floating point 32-bit shadow-depth map in PNG format. White is furthest possible distance, blue is occluding objects. [attachment=6860:SM_Error_DepthMap_0.jpg] I will post some test CODE SNIPPETS to show my methods, keep in mind these are not finished or optimized yet : [b]--------------[/b] [u][b]HLSL Effect file - Shadow Map Creation :[/b][/u] // Vertex Shader VSOut TransformVS( VSIn _vsin ) { // Zero out our output structure VSOut _output = (VSOut)0; _output.pos = float4(_vsin.pos, 1.0f); #if defined(SKINNED) int IndexArray[4] = (int[4])_vsin.BoneIndices; _output.pos = SkinningTransformPosition(gBones, _vsin.BoneWeights, IndexArray, _vsin.pos); #endif float4 vPosLightCast = GetPositionFromLightCast(_output.pos, gWorld, gViewLight, gProjLight); ..... #elif defined(SPOT) float4 vLightViewSpace = mul( mul( _output.pos, gWorld ), gViewLight ); _output.depth = vLightViewSpace.z; #endif _output.pos = vPosLightCast; // Return output return _output; } // Pixel Shader PSOut TransformPS( PSIn _psin ) : COLOR { PSOut _output = (PSOut)0; ..... #elif defined(SPOT) float fDepthVal = -(_psin.depth / gFarClipPlaneLight); // Negate because we are in Right-Handed Coordinate System. _output.color = float4(fDepthVal, 0, 0, 1); #endif return _output; } [b]--------------[/b] [u][b]HLSL Effect file - Spot Light Lighting - Depth Map already computed and being used here.[/b][/u] .... float4 GetPositionFromLight(float4 pos, float4x4 viewLight, float4x4 projLight) { float4x4 ViewProjection = mul( viewLight, projLight ); return mul(pos, ViewProjection); } float GetShadowMapDepthValue(float4 lightingPosition) { // Get the shadow map depth value for this pixel float2 ShadowTexC = 0.5 * (lightingPosition.xy / lightingPosition.w) + float2( 0.5, 0.5 ); ShadowTexC.y = 1.0f - ShadowTexC.y; return tex2D(TextureShadowMapSampler, ShadowTexC).r; } PSOut TransformPS( PSIn _psin ) : COLOR { ....... // _psin.pos3D is in world space // gLightPos is light position in world space float3 vLightToVertex = _psin.pos3D.xyz - gLightPos; // Compute the vector from the light position to the vertex. float3 vLightToVertexNormalized = normalize( vLightToVertex ); float fLightToVertexLength = distance( _psin.pos3D.xyz, gLightPos ); ...... #elif defined(SPOT) float4 lightingPosition = GetPositionFromLight(_psin.pos3D, gViewLight, gProjLight); // Get our position on the shadow map float4 lightPositionViewSpace = mul( _psin.pos3D, gViewLight ); float shadowdepth = GetShadowMapDepthValue(lightingPosition); float shadowsample = -(lightPositionViewSpace.z / gFarClipPlaneLight) - 0.03f; float fInShadow = (shadowsample < shadowdepth) ? 1.0f : 0.0f; float fInnerConeTest = 1.0f - saturate( dot(vLightToVertexNormalized, normalize(gLightDirection)) ); float fStepResult = 1.0f - smoothstep(gLightInnerConeAngle, gLightOuterConeAngle, fInnerConeTest); diffuseLightingFactor = saturate( dot(-vLightToVertexNormalized, _psin.normal)) * fStepResult * fInShadow; #endif .... // diffuseLightingFactor is then used in a lighting equation... } [u][b]Next is some C# XNA code showing how the view and projection matrices are calculated for the depth map calculation phase, the depth map itself seems to be okay...I hope =)[/b][/u] // Angle between light direction and cone edge. // Normalized between 0 and 1 for half-cone angle, where 0.0f is no angle and 1.0f is 90 degrees (both sides 90 degrees = full 180 spot-light). private float m_fInnerConeAngle = 0.0f; private float m_fOuterConeAngle = 0.0f; public override Matrix GetLightProjectionMatrix() { float fFOV = Math.Min(m_fOuterConeAngle * (float)Math.PI, (float)Math.PI); return Matrix.CreatePerspectiveFieldOfView( fFOV, // Between 0 and PI (180 degrees). 1, m_fNearClipPlane, m_fFarClipPlane); } public override Matrix GetLightViewMatrix() { Vector3 m_vLookAtPoint = m_vPosition + m_vDirection; Vector3 vUp = new Vector3(0.0f, 1.0f, 0.0f); // Special case : Change the up-vector if looking straight UP or DOWN. // Direction should always be normalized for testing. float fUpDownTest = Math.Abs(m_vDirection.Y); float fEpsilon = 1e-10f; if (fUpDownTest < (1.0f + fEpsilon) && fUpDownTest > (1.0f - fEpsilon)) { if (m_vDirection.Y > 0.0f) { vUp = new Vector3(0.0f, 0.0f, -1.0f); } else { vUp = new Vector3(0.0f, 0.0f, 1.0f); } } return Matrix.CreateLookAt(m_vPosition, m_vLookAtPoint, vUp); } [b]----------------[/b] Any help would be so so so much appreciated, I've been spinning my wheels, perhaps looking at this too long. I just can't seem to figure it out. I'm also finding it hard to find tutorials on the subject, without holes in them, in general. =) - Michael
  3. Hello All! I have having a problem with skinned meshes and ragdoll physics using BEPUPhysics in XNA 3.1. I am not a math expert, and the issue lies mostly in not understanding how to skin my meshes when physics is activated on a mesh (ie. ragdoll) I already have skinned meshes rendering and animating. The problem lies when physics takes over in my game. When I activate physics, whether in the T-Pose or in the middle of an animation on a mesh, I create a bunch of physics boxes using BEPU and add them to the physics space. They are positioned in world space given the animations current bone transformations and world transform. Using constraints, they seem to render fine using debug boxes I created, and fall/contort realistically. First picture is T-Pose with user defined collision boxes. Second picture is when physics takes over and the physics objects laying on some steps below. [attachment=6628:physics0.jpg] [attachment=6629:physics1.jpg] So, again I am not sure how to transform my vertices to match the ragdoll. I have a skinned shader which takes a world matrix and skeleton transforms, and then performs pretty standard hardware skinning. The skeleton transforms are calculated below for animations, which I believe is pretty standard. for (int i = 0; i < bones.Count; i++) { Bone bone = bones[i]; bone.ComputeAbsoluteTransform(); m_boneTransforms[i] = bone.AbsoluteTransform; } // // Determine the skin transforms from the skeleton // for (int s = 0; s < m_modelExtra.Skeleton.Count; s++) { Bone bone = bones[m_modelExtra.Skeleton[s]]; skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform; } public void ComputeAbsoluteTransform() { Matrix transform = Matrix.CreateScale(Scale * bindScale) * Matrix.CreateFromQuaternion(Rotation) * Matrix.CreateTranslation(Translation) * BindTransform; if (Parent != null) { // This bone has a parent bone AbsoluteTransform = transform * Parent.AbsoluteTransform; } else { // The root bone AbsoluteTransform = transform; } } I would appreciate some direction in how I need to calculate the skeleton matrices given box physics objects in world space. =) I am having lots of trouble understanding the concept and step-by-step instructions on how to proceed, especially after just wrapping my head around animation skinning. Thank you so much, I'm sure I'll need to elaborate more on certain things. - Mike