Advertisement
sebban

Untitled

Apr 18th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //this is how we create new models
  2.     worldMatrix = DirectX::XMMatrixTranslation(0.0f, -10.0f, 0.0f);
  3.     this->testModelGround->SetWorldMatrix(worldMatrix);
  4.  
  5. //Fill the vertex input layout description
  6.     polygonLayout[0].SemanticName = "POSITION";
  7.     polygonLayout[0].SemanticIndex = 0;
  8.     polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
  9.     polygonLayout[0].InputSlot = 0;
  10.     polygonLayout[0].AlignedByteOffset = 0;
  11.     polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  12.     polygonLayout[0].InstanceDataStepRate = 0;
  13.  
  14.     polygonLayout[1].SemanticName = "TEXCOORD";
  15.     polygonLayout[1].SemanticIndex = 0;
  16.     polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
  17.     polygonLayout[1].InputSlot = 0;
  18.     polygonLayout[1].AlignedByteOffset = 12;
  19.     polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  20.     polygonLayout[1].InstanceDataStepRate = 0;
  21.  
  22.     polygonLayout[2].SemanticName = "NORMAL";
  23.     polygonLayout[2].SemanticIndex = 0;
  24.     polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
  25.     polygonLayout[2].InputSlot = 0;
  26.     polygonLayout[2].AlignedByteOffset = 20;
  27.     polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  28.     polygonLayout[2].InstanceDataStepRate = 0;
  29.  
  30.     //Get the number of elements in the layout
  31.     numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);
  32.  
  33.     //Create the vertex input layout.
  34.     hresult = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &this->layout);
  35.     if (FAILED(hresult)) {
  36.         MessageBox(*hwnd, L"device->CreateInputLayout Deferred", L"Error", MB_OK);
  37.         return false;
  38.     }
  39.  
  40. //This is the vertex shader, HLSL
  41.  
  42.  
  43. struct VSInput
  44. {
  45.     float4 position : POSITION;
  46.     float2 tex : TEXCOORD0;
  47.     float3 normal : NORMAL;
  48. };
  49.  
  50. struct GSInput
  51. {
  52.     float4 position : SV_POSITION;
  53.     float2 tex : TEXCOORD0;
  54.     float4 worldPos : POSITION;
  55.     float3 normal : NORMAL;
  56.     float3 viewDir : NORMAL1;
  57. };
  58.  
  59. GSInput main(VSInput input)
  60. {
  61.     GSInput output;
  62.  
  63.     //Add homogencoordinates for proper matrix multiplication
  64.     input.position.w = 1.0f;
  65.  
  66.     //Multiply the position with world-, view- and projectionmatrix
  67.     //Save the world-pos of the vertex
  68.     output.position = output.worldPos = mul(input.position, worldMatrix);
  69.     output.position = mul(output.position, viewMatrix);
  70.     output.position = mul(output.position, projectionMatrix);
  71.  
  72.     //Store the color for output, we do nothing with the values, which is confusing :S
  73.     output.tex = input.tex;
  74.  
  75.     //Multiply normal with world matrix and normalize
  76.     output.normal = normalize(mul(input.normal, worldMatrix));
  77.  
  78.     //Get the unit vector from point to camera
  79.     output.viewDir = normalize(cameraPos.xyz - output.worldPos.xyz);
  80.  
  81.     return output;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement