Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
HLSL-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
struct VS_INPUT { float4 Pos : POSITION; float4 Color : COLOR; }; // ... PS_INPUT VS( VS_INPUT input ) { PS_INPUT output = (PS_INPUT)0; // Dieser Code funktioniert nicht. Sind die M vielleicht NULL ? // Keine Ahnung wie ich HLSL-Shader "debuggen" soll :( /*output.Pos = mul( input.Pos, World ); output.Pos = mul( output.Pos, View ); output.Pos = mul( output.Pos, Projection );*/ // Funktioniert wunderbar output.Pos = input.Pos; output.Color = input.Color; return output; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/********** Codeteil: DX11 initialisieren. Mit Sorgfalt debuggt. Läuft wie eine eins **********/ // Initialisierungen usw. // NUN DEN BUFFER FÜR DEN SHADER ERSTELLEN! // Wie gehabt... D3DXMatrixIdentity(&g_World); D3DXMatrixLookAtLH(&g_View, &D3DXVECTOR3(0.0f, 0.0f, 5.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH( &g_Projection , (0.78539816f), (float)(SCREEN_WIDTH/SCREEN_HEIGHT), 0.01f, 100.0f); // Buffer erstellen D3D11_MAPPED_SUBRESOURCE mappedResource; ConstantBuffer* dataPtr; unsigned int bufferNumber; // (Das ist eine vorrübergehende Lösung) D3DXMATRIX local_world, local_view, local_projection; D3DXMatrixTranspose(&g_World, &local_world); D3DXMatrixTranspose(&g_View, &local_view); D3DXMatrixTranspose(&g_Projection, &local_projection); // Lock the constant buffer so it can be written to. hr = devcon->Map(g_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); // Get a pointer to the data in the constant buffer. dataPtr = (ConstantBuffer*)mappedResource.pData; dataPtr->mProjection = local_projection; dataPtr->mView = local_view; dataPtr->mWorld = local_world; // Unlock the constant buffer. devcon->Unmap(g_pConstantBuffer, 0); // Set the position of the constant buffer in the vertex shader. bufferNumber = 0; // Finanly set the constant buffer in the vertex shader with the updated values. devcon->VSSetConstantBuffers(bufferNumber, 1, &g_pConstantBuffer); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f)); // select which vertex buffer to display UINT stride = sizeof(VERTEX); UINT offset = 0; devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset); // Dreiecksliste devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); if ( nullptr != g_pConstantBuffer) { ConstantBuffer cb; // Alles neu! D3DXMatrixIdentity(&g_World); D3DXMatrixLookAtLH(&g_View, &D3DXVECTOR3(0.0f, 0.0f, 0.5f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH( &g_Projection , ((float)D3DX_PI/4.0f), (float)(SCREEN_WIDTH/SCREEN_HEIGHT), 0.01f, 100.0f); D3DXMatrixTranspose( &cb.mWorld, &g_World); D3DXMatrixTranspose( &cb.mView , &g_View ); D3DXMatrixTranspose( &cb.mProjection, &g_Projection ); devcon->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 ); devcon->VSSetConstantBuffers(0, 1, &g_pConstantBuffer); devcon->VSSetShader(pVS, 0, 0); devcon->PSSetShader(pPS, 0, 0); } devcon->Draw(3, 0); swapchain->Present(0, 0); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Fireball« (04.03.2013, 21:27)
wenn du den Constant Buffer veränderst, dann musst du mit Map und Unmap arbeiten.
wenn du den Constant Buffer veränderst, dann musst du mit Map und Unmap arbeiten.
Niemand wird dazu gezwungen!
wenn du den Constant Buffer veränderst, dann musst du mit Map und Unmap arbeiten.
Niemand wird dazu gezwungen!
Aber ist es nicht sinnvoller? Ich rufe immer eine SetShaderParameter Methode auf, bevor ist das Objekt dann anzeige.
Werbeanzeige