Magmatwister

Members
  • Content count

    118
  • Joined

  • Last visited

Community Reputation

109 Neutral

About Magmatwister

  • Rank
    Member
  1. If you want to start from scratch to create a workable planetary renderer, over summer, without knowing whether you're going to use OpenGL, DirectX, etc, etc, good luck, you'll need it. Just as a frame of reference, my current planetary renderer achieves around ~350fps in 'space' with the planet taking up most of the screen and maintains around 200fps at the surface. I still need to optimise my CPU throughput more than anything, though profiling has proved difficult with CodeAnalyst, so for now I'm focusing on expanding the project. I used six quadtree faces forming a cube, mapped to a sphere to form the planet in conjunction with GPU based heightmap, normalmap generation. If you need any help, ask, but I assure you this will be no small task. I'm sure you've seen it already, but if not check out the Infinity project for more ideas.
  2. The C++ Error challenge

    It took me about 2 minutes, probably slightly less, I was looking for even worse errors, but yeah, turned out to be simple. I've been programming in C++ solely for roughly 2 years, though I have yet to accomplish anything. ;D
  3. Scripted GUIs

    In my opinion, based on what you're saying, you want to use Awesomium, essentially, that should give you all you need. You can use both HTML and CSS with the Webkit library to get the kind of customisation you're looking for. Heres a couple of links to the GUI of a guy who did just that: [url="http://blog.wolfire.com/2009/05/new-object-palette-window/"]http://blog.wolfire.com/2009/05/new-object-palette-window/[/url] [url="http://blog.wolfire.com/2009/10/animation-mixing-ui/"]http://blog.wolfire.com/2009/10/animation-mixing-ui/[/url] NOTE: I haven't tried this yet, but I will be doing so soon, so I don't know how easy this is to pull off. You could
  4. [quote name='d k h' timestamp='1314563187' post='4854809'] That's the way Direct3D does it for example, very nice. Definitely the best option I think if you're going for an engine, I'm writing a game, though, so I'm not sure if I want to be this 'general' with my functions (which would be perfect for an engine of course) - basically, I think I can afford to be more specialized. Errors are displayed in a messagebox and logged in the console window, they'll shut the game down if they were fatal too. Am I right in thinking there's a difference in that regard between an engine and an actual game project? Or should I just go with the engine approach anyways? [/quote] Well, for one thing, you [b]really [/b]shouldn't be tieing that kind of functionality to your error handling. What you want to do is make sure that the errors propagate up your hierarchy to your highest class, I.E your Framework class, which will probably just quit the program. You shouldn't have low level classes ending your game, for whatever reason. At most, you should use an exception handling system, wherein, again, the framework class is the class that does the heavy lifting. Why should an object know how to end the game? At least, this is what approach it seems you're using from what you said.
  5. The camera, it's defeating me!

    [quote name='Goishin' timestamp='1313946313' post='4851942'] [quote] Directx11 requires the transposed matrices passed to it, it doesn't look like you're doing that. So in your shader, change this: [code] // Transform the position from object space to homogeneous projection space Output.Position = mul( input.Position, g_mWorldViewProjection ); [/code] to this [code] // Transform the position from object space to homogeneous projection space Output.Position = mul( input.Position, transpose(g_mWorldViewProjection) ); [/code] [/quote] I get called away to help a friend clear a field, a full day's work, and I come back to an immediate answer? Instant Karma!!! This was the answer, it works great!. Thank you so much, Snail Coder. [/quote] Also, that was just a quick fix, you really should be passing the matrices already transposed to the shader, simply use: [url="http://msdn.microsoft.com/en-us/library/bb204962(v=vs.85).aspx"]http://msdn.microsof...2(v=vs.85).aspx[/url] Transposing matrices per vertex per frame isn't really good for performance or necessary . Oh, and could I have some rep? I'm pretty low as you can see...
  6. The camera, it's defeating me!

    [quote name='Goishin' timestamp='1313810040' post='4851467'] Hello all, I'm having a great deal of difficulty with my camera. I have a test triangle on the screen that I've been using to troubleshoot my camera. But I'm clearly doing something incorrect in generating my camera matrix. When I turn even slightly away from head on towards the triangle, the triangle distorts wildly. I've included two screenshots, the first shows the triangle head on, and it looks correct. All three vertices appear correct and are colored correctly. But when I turn slightly away, everything distorts. You can see it in the second screenshot. Triangle head on [url="http://i.imgur.com/11XvT.jpg"]http://i.imgur.com/11XvT.jpg[/url] Turned slightly left [url="http://i.imgur.com/2cBkC.jpg"]http://i.imgur.com/2cBkC.jpg[/url] Does anyone have any advice for me? Let me give you a peek at the code that generates this utter failure: Camera class definition: [code]class Camera { public: Camera(ID3D11Device*); ~Camera(); void Update(); void Draw( ID3D11DeviceContext* ); void move ( float x ); void Yaw ( float x ); void Pitch ( float x ); void Roll ( float x ); void Slew ( float x ); void Elevate ( float x ); void Accelerate( float x ); void Stop(); void ResetToStartPosition(); D3DXVECTOR3* GetPosition(); D3DXVECTOR3* GetLook(); float GetNearClippingPlane(); float GetFarClippingPlane(); void SetNearClippingPlane( float ); void SetFarClippingPlane( float ); void SetPerspectiveAngle( float ); float GetPerspectiveAngle(); float GetYaw(){ return m_yaw; } float GetPitch(){ return m_pitch; } float GetRoll(){ return m_roll; } private: HRESULT SendCameraDataToGraphicsCard( ID3D11DeviceContext* pDeviceContext ); D3DXMATRIX m_view; D3DXMATRIX m_perspective; D3DXMATRIX m_world; D3DXVECTOR3 m_pos; D3DXVECTOR3 m_look; D3DXVECTOR3 m_up; D3DXVECTOR3 m_right; float m_fov; float m_yaw; float m_pitch; float m_roll; float m_vel; float m_acc; float m_nearClippingPlane; float m_farClippingPlane; ID3D11Buffer* m_ConstantBuffer; VS_CONSTANT_BUFFER m_ConstantBufferContents; };[/code] Camera constructor: [code] Camera::Camera( ID3D11Device* pDevice ) { m_pos = D3DXVECTOR3 (0.0f, 0.0f, -10.0f); m_look = D3DXVECTOR3 (0.0f, 0.0f, 1.0f); m_right = D3DXVECTOR3 (1.0f, 0.0f, 0.0f); m_up = D3DXVECTOR3 (0.0f, 1.0f, 0.0f); m_vel = 0.0f; m_acc = 0.0f; m_fov = D3DX_PI / 4.0f; m_yaw = 0.0f; m_pitch = 0.0f; m_roll = 0.0f; m_farClippingPlane = 1000.0f; m_nearClippingPlane = 0.01f; // Supply the vertex shader constant data. D3DXMATRIX identity; D3DXMatrixIdentity( &identity ); m_view = identity; m_perspective = identity; m_world = identity; m_ConstantBufferContents.m_WorldViewProj = identity; m_ConstantBufferContents.m_World = identity; // Fill in a buffer description. D3D11_BUFFER_DESC cbDesc; cbDesc.Usage = D3D11_USAGE_DYNAMIC; cbDesc.ByteWidth = sizeof( VS_CONSTANT_BUFFER ); cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; cbDesc.MiscFlags = 0; cbDesc.StructureByteStride = 0; // Create the buffer. HRESULT hr = pDevice->CreateBuffer( &cbDesc, nullptr, &m_ConstantBuffer ); D3DXMatrixPerspectiveFovLH( &m_perspective, m_fov, 1.f, m_nearClippingPlane, m_farClippingPlane ); } [/code] Camera draw function: [code] void Camera::Draw( ID3D11DeviceContext* pDeviceContext ) { float yaw = D3DXToRadian( m_yaw ); // rotation around the y axis float pitch = D3DXToRadian( m_pitch ); // rotation around the x axis float roll = D3DXToRadian( m_roll ); // rotation around the z axis D3DXVECTOR3 position = m_pos; // camera position D3DXVECTOR3 up = m_up; D3DXVECTOR3 look = m_look; D3DXVECTOR3 right = m_right; D3DXMATRIX rotation; D3DXMatrixRotationYawPitchRoll(&rotation, m_yaw, m_pitch, m_roll); D3DXVec3TransformCoord(&look, &look, &rotation); D3DXVec3TransformCoord(&up, &up, &rotation); D3DXVec3TransformCoord(&right, &right, &rotation); D3DXMATRIX viewMatrix; D3DXMatrixIdentity(&viewMatrix); viewMatrix._11 = right.x; viewMatrix._12 = up.x; viewMatrix._13 = look.x; viewMatrix._21 = right.y; viewMatrix._22 = up.y; viewMatrix._23 = look.y; viewMatrix._31 = right.z; viewMatrix._32 = up.z; viewMatrix._33 = look.z; viewMatrix._41 = - D3DXVec3Dot( &position, &right ); viewMatrix._42 = - D3DXVec3Dot( &position, &up ); viewMatrix._43 = - D3DXVec3Dot( &position, &look ); m_view = viewMatrix; SendCameraDataToGraphicsCard( pDeviceContext ); } [/code] Function to transfer the view projection matrix to the shader: [code] HRESULT Camera::SendCameraDataToGraphicsCard( ID3D11DeviceContext* pDeviceContext ) { D3DXMATRIX worldViewProjection = m_view * m_perspective; D3D11_MAPPED_SUBRESOURCE mappedResource; pDeviceContext->Map( m_ConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource ); VS_CONSTANT_BUFFER* dataPtr = (VS_CONSTANT_BUFFER*)mappedResource.pData; dataPtr->m_WorldViewProj = worldViewProjection; dataPtr->m_World = m_world; pDeviceContext->Unmap( m_ConstantBuffer, 0 ); // Set the buffer. pDeviceContext->VSSetConstantBuffers( 0, 1, &m_ConstantBuffer ); return S_OK; //You might want to have something real returned, dork } [/code] And finally, the shader: [code] //-------------------------------------------------------------------------------------- // Constant Buffers //-------------------------------------------------------------------------------------- cbuffer cbPerObject //: register( b0 ) { matrix g_mWorldViewProjection : packoffset( c0 ); matrix g_mWorld : packoffset( c4 ); } cbuffer cbPerFrame //: register( b1 ) { float3 g_vLightDir : packoffset( c0 ); float g_fTime : packoffset( c0.w ); float4 g_LightDiffuse : packoffset( c1 ); }; //----------------------------------------------------------------------------------------- // Textures and Samplers //----------------------------------------------------------------------------------------- Texture2D g_txDiffuse : register( t0 ); SamplerState g_samLinear : register( s0 ); //-------------------------------------------------------------------------------------- // shader input/output structure //-------------------------------------------------------------------------------------- struct VS_INPUT { float4 Position : POSITION; // vertex position float4 Color0 : COLOR0; // vertex color }; struct VS_OUTPUT { float4 Position : SV_POSITION; // vertex position float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1) }; //-------------------------------------------------------------------------------------- // This shader computes standard transform and lighting //-------------------------------------------------------------------------------------- VS_OUTPUT RenderSceneVS( VS_INPUT input ) { VS_OUTPUT Output; float3 vNormalWorldSpace; // Transform the position from object space to homogeneous projection space Output.Position = mul( input.Position, g_mWorldViewProjection ); // Calc diffuse color Output.Diffuse = input.Color0; return Output; } //-------------------------------------------------------------------------------------- // This shader outputs the pixel's color by modulating the texture's // color with diffuse material color //-------------------------------------------------------------------------------------- float4 RenderScenePS( VS_OUTPUT In ) : SV_TARGET { return In.Diffuse; } [/code] Well, that ended up being quite the code dump, and I apologize for that. I just feel at my wits end as I've been struggling and googling and trying a billion different things to make it work. But at least I've gotten this far! Thanks to everyone who takes a look, and even if you don't have anything to offer, I hope you all have a great weekend! [/quote] Directx11 requires the transposed matrices passed to it, it doesn't look like you're doing that. So in your shader, change this: [code] // Transform the position from object space to homogeneous projection space Output.Position = mul( input.Position, g_mWorldViewProjection ); [/code] to this [code] // Transform the position from object space to homogeneous projection space Output.Position = mul( input.Position, transpose(g_mWorldViewProjection) ); [/code]
  7. Sphere Seams

    Just so you know, you could also use this: [url="http://www.infinity-universe.com/Infinity/index.php?option=com_smf&Itemid=75&topic=2305.0.html"]http://www.infinity-universe.com/Infinity/index.php?option=com_smf&Itemid=75&topic=2305.0.html[/url] Already tried and tested, in fact, I'm using it on my own planet renderer
  8. How to use D2D with D3D11?

    I for one have seen this thread many, many times. I think I first found it almost a year ago, when I first wanted to render text, albeit when I was much worse coder. Regardless, even though now I'm alot more experienced with directx11 and c++ in general, programmers still shouldn't have to go through all this to render some text. I'd like to see microsoft put some effort into having a fast, robust, not to the point of every format in existence, but with basic antialising, etc, ship with every version of directx. Sure, ID3DXFont was slow, really slow, but it got the job done, with little or no headache. Ever since I found out that this interop would have to be done, I can't seem to force myself to do it, even know, comparatively speaking to even my smaller files, there isn't that much code involved. I think...If I was to do this interop, It would either have to be an easy straight copy and paste, or else I'd really, genuinely rather write my own font renderer. Maybe.... one day I'll render some text in Directx11 For now, anyway, I'll procrastinate as long as possible. EDIT: I just remembered, all the DirectX11 samples I've seen, are really just using ID3DXFont. Says it all, really. For fast prototyping, you don't want to have all this overhead code, even if you only have to write it once.
  9. Tell me if I got this whole HDR thing right?

    [quote name='MJP' timestamp='1312969392' post='4847095'] I made a quick [url="http://mynameismjp.wordpress.com/2011/08/10/average-luminance-compute-shader/"]sample[/url] for my blog that calculates the average luminance using a compute shader reduction, and on my hardware (AMD 6950) it's about twice as fast as GenerateMips for a 1024x1024 luminance map. I'd be interested to see what the results are on other hardware, if you want to try it out. At the very least it's a better starting point than the SDK sample if you're targeting FEATURE_LEVEL_11 hardware. [/quote] Cheers MJP, just what I needed as usual
  10. Tell me if I got this whole HDR thing right?

    [quote name='Quat' timestamp='1312926701' post='4846916'] [quote] In theory, a parallel reduction implemented with shared memory in a compute shader should have significantly less memory reads and writes compared to generating a mip chain. In practice it depends on how well the compute shader is implemented since there are all kinds of subtle performance pitfalls. [/quote] I see. I guess I sort of assumed that since graphics hardware has had auto mipmap chain support for a while it would be quite good at it, and perhaps optimized for it. I'll have to do some comparisons if I get time. [/quote] The whole luminace mip-map thing is the most obvious thing and what I first thought of, I'd be interested to see your results. I'm particularly lazy when it comes down to it I, too looked at the demo when I first started looking at HDR but found the code needed to utilise compute shaders not hard to understand particularly, but certainly more complex.
  11. Updating Shader Files

    Thanks for the help guys.
  12. [quote name='Tordin' timestamp='1312591384' post='4845293'] Hello! I noticed that i got memory leaks from the dx debug device. i have been on this for ever trying to solve it but how hard i try i still get the same ones... Example : D3D11: WARNING: Live Device: Name="unnamed", Addr=0x00286EE8, ExtRef=1 [ STATE_CREATION WARNING #2097297: LIVE_DEVICE ] D3D11: WARNING: Live Texture2D: Name="unnamed", Addr=0x00288E4C, ExtRef=0, IntRef=0 [ STATE_CREATION WARNING #2097235: LIVE_TEXTURE2D ] D3D11: WARNING: Live Query: Name="unnamed", Addr=0x002889EC, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097280: LIVE_QUERY ] D3D11: WARNING: Live Sampler: Name="unnamed", Addr=0x002887B4, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097268: LIVE_SAMPLER ] D3D11: WARNING: Live RasterizerState: Name="unnamed", Addr=0x0028858C, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097277: LIVE_RASTERIZERSTATE ] D3D11: WARNING: Live DepthStencilState: Name="unnamed", Addr=0x00288404, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097274: LIVE_DEPTHSTENCILSTATE ] D3D11: WARNING: Live BlendState: Name="unnamed", Addr=0x0028CDA4, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097271: LIVE_BLENDSTATE ] D3D11: WARNING: Live Context: Name="unnamed", Addr=0x0228006C, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT ] D3D11: WARNING: Live Device Child Summary: Device Addr=0x00286EE8 When i google the warnings i only get post about ppl who havent released it right, but i are more than sure that i have! Any clues Internet? [/quote] Trust me, you haven't. I'm currently working on a planet renderer and everytime I get memory leaks, I find that I, indeed had some obscure situation where they weren't released. Try slowly commenting out code sections until you get a clean exit.
  13. I'm not sure if any of you have run into this problem but I would like to get rid of the problem where I update my shaders in my main project folder but forget to update them in the debug or release folders. Is there anyway to synchronize all changes between those files so that I can modify any file and it will affect the rest? Or will I have to simply only use one set of shader files?
  14. [quote name='MJP' timestamp='1310492347' post='4834406'] The texture resource will have it's own pitch (the number of bytes in a row), which is probably different than the pitch of your source data. This pitch is given to you as the "RowPitch" member of D3D11_MAPPED_SUBRESOURCE. So typically you do something like this: [code] BYTE* mappedData = reinterpret_cast<BYTE*>(mappedResource.pData); for(UINT i = 0; i < height; ++i) { memcpy(mappedData, buffer, rowspan); mappedData += mappedResource.RowPitch; buffer += rowspan; } [/code] [/quote] MJP, I've seen you post this at least twice now besides for me, I'm thinking that maybe msdn should post the information about this under the map method in remarks?
  15. DX11 mipmap dx11

    [quote name='afraidofdark' timestamp='1309807015' post='4831098'] [quote name='MJP' timestamp='1309806264' post='4831086'] If you read the documentation for ID3D11Device::CreateTexture2D carefully, you'll notice that it says this for pInitialData: "Pointer to an array of subresource descriptions; one for each subresource" So if you create a texture with N mip levels, you must pass an array of N D3D11_SUBRESOURCE_DATA's each containing the data for a mip level. The same goes for texture arrays. Note that you're not "creating the memory" for those mip levels, you're just passing in the data to initialize the mip levels with. Calculating the number of mip levels is really easy: [code] UINT GetNumMipLevels(UINT width, UINT height) { UINT numLevels = 1; while(width > 1 && height > 1) { width = max(width / 2, 1); height = max(height / 2, 1); ++numLevels; } return numLevels; } [/code] [/quote] thank you, generating and filling new mipmaps manually is really a burden to me, however I am working on it . The code I post above uses directx library to generate mipmaps automatically, however there is no sign of mipmap at all [b][font="Arial"][size="2"]ID3D11DeviceContext::GenerateMips Method[/size][/font][/b] msdn says: Generate mipmaps for the given shader resource. here is the result of GenerateMips() [img]http://dl.dropbox.com/u/27785963/websitepics/mipmapless.jpg[/img] [/quote] [b]If the base resource was not created with [url="http://msdn.microsoft.com/en-us/library/ff476085(v=vs.85).aspx"]D3D11_BIND_RENDER_TARGET[/url] and [url="http://msdn.microsoft.com/en-us/library/ff476203(v=vs.85).aspx"]D3D11_RESOURCE_MISC_GENERATE_MIPS[/url][/b][b], this call has no effect.[/b] [b]The resource must be created with the [url="http://msdn.microsoft.com/en-us/library/ff476085(v=vs.85).aspx"]bind flags[/url] that specify that the resource is a render target and a shader resource.[/b] [font="'Segoe UI"][size="2"][b] [/b][/size][/font] [font="'Segoe UI"][size="2"]You did take this into account right? Post the updated code. [/size][/font]