Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is how we create new models
- worldMatrix = DirectX::XMMatrixTranslation(0.0f, -10.0f, 0.0f);
- this->testModelGround->SetWorldMatrix(worldMatrix);
- //Fill the vertex input layout description
- polygonLayout[0].SemanticName = "POSITION";
- polygonLayout[0].SemanticIndex = 0;
- polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
- polygonLayout[0].InputSlot = 0;
- polygonLayout[0].AlignedByteOffset = 0;
- polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
- polygonLayout[0].InstanceDataStepRate = 0;
- polygonLayout[1].SemanticName = "TEXCOORD";
- polygonLayout[1].SemanticIndex = 0;
- polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
- polygonLayout[1].InputSlot = 0;
- polygonLayout[1].AlignedByteOffset = 12;
- polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
- polygonLayout[1].InstanceDataStepRate = 0;
- polygonLayout[2].SemanticName = "NORMAL";
- polygonLayout[2].SemanticIndex = 0;
- polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
- polygonLayout[2].InputSlot = 0;
- polygonLayout[2].AlignedByteOffset = 20;
- polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
- polygonLayout[2].InstanceDataStepRate = 0;
- //Get the number of elements in the layout
- numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);
- //Create the vertex input layout.
- hresult = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &this->layout);
- if (FAILED(hresult)) {
- MessageBox(*hwnd, L"device->CreateInputLayout Deferred", L"Error", MB_OK);
- return false;
- }
- //This is the vertex shader, HLSL
- struct VSInput
- {
- float4 position : POSITION;
- float2 tex : TEXCOORD0;
- float3 normal : NORMAL;
- };
- struct GSInput
- {
- float4 position : SV_POSITION;
- float2 tex : TEXCOORD0;
- float4 worldPos : POSITION;
- float3 normal : NORMAL;
- float3 viewDir : NORMAL1;
- };
- GSInput main(VSInput input)
- {
- GSInput output;
- //Add homogencoordinates for proper matrix multiplication
- input.position.w = 1.0f;
- //Multiply the position with world-, view- and projectionmatrix
- //Save the world-pos of the vertex
- output.position = output.worldPos = mul(input.position, worldMatrix);
- output.position = mul(output.position, viewMatrix);
- output.position = mul(output.position, projectionMatrix);
- //Store the color for output, we do nothing with the values, which is confusing :S
- output.tex = input.tex;
- //Multiply normal with world matrix and normalize
- output.normal = normalize(mul(input.normal, worldMatrix));
- //Get the unit vector from point to camera
- output.viewDir = normalize(cameraPos.xyz - output.worldPos.xyz);
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement