Jump to content
  • Advertisement

Kamil9132

Member
  • Content Count

    18
  • Joined

  • Last visited

Community Reputation

135 Neutral

About Kamil9132

  • Rank
    Member
  1. Kamil9132

    Light - Dot function

    Thank you for help.
  2. Kamil9132

    Light - Dot function

    Thanks, float4 PosD = float4(0, 1, 0, 0); resolved problem with dot funtion. But i still have problem with this lightning. struct PS_INS_INPUT{ float4 Pos : SV_POSITION; float4 Nor : NORMAL; float2 Tex : TEXCOORD0; float Light_S : LIGHT_S; }; struct VS_INS_INPUT{ float4 Pos : POSITION; float4 Nor : NORMAL; float2 Tex : TEXCOORD0; matrix instancePos : INSTANCEPOS; float Light_S : LIGHT_S; }; PS_INS_INPUT VS_INS (VS_INS_INPUT input){ PS_INS_INPUT output = (PS_INS_INPUT)0; output.Pos = mul (input.Pos, input.instancePos); output.Pos = mul (output.Pos, View); output.Pos = mul (output.Pos, Projection); output.Tex = input.Tex; output.Light_S = input.Light_S; output.Nor = mul (input.Nor, input.instancePos); return output; } float4 PS_INS (PS_INS_INPUT input) : SV_Target{ float4 diffuse = txDiffuse.Sample( samLinear, input.Tex ) * input.Light_S + KolorL; float3 PosD = float3 (0.25f, 0.5f, -1.0f); float3 LighD = float3 (0.5f, 0.5f, 0.5f); float3 LighA = float3 (0.2f, 0.2f, 0.2f); float3 FK; float3 NR = float3 (input.Nor.x, input.Nor.y, input.Nor.z); FK = diffuse * LighA; FK += saturate(dot(PosD, NR) * LighD * diffuse); return float4 (FK, diffuse.a); } Without FK += saturate(dot(PosD, NR) * LighD * diffuse); http://i.imgur.com/RyX6FyK.jpg   With FK += saturate(dot(PosD, NR) * LighD * diffuse); http://i.imgur.com/FPALXy6.jpg   Why do I get someting like second photo? 
  3. I want to add lightning to my application. I tried to do it in this way, but only ambient lightning is working: float4 PS_INS (PS_INS_INPUT input) : SV_Target{ float4 diffuse = txDiffuse.Sample( samLinear, input.Tex ) * input.Light_S + KolorL; float4 PosD = (0, 1, 0, 0); float4 LighD = (0.5f, 0.5f, 0.5f, 0.5f); float4 LighA = (0.2f, 0.2f, 0.2f, 0.2f); float4 FK; FK = diffuse * LighA; FK += saturate(dot(PosD, input.Nor) * LighD * diffuse); return FK; } I tried found what is wrong and I found that dot function doesn't work correct. float4 diffuse = txDiffuse.Sample( samLinear, input.Tex ) * input.Light_S + KolorL; float4 PosD = (0, 1, 0, 0); float4 PosW = (0, 1, 0, 0); float4 LighD = (0.5f, 0.5f, 0.5f, 0.5f); float4 LighA = (0.2f, 0.2f, 0.2f, 0.2f); float4 FK; FK = diffuse * LighA; FK += dot(PosD, PosW) * LighD * diffuse; //LighD * diffuse is not added FK += 1 * LighD * diffuse; //LighD * diffuse is added Dot function should return something like this: Ax*Bx+Ay*By+Az*Bz, so dot (PosD, PosW) should return 1 (0*0+1*1+0*0+0*0). Why doesn't dot return 1?
  4. Kamil9132

    Constant buffer - Memory error

    Should I use this rule (multiple of 16) with vertex buffer?
  5. Kamil9132

    Constant buffer - Memory error

    Thank you for help. I thought that padding is automatically added.
  6. I have constant buffer with 2 variables, when i add one more variable to constant buffer i got this error in output window: First-chance exception at 0x7673C42D in Game.exe: Microsoft C++ exception: _com_error at memory location 0x0021F90C. First-chance exception at 0x7673C42D in Game.exe: Microsoft C++ exception: _com_error at memory location 0x0021F90C. What is wrong in this code?   .fx: Texture2D txDiffuse : register( t0 ); SamplerState samLinear : register( s0 ); cbuffer cbNeverChanges : register( b0 ) { matrix View; }; cbuffer cbChangeOnResize : register( b1 ) { matrix Projection; }; cbuffer cbChangesEveryFrame : register( b2 ) { matrix World; bool cPrzez; int kolorP; }; cbuffer cbPixelShader : register( b3 ) { float4 kolorS; float4 kolorL; int Trans; };   main.cpp: struct SimpleVertex{ XMFLOAT3 Pos; XMFLOAT2 Tex; }; struct CBNeverChanges{ XMMATRIX mView; }; struct CBChangeOnResize{ XMMATRIX mProjection; }; struct CBChangesEveryFrame{ XMMATRIX mWorld; int cPrzez; int cKolorP; }; struct CBPixelShader{ XMFLOAT4 kolorS; XMFLOAT4 kolorL; int Trans; }; struct INS{ XMFLOAT4X4 IN_N; float Light_Simple; }; bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(CBNeverChanges); bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = 0; d3d11Device->CreateBuffer( &bd, NULL, &g_pCBNeverChanges ); bd.ByteWidth = sizeof(CBChangeOnResize); d3d11Device->CreateBuffer( &bd, NULL, &g_pCBChangeOnResize ); bd.ByteWidth = sizeof(CBPixelShader); d3d11Device->CreateBuffer( &bd, NULL, &g_pCBPixelShader ); bd.ByteWidth = sizeof(CBChangesEveryFrame); d3d11Device->CreateBuffer( &bd, NULL, &g_pCBChangesEveryFrame ); I got error on this line: d3d11Device->CreateBuffer( &bd, NULL, &g_pCBPixelShader ); If i delete int Trans from main.cpp and .fx, program will work properly.
  7. Kamil9132

    Updating dynamic vertex buffer

    @HappyCoder I got unhandled exception at...   I changed D3D11_MAP_WRITE to D3D11_MAP_WRITE_DISCARD and now it's working properly. Thank you for help.
  8. Hi, I want to update dynamic vertex buffer. I tried update this buffer in 2 ways, but in first i got error and in second buffer has not changed. 1. D3D11_MAPPED_SUBRESOURCE VertexMap; ZeroMemory (&VertexMap, sizeof(D3D11_MAPPED_SUBRESOURCE)); d3d11DevCon->Map (WorldDX->VertexBuff[K], 0, D3D11_MAP_WRITE, 0, &VertexMap); memcpy (VertexMap.pData, &WorldDX->WM[WorldDX->wK][K][0], sizeof (INS) * WorldDX->WM[WorldDX->wK][K].size()); //error d3d11DevCon->Unmap(WorldDX->VertexBuff[K], 0); 2. d3d11DevCon->Map (WorldDX->VertexBuff[K], 0, D3D11_MAP_WRITE, 0, &VertexMap); VertexMap.pData = &WorldDX->WM[WorldDX->wK][K][0]; d3d11DevCon->Unmap(WorldDX->VertexBuff[K], 0); I can destroy and create this buffer but it takes too much time: D3D11_BUFFER_DESC bd; D3D11_SUBRESOURCE_DATA InitData; WorldDX->VertexSize[K] = WorldDX->WM[WorldDX->wK][K].size(); if (WorldDX->VertexBuff[K]){ WorldDX->VertexBuff[K]->Release(); WorldDX->VertexBuff[K] = NULL; } ZeroMemory (&bd, sizeof(bd)); ZeroMemory (&InitData, sizeof(InitData)); bd.Usage = D3D11_USAGE_DYNAMIC; bd.ByteWidth = sizeof (INS) * WorldDX->VertexSize[K]; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; InitData.pSysMem = &WorldDX->WM[WorldDX->wK][K][0]; d3d11Device->CreateBuffer (&bd, &InitData, &WorldDX->VertexBuff[K]);
  9. Kamil9132

    Releasing vertex buffer

    @Buckeye VertexReady is array of bools, it is initialize with 0 before creating this buffer.   I forgot set this buffer as NULL after Release. Now it's working.   Thanks for help.
  10. I have function in which i create vertex buffers. I use this function about 10-15sec. for (size_t TB_01 = 0; TB_01 < ltextur1D + ltextur2D + ltextur3D + lModeli + lModeliV + lModeliP + lModeliPV; TB_01++){ InV.resize (WorldDX->W[wk][TB_01].size() + WorldDX->W[wt][TB_01].size()); for (size_t TB_02 = 0; TB_02 < WorldDX->W[wk][TB_01].size(); TB_02++) InV[TB_02 ] = WorldDX->W[wk][TB_01][TB_02].M; for (size_t TB_02 = 0; TB_02 < WorldDX->W[wt][TB_01].size(); TB_02++) InV[TB_02 + WorldDX->W[wk][TB_01].size() ] = WorldDX->W[wt][TB_01][TB_02].M; WorldDX->VertexSize[TB_01] = InV.size(); // if (WorldDX->VertexReady[TB_01]) WorldDX->VertexBuff[TB_01]->Release(); ZeroMemory (&bd, sizeof(bd)); ZeroMemory (&InitData, sizeof(InitData)); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof (INS) * WorldDX->VertexSize[TB_01]; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; InitData.pSysMem = &InV[0]; d3d11Device->CreateBuffer (&bd, &InitData, &WorldDX->VertexBuff[TB_01]); InV.clear(); WorldDX->VertexReady[TB_01] = 1; } Should i release buffer before i create this buffer again? I tried release buffer in this way but i got error: if (WorldDX->VertexReady[TB_01]) WorldDX->VertexBuff[TB_01]->Release();
  11. Kamil9132

    Directx 11 instancing

    I found what was wrong. I had something like this in code: ID3D11Buffer* BTV[2] = {Buffer1, Buffer2}; Then i created Buffer1 and Buffer2.   Now i create buffers first, then i create ID3D11Buffer* BTV[2].
  12. Kamil9132

    Directx 11 instancing

    I removed row_major, but nothing has changed.
  13. Kamil9132

    Directx 11 instancing

    I am not sure, but i think that for every instance instancePos is changing and World is constant, World is only changing when i update resource using `UpdateSubresource` in main code.
  14. Kamil9132

    Directx 11 instancing

    matrix World is used in drawing without instancing row_major matrix instancePos is used in drawing with instancing
  • 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!