Note that there are some explanatory texts on larger screens.

plurals
  1. POHLSL Point Light shader causing tiles to be shaded separately
    text
    copied!<p>I've recently started learning HLSL after deciding that I wanted better lighting than what BasicEffect offered. After going through many tutorials, I found this and decided to learn from it: <a href="http://brooknovak.wordpress.com/2008/11/13/hlsl-per-pixel-point-light-using-phong-blinn-lighting-model/" rel="nofollow">http://brooknovak.wordpress.com/2008/11/13/hlsl-per-pixel-point-light-using-phong-blinn-lighting-model/</a></p> <p>It seems that the shader above doesn't work very well in my game though, because my game uses a tile based approach, which means multiple models in a grid-like formation.</p> <p>What happens is that each of my tiles gets shaded separately from the others. Please see this image for a visual reference: <a href="http://i.imgur.com/1Sfi2.png" rel="nofollow">http://i.imgur.com/1Sfi2.png</a> I understand that this is because each tile has it's own model and the shader doesn't take into account other models as it's executing on the meshes of a model.</p> <p>Now, for the question. How does one go about to shade all the tiles together? I understand that I may have to write a shader from scratch to accomplish this, but if anyone could give me some tips on how to achieve the effect I want, I'd really appreciate it.</p> <p>It's late so there's a possibility that I've forgotten something. If you need more information, please tell me and I'll add it.</p> <p>Thanks, Merigrim</p> <p><strong>EDIT:</strong></p> <p>Here is my code for drawing a model:</p> <pre class="lang-cs prettyprint-override"><code>public void DrawModel(Model model, Matrix modelTransform, Matrix[] absoluteBoneTransforms, Vector3 color, float alpha = 1.0f, Texture2D texture = null) { foreach (EffectPass pass in effect.CurrentTechnique.Passes) { foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = effect; Matrix world = absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform; effect.Parameters["World"].SetValue(absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform); effect.Parameters["View"].SetValue(camera.view); effect.Parameters["Projection"].SetValue(camera.projection); effect.Parameters["CameraPos"].SetValue(camera.cameraPosition); Vector3 lookAt = camera.cameraPosition + camera.cameraDirection; effect.Parameters["LightPosition"].SetValue(new Vector3(lookAt.X, 1.0f, lookAt.Z - 5.0f)); effect.Parameters["LightDiffuseColor"].SetValue(new Vector3(0.45f, 0.45f, 0.45f)); effect.Parameters["LightSpecularColor"].SetValue(new Vector3(0.45f, 0.45f, 0.45f)); effect.Parameters["LightDistanceSquared"].SetValue(40.0f); effect.Parameters["DiffuseColor"].SetValue(color); effect.Parameters["AmbientLightColor"].SetValue(Color.Black.ToVector3()); effect.Parameters["EmissiveColor"].SetValue(Color.White.ToVector3()); effect.Parameters["SpecularColor"].SetValue(Color.White.ToVector3()); effect.Parameters["SpecularPower"].SetValue(10.0f); if (texture != null) { effect.Parameters["DiffuseTexture"].SetValue(texture); } mesh.Draw(); } } pass.Apply(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload