andyS91

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

105 Neutral

About andyS91

  • Rank
    Newbie
  1. Is there a way to add a texture to an object so that you can only see it on the shadow side of the object (some kind of inverse lightning)? I've got a sphere with a earth texture on it and a light (sun) rotating around the earth. The lighted side looks fine but the shadow side is just black (or gray shadowed depending on material settings). What i want is to add a 2. texture with earth at night (city lights and so on) which should only be visible on the shadow side and not on the daylight side. I've searched for hours and tried different lightning and blending options but nothing worked. The night texture is either visible everywhere or no where. Any suggestions how to solve this? Thank you in advance! p.s. I'm using DirectX9
  2. Distorted Texture on Sphere

    Thank you very much - now I've got it! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] If someone is having the same problems, here's the code for adding texture coordinates to a standard sphere mesh: [code] public static void ComputeTexCoords(Device device, ref Mesh mesh) { mesh.ComputeNormals(); Mesh newMesh = mesh.Clone(device, mesh.CreationOptions, mesh.VertexFormat | VertexFormat.Texture1); mesh.Dispose(); mesh = newMesh; VertexElement[] elems = mesh.GetDeclaration(); int posElem = FindElementIndex(elems, DeclarationUsage.Position); int normalElem = FindElementIndex(elems, DeclarationUsage.Normal); int texCoordsElem = FindElementIndex(elems, DeclarationUsage.TextureCoordinate); DataStream ds = mesh.LockVertexBuffer(LockFlags.None); while (ds.Position < ds.Length) { long oldPos = ds.Position; Vector3 vec; ds.Position += elems[normalElem].Offset; vec = ds.Read<Vector3>(); ds.Position = oldPos; var phi = Math.Acos((double)vec.Y); var v = (float)(phi / Math.PI); var u = 0f; if (vec.Y == 1.0f || vec.Y == -1.0f) { u = 0.5f; } else { u = (float)(Math.Acos(Math.Max(Math.Min(( double)-vec.Z / Math.Sin(phi), 1.0 ), -1.0)) / (2.0 * Math.PI)) ; u = (vec.X > 0f) ? u : 1 - u; } ds.Position += elems[texCoordsElem].Offset; ds.Write<float>(u); ds.Write<float>(v); ds.Position = oldPos + mesh.BytesPerVertex; } mesh.UnlockVertexBuffer(); }[/code] [code] public static int FindElementIndex(VertexElement[] elems, DeclarationUsage usage) { for (int i = 0; i < elems.Length; ++i) { if (elems[i].Usage == usage) return i; } return -1; }[/code] Just create a sphere with Mesh.CreateSphere and a Texture with Texture.FromFile, call the ComputeTexCoords method with this mesh and your D3D9 device as argument and set up drawing the texture with device.setTexture in your render method. I also recommend to set the renderstate to device.SetRenderState(RenderState.Wrap0, TextureWrapping.WrapCoordinate0) to avoid a ugly seam. Most of the sourcecode isn't written by me (indeed I've written very less of it myself). The underlaying structure is from this post here: [url="http://www.gamedev.net/topic/548474-slimdx-mesh-utility-functions-source-included/"]http://www.gamedev.n...ource-included/[/url] with changes regarding the calculation of the UV-coordinates (which I've taken from here: [url="http://channel9.msdn.com/coding4fun/articles/Ask-the-ZMan-Applying-Textures-Part-3"]http://channel9.msdn...Textures-Part-3[/url]). I hope the authors of those articles don't mind if I reuse their code. Thanks again for your help and good luck for those who try to do the same ;)
  3. I was trying to add some Textures to a sphere created with Mesh.CreateSphere. As far as i know those spheres don't have texture coordinates so i tried to add them using the sample code provided here [url="http://www.gamedev.net/topic/548474-slimdx-mesh-utility-functions-source-included/"]http://www.gamedev.n...ource-included/[/url]. I called the ComputeTexCoords method from the first post with the previously created mesh as argument and then set the texture with SetTexture in the render method (Mike's code in the second post throws for some reason out of bounds exceptions and I don't know why). When launching the program everything seems to be ok but when i rotate the sphere by 90° (no matter in which direction) the texture is highly distorted (like a vortex around the x-axis). The texture I was trying to use is this one: [url="http://celestia.h-schmidt.net/earth-vt/unshaded1024.jpg"]http://celestia.h-sc...nshaded1024.jpg[/url]. If it's helpful i'll post a screenshot of the distorted texture on the sphere later (it's on another computer). Can someone tell me what I'm doing wrong? Is it something with the ComputeTexCoords method or with the Texture? Do I have to change some RenderState/SamplerState settings? Thank you in advance. p.s.: I'm using Direct3D9 with SlimDX and Visual Studio 2008 (C#)