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

antmck2013

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

113 Neutral

About antmck2013

  • Rank
    Newbie

Personal Information

  • Location
    Australia
  1. Here's the complete code for shader. At the moment I've calculated the normals for each vertex but not using them yet. Also, no real lighting just adding shadows, so I'm darkening pixels where a shadow is. As I said before I've tried several bias values.  The shadows just don't look right. This is self shadows on terrain only - at the moment.   float4x4 WorldMatrix; float4x4 ViewMatrix; float4x4 ProjectionMatrix; float4x4 LightViewMatrix; float4x4 LightProjectionMatrix; float maxHeight;           //maximum height of the terrain Texture2D heightMap; Texture2D shadowMap; Texture2D sandTexture; Texture2D grassTexture; Texture2D snowTexture; Texture2D rockTexture; SamplerState pointSampler; SamplerState linearSampler; SamplerState shadowMapSampler; struct VS_INPUT {     float4 Position : SV_POSITION;  float2 UV  : TEXCOORD0; }; struct VS_OUTPUT {     float4 Position   : SV_POSITION;  float4 Normal   : NORMAL0;     float2 UV    : TEXCOORD0;  float4 TextureWeights : TEXCOORD1; // Weights used for multitexturing   float  Depth            : TEXCOORD2; // Used for texture LOD  float4 LightPosition : TEXCOORD3; // Position in light space }; struct SHADOW_VS_INPUT {  float4 Position   : SV_POSITION;     float2 UV    : TEXCOORD0; }; struct SHADOW_VS_OUTPUT {  float4 Position : SV_POSITION;  float4 Depth    : TEXTURE0; }; //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- VS_OUTPUT VS(VS_INPUT input) {  float height = heightMap.SampleLevel(pointSampler, input.UV, 0).r;  input.Position.y = height * maxHeight;  float4x4 worldViewProj = mul(mul(WorldMatrix, ViewMatrix), ProjectionMatrix);  float4x4 lightWorldViewProj = mul(mul(WorldMatrix, LightViewMatrix), LightProjectionMatrix);  // Height values of adjacent vertices  float y = input.Position.y;  float N = heightMap.SampleLevel(pointSampler, input.UV, 0, float2(0,-1)).r * maxHeight;  float S = heightMap.SampleLevel(pointSampler, input.UV, 0, float2(0,1)).r * maxHeight;  float W = heightMap.SampleLevel(pointSampler, input.UV, 0, float2(-1,0)).r * maxHeight;  float E = heightMap.SampleLevel(pointSampler, input.UV, 0, float2(1,0)).r * maxHeight;  float NE = heightMap.SampleLevel(pointSampler, input.UV, 0, float2(1,-1)).r * maxHeight;  float SW = heightMap.SampleLevel(pointSampler, input.UV, 0, float2(-1,1)).r * maxHeight;  // Vectors joins adjacent vertices  float3 vectorN = float3(0, N - y, 1);  float3 vectorS = float3(0, S - y, -1);  float3 vectorE = float3(1, E - y, 0);  float3 vectorW = float3(-1, W - y, 0);  float3 vectorNE = float3(1, NE - y, 1);  float3 vectorSW = float3(-1, SW - y, -1);  // Average normal for current vertex  float3 normal = normalize(cross(vectorN, vectorNE) + cross(vectorNE, vectorE) + cross(vectorE, vectorS)      + cross(vectorS, vectorSW) + cross(vectorSW, vectorW) + cross(vectorW, vectorN));  VS_OUTPUT output = (VS_OUTPUT)0;  output.Position = mul(input.Position, worldViewProj);  output.Normal = mul(float4(normal, 1), WorldMatrix);  float4 texWeights = 0;     texWeights.x = saturate(1.0f - height * 3.0f);  texWeights.y = saturate(1.0f - abs(height - 0.4f) * 3.0f);  texWeights.z = saturate(1.0f - abs(height - 0.9f) * 3.0f);  texWeights.w = 1;  float totalWeight = texWeights.x + texWeights.y + texWeights.z;  texWeights.xyz /= totalWeight;  texWeights.w = 1;  if (normal.y > 0.81f)  {   texWeights.w = 0;  }  else if (normal.y > 0.75)  {   texWeights.w = normal.y;  }  output.TextureWeights = texWeights;  output.UV = input.UV;  output.Depth = output.Position.z/output.Position.w;  output.LightPosition = mul(input.Position, lightWorldViewProj);  //output.LightPosition /= output.LightPosition.w;   return output; } //-------------------------------------------------------------------------------------- // Pixel Shader //-------------------------------------------------------------------------------------- float4 PS(VS_OUTPUT input) : SV_TARGET {  float blendDistance = 0.99f;  float blendWidth = 0.005f;  float blendFactor = clamp((input.Depth - blendDistance) / blendWidth, 0, 1);  float4 weights = input.TextureWeights;  float scale = 4;  float4 rock = rockTexture.Sample(linearSampler, input.UV * scale);  float4 sand  = sandTexture.Sample(linearSampler,  input.UV * scale);  float4 grass = grassTexture.Sample(linearSampler, input.UV * scale);  float4 snow  = snowTexture.Sample(linearSampler,  input.UV * scale);  float4 farColour = rock * weights.w + (1 - weights.w) * (sand * weights.x + grass * weights.y + snow * weights.z);  scale = 16;  rock = rockTexture.Sample(linearSampler, input.UV * scale);  sand  = sandTexture.Sample(linearSampler,  input.UV * scale);  grass = grassTexture.Sample(linearSampler, input.UV * scale);  snow  = snowTexture.Sample(linearSampler,  input.UV * scale);  float4 nearColour = rock * weights.w + (1 - weights.w) * (sand * weights.x + grass * weights.y + snow * weights.z);  float4 colour = lerp(nearColour, farColour, blendFactor);  //--------------------------------------------------------------------------------------  // Shadows  //--------------------------------------------------------------------------------------  input.LightPosition.xyz /= input.LightPosition.w;  float2 projectedTexCoords;     projectedTexCoords[0] = input.LightPosition.x / 2.0f + 0.5f;     projectedTexCoords[1] = input.LightPosition.y / -2.0f + 0.5f;  float shadowMapDepth = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r;   if (shadowMapDepth < input.LightPosition.z - 0.0007f)  {   colour *= 0.25;  }  return colour; } //-------------------------------------------------------------------------------------- // Shadow Vertex Shader //-------------------------------------------------------------------------------------- SHADOW_VS_OUTPUT ShadowMapVS(SHADOW_VS_INPUT input) {  input.Position.w = 1.0f;  // Generate terrain height from heightmap     float height = heightMap.SampleLevel(pointSampler, input.UV, 0).r;  input.Position.y = height * maxHeight;  //float4x4 lightWorldViewProj = mul(mul(WorldMatrix, LightViewMatrix), LightProjectionMatrix);  SHADOW_VS_OUTPUT output = (SHADOW_VS_OUTPUT)0;  //output.Position = mul(input.Position, lightWorldViewProj);  output.Position = mul(input.Position,  WorldMatrix);     output.Position = mul(output.Position, LightViewMatrix);     output.Position = mul(output.Position, LightProjectionMatrix);  output.Depth = output.Position;     return output; }   //-------------------------------------------------------------------------------------- // Shadow Pixel Shader //-------------------------------------------------------------------------------------- float4 ShadowMapPS(SHADOW_VS_OUTPUT input) : SV_TARGET {  float zValue = input.Depth.z / input.Depth.w;  return float4(zValue, zValue, zValue, 1.0f); } //-------------------------------------------------------------------------------------- // Techniques //-------------------------------------------------------------------------------------- technique ShadowMap {     pass Pass0     {   SetVertexShader(CompileShader(vs_4_0, ShadowMapVS()));   SetGeometryShader(NULL);   SetPixelShader(CompileShader(ps_4_0,  ShadowMapPS()));     } } technique Terrain {     pass Pass0     {         SetVertexShader(CompileShader(vs_4_0, VS()));   SetGeometryShader(NULL);   SetPixelShader(CompileShader(ps_4_0,  PS()));     } }
  2. Actually I've tried several different values - done look right.  Is there a way calculate the ideal value?
  3. I have had a lot of trouble getting shadow mapping working with terrain.  I've used code from tutes too.  In fact pretty much the same code as listed further up this page.  I'm using SharpDX which is Directx10/11 based.  Either the entire terrain is in shadow or it's lit.  Looks really odd when the sun moves through a complete cycle.  Still don't have it working.  People tell me to put other objects in the scene and turn off shadows on the terrain, but I only have terrain.  At this point I just want the terrain to be correctly shadowed.  I'd like to do real-time editing and watch the shadows change.
  4. I only have terrain.  I want to get the self shadowing working.  I used code from tutes, so I assumed it would work. I've looked at tutes on http://www.riemers.net and http://takinginitiative.net/2011/05/15/directx10-tutorial-10-shadow-mapping/
  5. I've set the size of shadow map to equal the window client size so 800x600., but the window size can be changed - that doesn't cause any problems. I am still having trouble with shadows though.  At lease the shadow map is actually adding shadows now, but shadows still aren't right. Maybe something to do with converting the current vertex/pixel position into light space and then into texture space??   I have in the vertex shader: output.LightPosition = mul(input.Position, lightWorldViewProj); output.LightPosition /= output.LightPosition.w;   And in the pixel shader:     float2 projectedTexCoords; projectedTexCoords[0] = input.LightPosition.x / 2.0f + 0.5f; projectedTexCoords[1] = input.LightPosition.y / -2.0f + 0.5f;   float shadowMapDepth = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r;   float realDistance = input.LightPosition.z;   if ((realDistance - 1.0f / 100.0f) <= shadowMapDepth) {     colour *= 0.25; }   return colour;   I 'm using a left handed co-ord system. I added a screenshot.  The sun is 25deg above the east (x axis) and looking at the origin. The camera is looking west or in the -x direction.  There should not be that much shadow. The greyscale image in the corner is the heightmap.
  6. As I'm using SharpDX I posted their forums and found out that I need to set the render target before binding the shadow map. Now it renders shadows - there not quite right yet, but at least I have something to work with.
  7. Right, so no-one has an idea what's going on then?  Guess I'm never going to finish this - damn.
  8. I'm having a similar problem.  I have a height map that the vertex shader generates y values from, and I have 4 textures to render the terrain with in the pixel shader. I have a another vertex shader to generate a shadow map.  All of that works fine.  But adding shadows to the terrain (after texturing) doesn't work.  The line where the shadow map is sampled always returns zero.  All the other texture sampling works, just not the with the shadow map.  I have saved the shadow map texture and it looks fine.  The texture co-ords look OK too.  I don't understand what is going on.  All the other texture sampling is fine - why not this one???
  9. I'm new to shadow mapping.  I've followed some tutes on the net, but can't get this working. I've created a terrain using a heightmap and textured it comparing slope and height.  All that's working. Then I tried getting shadows to work.  I've created a shadow map by using the orthographic projection (for the sun) - projection matrix and view matrix from the light.  I've translated the current vertex/pixel to light-space.  I then used a texture sampler to lookup depth value from the shadow map texture.  At the moment I'm just testing if a pixel is in shadow or not.  If it's in shadow I add the shadow by darkening the pixel.  I've checked the tutes and my code "seems" OK, but no shadows show up.  I've attached the shadow map the was generated and some HLSL code.   Vertex Shader: ... output.LightPosition = mul(input.Position, lightWorldViewProj); output.LightPosition /= output.LightPosition.w;   return output; }   Pixel Shader: ...   float2projectedTexCoords;     projectedTexCoords[0] = input.LightPosition.x / 2.0f + 0.5f;     projectedTexCoords[1] = input.LightPosition.y / -2.0f + 0.5f;     float depthStoredInShadowMap = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r;   float realDistance = input.LightPosition.z;   if ((realDistance - 1.0f / 100.0f) <= depthStoredInShadowMap) { colour.xyz *= 0.25f; }   return colour; }     edit:  It seems that the line float depthStoredInShadowMap = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r; is always returning zero?? What is happening??