haansn08

Members
  • Content count

    23
  • Joined

  • Last visited

Community Reputation

172 Neutral

About haansn08

  • Rank
    Member
  1.   Yes - and it's not just valid it's also good practice: http://www.fatagnus.com/program-to-an-interface-not-an-implementation/   And you can type var (C#) or auto (C++) or whatever if you want the compliler to recognize the type automatically. (But it disguises the type e.g. if the return value of a function is not clear.)
  2. I just found out I didn't set an input layout! But it still doesn't work: When calling ID3D11SwapChain::Present the screen goes black and I get a strange error message, later when I clear the back buffer...   This seems to work: D3DX11_PASS_DESC passDesc; _FXColor->GetTechniqueByIndex(0)->GetPassByIndex(0)->GetDesc(&passDesc); D3D11_INPUT_ELEMENT_DESC layout[2]; VertexFormats::VertexPositionColor::GetDesc(layout); if (FAILED(_dev->CreateInputLayout(layout, 2, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &_layout))) throw "Failed to create input layout."; But of course I need the input layout...   EDIT: I found  the problem - it seems like my graphics card doesn't support the specified shader version... (But the Effect version needs to be 5.0... ?)
  3. colorTechDesc.Passes is one - and Apply return S_OK. :\
  4. Hello there, I'm trying to learn how to use the effect framework and tried to recreate my "grid scene" (a floor grid with colored axis), but this time with effects instead of own compiled shaders But I'm having a couple of problems with it not least, because the framework seems to remove the shader from the device context: (This can't work...)   My effect file: cbuffer cbPerObject : register(b0) { float4x4 worldViewProj; }; struct VertexIn { float3 pos : POSITION; float4 col : COLOR; }; struct VertexOut { float4 pos : SV_POSITION; float4 col : COLOR; }; VertexOut VS (VertexIn input) { VertexOut vout; vout.pos = float4 (input.pos, 1.0f); vout.pos = mul(vout.pos, worldViewProj); vout.col = input.col; return vout; } float4 PS(VertexOut input) : SV_TARGET { return input.col; } RasterizerState SolidCull { FillMode = Solid; CullMode = Back; }; technique11 ColorTech { pass P0 { SetVertexShader(CompileShader(vs_5_0, VS())); SetPixelShader (CompileShader(ps_5_0, PS())); SetRasterizerState (SolidCull); } } Loading the effect: ID3D10Blob *fx; ID3D10Blob *error; if (FAILED(D3DX11CompileFromFileA("Color.fx", nullptr, nullptr, 0, "fx_5_0", D3D10_SHADER_DEBUG | D3D10_SHADER_SKIP_OPTIMIZATION, 0, 0, &fx, &error, 0))) { throw (char*)error->GetBufferPointer(); } if (FAILED(D3DX11CreateEffectFromMemory(fx->GetBufferPointer(), fx->GetBufferSize(), 0, _dev, &_FXColor))) throw "Can't create effect."; fx->Release(); Rendering Code: XMMATRIX gridMatrix = _camera.GetCameraMatrix() * _proj; _FXColor_WorldViewProj->SetMatrix((float*)(&gridMatrix)); auto colorTech = _FXColor->GetTechniqueByName("ColorTech"); D3DX11_TECHNIQUE_DESC colorTechDesc; colorTech->GetDesc(&colorTechDesc); for (UINT pass = 0; pass < colorTechDesc.Passes; pass++) { colorTech->GetPassByIndex(pass)->Apply(0, _devcon); _grid->Render(); } The Apply function seems to set the shaders to zero.
  5. Hello there, I'm currently trying to implement a simple light shader, but I have a couple of problems with it. The diffuse lightning works fine, but the specular highlight seems not very correct. This is my pixel shader: struct VertexOut { float4 posH : SV_POSITION; float3 posW : POSITION; float3 normal : NORMAL; }; cbuffer cbPerObject : register (b0) { float3 eyePos; float3 lightDirection; float4 lightColor; float lightStrength; float4 ambient; float4 diffuse; float4 specular; float specular_power; }; float4 main (VertexOut input) : SV_TARGET { //Calculate diffuse light float3 light0 = normalize(lightDirection); float _diff_fac = max(mul(light0, input.normal), 0); float4 _diff = _diff_fac * (diffuse * lightColor) * lightStrength; //Ambient light float4 _ambient = ambient; //Specular light //Calculate the angle float4 _spec = float4(0.0f,0.0f,0.0f,0.0f); [flatten] if (_diff_fac > 0.0f) { float3 toEye = normalize(input.posW - eyePos); float3 reflection = normalize(reflect(-light0, input.normal)); float _spec_fac = pow(max(dot(reflection, toEye), 0), specular_power); _spec = _spec_fac * specular; } return _diff + _ambient + _spec; } And my vertex shader: cbuffer cbPerObject : register (b0) { float4x4 world; float4x4 worldViewProj; float4x4 worldInvTrans; }; struct VertexIn { float3 pos : POSITION; float3 normal : NORMAL; }; struct VertexOut { float4 posH : SV_POSITION; float3 posW : POSITION; float3 normal : NORMAL; }; VertexOut main (VertexIn input) { VertexOut output; //Transform vertex output.posH = mul(float4(input.pos,1.0f), worldViewProj); output.posW = mul(input.pos, world); //Transform normal output.normal = mul (input.normal, (float3x3)worldInvTrans); return output; } I checked the constant buffer of the pixel shader and everything seems to be right... Here are some screenshots (I increase the specular_power variable linear with the time)   As you can see, the specular highlight dismishes over time and is replaced by the diffuse lightning - but actually it should shrink to a point.   Please tell me if you need more source code.
  6. Indices of an obj file

    I found the problem(s): 1: I only read 2 vertices instead of 3 per triangle //Only triangles are supported! if (triangle_data.size() != 4) //1st element is a empty string! throw invalid_argument("OBJ file contains primitive data other than Triangle Lists. (NGON, Lines, ...)"); //Read the vertices //for (int iVertex = 0; iVertex < 3; iVertex++) //<---- Wrong for (int iVertex = 1; iVertex < 4; iVertex++) //Process each vertex 2: I skip every secound triangle, since I jump to the next line after processing one triangle, but since I use getline the '\n' char is already read. if (data_type == "f") //current line contains a triangle specification { ReadFace(file, positions, normals, vertices, indices); continue; //ReadFace does already read the \n char! } //Simply ignore other commands for now #undef max //Skip the line file.ignore(numeric_limits<streamsize>::max(), '\n'); #define max
  7. GDC 2013: Interview with Kate Craig

  8. Hello there, I'm trying to load an .obj wavefront file (for simplicity reasons - later I want to read other - better - fromats). The models are exported with Blender 2.68a. I assume that the vertices are read correctly - the problem is rather in the index generating part as this picture suggests:   (The left model was recreated from the Input Assembler input)   The main problem with loading the indices is similar to this: http://www.gamedev.net/topic/589494-opengl-es-20-how-to-obtain-indices-from-a-wavefront-obj-file/#entry4741209   My solution to the problem is to look in each face definition if the vertex already exists and then add the corresponding index. Otherwise the new vertex is added to a list and then add a the index (wich is the size of the vertex array...) //Split the line with delim ' ' (Space) to gather the data of each vertex vector<string> triangle_data = Split(line,' '); //Vetor of vertex data //Only triangles are supported! if (triangle_data.size() != 4) //1st element is a empty string! throw invalid_argument("OBJ file contains primitive data other than Triangle Lists. (NGON, L ines, ...)"); //Read the vertices for (int iVertex = 0; iVertex < 3; iVertex++) //Process each vertex { /* one vertex data looks like this: 5/8/9 or 6//4 */ string vertex_data = triangle_data.at(iVertex); if (vertex_data == "") continue; //Split vertex_data with delimeter '/' to gather indices of position and normal vector<string> vertex_index_data = Split(vertex_data); //Get Position data UINT position_index = stoi(vertex_index_data.at(0)) - 1; UINT normal_index = stoi(vertex_index_data.at(2)) - 1; if (position_index >= position_data.size() || normal_index >= normal_data.size()) continue; //We should never get here XMFLOAT3 pos = position_data.at (position_index); XMFLOAT3 nrm = normal_data.at (normal_index); //Assemble the vertex VertexFormats::VertexPositionNormal vertex; vertex.position = pos; vertex.normal = nrm; //Update the vertex and index vectors //Check if the vertex already exists auto vertex_pos = find(vertices.begin(), vertices.end(), vertex); if (vertex_pos == vertices.end()) { //The vertex does not exist - add it to the vertex list vertices.push_back(vertex); //Update the index list indices.push_back(vertices.size() - 1); } else { //the vertex already exists - add the corresponding index indices.push_back(vertex_pos - vertices.begin()); } } //for each vertex (The whole code of the class is attached.)
  9. OK, it works. Altough I really have no clue why... 
  10. Hello there, I'm trying to build a class that is responsible for loading and managing a vertex shader. The idea is to have a separate class for managing the constant buffer (the data a vertex shader needs.) This class looks like this:   dxman_cbuffer.h #pragma once #include "dxman_common.h" #include <D3D11.h> template <typename Buffer> class ConstantBuffer { private: ID3D11Buffer *_buffer; const Buffer *_content; public: HRESULT Init(ID3D11Device* dev, Buffer* initialData); void Exit(); ID3D11Buffer* GetBuffer() const; HRESULT SetBufferData (ID3D11DeviceContext* devcon, Buffer *content); const Buffer* GetBufferData() const; }; The problem occours in this class:   ColorShader.h #pragma once #include "common.h" #include "dxman_shader.h" #include "dxman_cbuffer.h" class VSColor : public IVertexShader { private: struct SMatrixBuffer { XMMATRIX worldViewProj; }; ConstantBuffer<SMatrixBuffer> _cbPerObject; public: virtual HRESULT Init (ID3D11Device *dev); //Loads the shader & creates the constant buffer virtual void Exit(); //Releases all resources virtual void Activate (ID3D11DeviceContext* devcon); //Sets the shader and the constant buffer to the Vertex Shader stage virtual HRESULT UpdateMatrixBuffer (ID3D11DeviceContext *devcon, XMMATRIX &worldViewProj); //Updates the buffer data }; Since the template class ConstantBuffer<SMatrixBuffer> is never declared, the linker can't find any symbols. The problem is that I can't just write ConstantBuffer<SMatrixBuffer> in dxman_cbuffer.cpp (where the ConstantBuffer class is) since SMatrixBuffer is declared as private in another class. (And I want to keep both files separated!)
  11. Hm. Probably the bug is somewhere else. I have attached the source code of the whole project now.
  12. Yes. This code creates the viewport: //Set the viewport D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(viewport)); viewport.Width = float(width); viewport.Height = float(height); viewport.MaxDepth = 1.0f; _devcon->RSSetViewports(1, &viewport); And my vertex shader code: cbuffer perObject { float4x4 worldViewProj; }; struct VertexOut { float4 pos : SV_POSITION; float4 col : COLOR; }; VertexOut main( float4 pos : POSITION) { VertexOut ret; ret.pos = mul(pos, worldViewProj); ret.col = float4(1.0f,1.0f,1.0f,1.0f); return ret; }
  13. Hm changing the VertexOut structure to: struct VertexOut { float4 pos : SV_POSITION; float4 col : COLOR; }; didn't help much. Returning any color in the pixel shader neither did.   But I'm pretty sure that the matrices are correct since the image under "Vertex Shader" looks like this:  
  14. Hello there, I'm trying to draw some "terrain" (when you can call a displaced grid without color a terrain ^^), and (again) nothing is shown on the screen. With the graphics debugging tools of VS2012 I found out that there is no pixel shader stage similiar to this problem: http://msdn.microsoft.com/en-us/library/vstudio/jj191650.aspx   Altough I do set a pixel shader:   The code of my pixel shader: struct VertexOut { float4 pos : POSITION; float4 col : COLOR; }; float4 main(VertexOut input) : SV_TARGET { return input.col; }