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

Antigroup

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

104 Neutral

About Antigroup

  • Rank
    Newbie
  1. Thanks. I'm not using D3DX, but I found the option for fxc to use different matrix packing.   I'm not sure how the order of the constant buffers is decided, but I got it to work as I'd expect it to using this code:   context->VSSetConstantBuffers(0, 1, &perFrameConstantBuffer); context->VSSetConstantBuffers(1, 1, &perObjectConstantBuffer); context->VSSetShader(vertexShader, NULL, 0); context->PSSetConstantBuffers(0, 1, &perFrameConstantBuffer); context->PSSetConstantBuffers(1, 1, &perObjectConstantBuffer); context->PSSetShader(pixelShader, NULL, 0); In the shader files, the buffers are the exact same: cbuffer PerFrameConstantBuffer : register(b0) { float4 lightColor; float4 lightAmbientColor; float4 lightDirection; float4 cameraPosition; }; cbuffer PerObjectConstantBuffer : register(b1) { float4x4 world; float4x4 wvp; float4 materialDiffuse; float4 materialSpecular; float4 materialAmbient; };   This works, I'm just not sure why, but I guess I'll figure it out eventually.   Thanks for the help.
  2. I thought they should be able to use the same slots, but something in another post I read while trying to figure this out seemed to imply that you should use different slots, and when I used the same slots for both, I got a warning about the constant buffer being smaller than expected for the pixel shader.   I just tried using slots 0 and 1 on both again, and for some reason the pixel shader has the buffers in the opposite slots from the way the vertex shader has them, but it works not using this code.   context->VSSetConstantBuffers(1, 1, &perFrameConstantBuffer); context->VSSetConstantBuffers(0, 1, &perObjectConstantBuffer); context->VSSetShader(vertexShader, NULL, 0); context->PSSetConstantBuffers(1, 1, &perObjectConstantBuffer); context->PSSetConstantBuffers(0, 1, &perFrameConstantBuffer); context->PSSetShader(pixelShader, NULL, 0);     I'm not sure how the slots for constant buffers are chosen. I thought they would be in the order declared in the shader files. Maybe I'll see how I can use reflection to figure that out rather than trial and error.   While I'm asking about constant buffers, when using xnamath matrices (with XMFLOAT4X4 for members), is there a reason for it to be necessary to transpose them before sending them to the constant buffer? I didn't see this mentioned anywhere, but a while back I found that not transposing them lead to very wrong results visually, but everything works fine when you transpose them. Does anybody know why this would be, or should I just keep doing it?
  3. I'm learning Direct3D 11 and I'm working on getting lighting to work, but for some reason the geometry I'm drawing is showing up black, and I've traced what seems to be the problem to the code that actually updates the constant buffers.   Here's the relevant code:   class LitEffect: public Effect { private: static ID3D11InputLayout *inputLayout; static ID3D11VertexShader *vertexShader; static ID3D11PixelShader *pixelShader; static ID3D11Buffer *perFrameConstantBuffer; static ID3D11Buffer *perObjectConstantBuffer; struct PerFrameConstants { XMFLOAT4 lightColor; XMFLOAT4 lightAmbientColor; XMFLOAT4 lightDirection; XMFLOAT4 cameraPosition; } perFrameCBuffer; bool perFrameChanged; struct PerObjectConstants { XMFLOAT4X4 world; XMFLOAT4X4 wvp; XMFLOAT4 diffuseColor; XMFLOAT4 specularColor; XMFLOAT4 ambientColor; } perObjectCBuffer; bool perObjectChanged; public: LitEffect(void); LitEffect(ID3D11Device * device); ~LitEffect(void); void setWVP(XMFLOAT4X4 wvp); void setWorld(XMFLOAT4X4 world); void setMaterial(XMFLOAT4 diffuse, XMFLOAT4 specular, XMFLOAT4 ambient); void setLight(XMFLOAT4 color, XMFLOAT4 ambient, XMFLOAT4 direction); void setCameraPosition(XMFLOAT4 position); void apply(ID3D11DeviceContext * context); };   Effect is just an abstract class that defines the apply(ID3D11DeviceContext*) method. I'm using two constant buffers based on how often they should be updated.   The problem seems to be happening in the apply() method. void LitEffect::apply(ID3D11DeviceContext * context) { if(perObjectChanged) { D3D11_MAPPED_SUBRESOURCE sr = {0}; //context->Map(perObjectConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sr); ////*((PerObjectConstants*)sr.pData) = perObjectCBuffer; //memcpy(sr.pData, &perObjectCBuffer, sr.RowPitch); //context->Unmap(perObjectConstantBuffer, 0); context->UpdateSubresource(perObjectConstantBuffer, 0, NULL, &perObjectCBuffer, sizeof(PerObjectConstants), sizeof(PerObjectConstants)); perObjectChanged = false; } if(perFrameChanged) { D3D11_MAPPED_SUBRESOURCE sr = {0}; //context->Map(perFrameConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sr); ////*((PerFrameConstants*)sr.pData) = perFrameCBuffer; //memcpy(sr.pData, &perFrameCBuffer, sr.RowPitch); //context->Unmap(perFrameConstantBuffer, 0); context->UpdateSubresource(perFrameConstantBuffer, 0, NULL, &perFrameCBuffer, sizeof(PerFrameConstants), sizeof(PerFrameConstants)); perFrameChanged = false; } ID3D11Buffer *buffers[2]; buffers[0] = perObjectConstantBuffer; buffers[1] = perFrameConstantBuffer; context->IASetInputLayout(inputLayout); context->VSSetConstantBuffers(0, 2, buffers); context->VSSetShader(vertexShader, NULL, 0); context->PSSetConstantBuffers(2, 2, buffers); context->PSSetShader(pixelShader, NULL, 0); }   From using the Visual Studio debugging tools, I've noticed that before calling Map() or UpdateSubresource(), the data in the constant buffer structs is as it should be. Afterwards, however, much of the data is changed to random really small floating-point values, but somehow the world-view-projection matrix is fine, and the geometry appears on screen, but black.   I've done plenty of checking on the shaders and they seem to work correctly, but the correct data never makes it to them.   Is there something I'm not understanding about using constant buffers?