Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

124 Neutral

About clarkm2

  • Rank
  1. I'm trying to use orthographic projective texturing to map a texture to a section of my terrain. The section consists of a grid of 21x21 quads that span a region of 100x100 logical units centered at the origin. I finished writing up the framework using C# (SlimDX) and HLSL, but my "projected" image is stretched along the z-axis. I provided relevant sections of my code below for review, please let me know what I'm missing. // -- I set the width and height to size of my region -- // m_ProjMatrix = Matrix.OrthoLH(100, 100, 0.1f, 100); // -- Rotate camera to point at the origin in the -y direction (world down) --// var m_ViewMatrix = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) * Matrix.Translation(0, -40, 0); // -- I then send the ViewProj (m_ViewMatrix * m_ProjMatrix) Matrix to my vertex Shader as mProjector using a constant buffer -- // PS_INPUT VS(VS_INPUT_TYPE1 inData) { PS_INPUT results = (PS_INPUT)0; results.vPos=mul(float4(inData.vPos,1),mWorldViewProj); results.vProject = mul(float4(inData.vPos,1),mProjector); return results; } SamplerState SamplerLinear { Filter = MIN_MAG_MIP_LINEAR; AddressU = Clamp; AddressV = Clamp; }; float4 PS(PS_INPUT inData) : SV_Target { float2 vProjTex; vProjTex.x = inData.vProject.x/(inData.vProject.w/2) + 0.5f; vProjTex.y = 0.5f - inData.vProject.y/(inData.vProject.w/2); return g_ColorMap0.Sample( SamplerLinear, vProjTex); } thanks!
  2. I'm updating my GUI rendering algorithm by using the geometry shader (GS) and no longer supporting vertex coloring. The scale and position for each sprite is defined in the model matrix, so I no longer require a vertex buffer for this simple case. My first attempt was to make an empty vertex shader and set the input PrimitiveType argument to NULL in the GS as so void VS(){} [maxvertexcount(8)] void GS(NULL, inout TriangleStream<PS_INPUT> outStream ) { ... } Of course I got a compile error with the "NULL" argument, so I fixed the problem with a dummy structure and passed it into the GS as so struct GS_INPUT { float3 Rsvd : POSITION; }; GS_INPUT VS() { GS_INPUT results = (GS_INPUT)0; return results; } [maxvertexcount(8)] void GS(point GS_INPUT Data[1], inout TriangleStream<PS_INPUT> outStream ){ ... } Now this worked, but I'm wondering if there is another solution. Thanks
  3. clarkm2

    [SlimDX] EffectPool

    Oops... the child effect flag needed to be set. It's working now.
  4. I recently coded and tested an "unshared" constant buffer implementation for a single DX10 Shader Effect. I am now trying to expand this feature by sharing a constant buffer across each Effect file. It nearly complete, but my Effect files are not loading and no complication (from Effect.FromFile) or DirectX error messages are reported. Let me try to summarize my implementation. My constant buffer is defined in a header file (.fxh) and meets the 16 byte alignment rule as shown below: // -- Constants.fxh -- // shared cbuffer ChangePerFrame { row_major float4x4 mViewInv; // 64 Bytes, 0 Offset LIGHT_SOURCE oLight; // 96 Bytes, 64 Offset float3 vAmbientColor; // 12 Bytes, 160 Offset float fTimeMs; // 4 Bytes, 172 Offset } I first create the EffectPool by loading the header file and then creating the constant buffers, which executes successfully. m_EffectPool = EffectPool.FromFile(m_Device, @"..\..\FX\Constants.fxh", "fx_4_0", ShaderFlags.None, EffectFlags.None, out errors); // -- Get Effect -- // m_PoolEffect = m_EffectPool.AsEffect(); // -- Get Constant Buffer Reference -- // m_eUpdatePerFrame = m_PoolEffect.GetConstantBufferByName("ChangePerFrame"); // -- Create Constant Buffers -- // CreateBuffers(); Next, I simply load each Shader and pass in the EffectPool as so m_effect = SlimDX.Direct3D10.Effect.FromFile(m_Device, FilePath, GetProfile(version), ShaderFlags.None, EffectFlags.None, m_effectPool, null, out Errors); When I try to load the Effect file, the call fails by exception and does not report any error messages. I thought there might be syntax errors, but when I set m_effectPool = null the file is loaded successfully. I also verified a complication error is reported when I intentionally caused a syntax error. I also tried to load a dummy Effect file instead of the header, but this caused the same results. I must be missing a step, and yes I am including the header file in each Effect File. Quick question... Should I prevent the header from being loaded more then once by using the following code? #ifndef _H_CONSTANTS_ #define _H_CONSTANTS_ . . #endif
  5. Setting the DepthComparison = Comparison.LessEqual in the DepthStencilStateDescription did the trick : )
  6. I've recently ported my DX9 GUI system to DX10 and my depth ordering is now reversed. Each colored quad (sprite) is defined with the same "z" distance, and I'm using a orthographic projection matrix. I was expecting the "last" rendered sprite to be in front, but the "first" rendered sprite is currently in front. I did create a DepthStencil buffer, and I'm currently playing around with the DepthStencilState, but I'm having no luck. Any help would be appreciated.
  7. I'm calculating the frustum planes as defined in the paper "Fast Extraction of Viewing Frustum Planes from the World- View-Projection Matrix." I have a question concerning my results with the near plane equation. Here are the near and far plane equations: // Near clipping plane m_Planes[0].Normal.X = ViewProj.M13; m_Planes[0].Normal.Y = ViewProj.M23; m_Planes[0].Normal.Z = ViewProj.M33; m_Planes[0].Distance = ViewProj.M43; // Far clipping plane m_Planes[1].Normal.X = ViewProj.M14 - ViewProj.M13; m_Planes[1].Normal.Y = ViewProj.M24 - ViewProj.M23; m_Planes[1].Normal.Z = ViewProj.M34 - ViewProj.M33; m_Planes[1].Distance = ViewProj.M44 - ViewProj.M43; I set the near and far distances to 0.1 and 5000 respectively, and PI/4 for the FOV. When the View matrix is set to the Identity matrix, I get the following results... Near: Normal = {0,0,1} Distance = -0.1 Far: Normal = {0,0,-1} Distance = 4993.31934 and when I translate the view matrix in the -Z direction by 500, I get the following... Near: Normal = {0,0,1} Distance = -500.1 Far: Normal = {0,0,-1} Distance = 5493.3335 I double checked all the equations, so I'm just curious why the near plane would be "behind the camera." Maybe I'm missing somthing... EDIT: I forgot to mention that I am "normalizing" the Normal vector and the Distance by the magnitude of the normal vector.
  8. clarkm2

    Picking on a 2D plane

    I just finished porting the project to DirectX10, and I'm seeing the same error. I'm not sure if this is expected...
  9. clarkm2

    Picking on a 2D plane

    The equation has a typo: y = (1 - 2*Sy/H)*D*ATan(FOV/2), where D is position of the camera on the Zaxis, Sx is the pixel coordinate ,H is the backbuffer/Screen Height and FOV is the field of view in radians.
  10. I'm working on an graphics editor in C# using SlimDX. I created a 2D viewing window using a perspective projection. I would like to transform the mouse's "pixel" coordinates to logical units on the X-Y plane (centered at the origin). I positioned the camera at some arbitrary distance from the origin with a look-at direction normal to the X-Y plane. To help verify my calculations, I setup a 2D-Grid on the X-Y plane with a spacing of 8 units. My equation for the Y coordinate is shown below: y = (1 - 2*Sy/W)*D*ATan(FOV/2), where D is position of the camera on the Zaxis, Sx is the pixel coordinate ,W is the backbuffer/Screen Width and FOV is the field of view in radians. Here the function to create vertices for lines spaced along the Y axis: for (float row = -height / 2; row < height / 2; row += spacing) { Vertex.Position.Y = row; Vertex.Position.X = -width / 2; Vertex.Position.Z = depth; Vertex.Diffuse = color.ToArgb(); m_VertexList.Add(Vertex); Vertex.Position.Y = row; Vertex.Position.X = width / 2; Vertex.Position.Z = depth; Vertex.Diffuse = color.ToArgb(); m_VertexList.Add(Vertex); } When I test this out, my logical coordinates are not lining up with the GRID. It seems to be ~0.8 units off relative to the GRID on the Y axis. Any help would be appreciated.
  11. clarkm2

    Errors Including vfw.h

    It took awhile, but I found a #define POINT in my code which caused the error.
  12. I included <vfw.h> header after including <windows.h>, and I also included the vfw32.lib library file. Any ideas why I'm getting the following compile errors? 1>c:\program files\microsoft sdks\windows\v6.0\include\vfw.h(3551) : error C2059: syntax error : 'constant' 1>c:\program files\microsoft sdks\windows\v6.0\include\vfw.h(3551) : error C2238: unexpected token(s) preceding ';' Both errors occurs on the line shown below: typedef struct tagCapStatus { UINT uiImageWidth; // Width of the image UINT uiImageHeight; // Height of the image BOOL fLiveWindow; // Now Previewing video? BOOL fOverlayWindow; // Now Overlaying video? BOOL fScale; // Scale image to client? POINT ptScroll; // <-----Here // Scroll position
  13. clarkm2

    [SlimDX] Rendering Text Problem

    Thanks, I didn't setup the backbuffer width/height for the PresentParameters object. In several C# tutorials this was not defined, so for some reason I thought it was defined when I created the device given the user control handle.
  14. I created a C# user control to render my DirectX screen, and I'm try to get the position of the text aligned with a 2D texture and the mouse position. So far, the texture and mouse position are correct, but the text is not getting positioned correctly. After a few tests, I got the following results: Expected (0,0), (100,100), (300,300) Actual (0,0), (125,125), (375,375) Adding a sprite interface to the DrawString function didn't seem to fix the problem, so I just left it out. Any suggestions would be helpful. m_Font = new SlimDX.Direct3D9.Font(m_Device, 12, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.Antialiased | FontQuality.ClearTypeNatural | FontQuality.Proof, PitchAndFamily.DontCare, "Arial"); // BeginRender(); // m_Font.DrawString(null, "Hello", 300, 300, Color.Red); // EndRender();
  15. I guess D3DX and CreateTextureFromFile() were removed from the latest MDX release, but the equivalent is Texture.FromFile(). Knowing this I still checked out SlimDX and decided to port my project. I'm almost done now and I have no complaints. Thanks for the advice...
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!