Changes

Jump to: navigation, search

GAM670/DPS905 Weekly Schedule 20121

5,107 bytes added, 18:16, 14 February 2012
This Week
:: APIBase.h - pointers into the shader
<pre>
static IDirect3DVertexShader9* vertexShader; // vertex shader static ID3DXConstantTable* uniformVS; // for vertex shader</pre>:: APIDisplay.h<pre> Matrix projection; // projection transformation</pre>:: APIDisplay.cpp<pre> // points to compiled shader code LPD3DXBUFFER compiledCodeVS = nullptr;  // check for minimum vertex shader version required if (caps.VertexShaderVersion < D3DVS_VERSION(2,0)) error(L"Display::09 Device does not support vertex shader 2_0");</pre><pre> // compile the vertex shader source code else if (FAILED(D3DXCompileShaderFromFile(VERTEX_SHADER_FILE, NULL, NULL, VERTEX_SHADER_ENTRY_POINT, D3DXGetVertexShaderProfile(d3dd), D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION, &compiledCodeVS, NULL, &uniformVS))) { release(); error(L"APIDisplay::13 Unable to compile vertex shader"); } // create the vertex shader object else if (FAILED(d3dd->CreateVertexShader( (DWORD*)compiledCodeVS->GetBufferPointer(), &vertexShader))) { compiledCodeVS->Release(); release(); error(L"APIDisplay::14 Unable to create vertex shader object"); } else { compiledCodeVS->Release();</pre><pre> d3dd->SetVertexShader(vertexShader);</pre><pre> this->projection = *((Matrix*)projection);</pre><pre> Matrix& v = *((Matrix*)view); Matrix viewProjection = v * projection; uniformVS->SetMatrix(d3dd, "viewProjection", (D3DXMATRIX*)&viewProjection); Vector heading(v.m13, v.m23, v.m33); // Required for specular lighting calculations uniformVS->SetFloatArray(d3dd, "heading", (FLOAT*)&heading, 3);</pre><pre> Colour colour(red, green, blue); uniformVS->SetFloatArray(d3dd, "ambient", (FLOAT*)&colour, 4); uniformVS->SetInt(d3dd, "noLights", 4);</pre><pre> uniformVS->SetBool(d3dd, "lighting", b);</pre><pre> uniformVS->SetMatrix(d3dd, "world", (D3DXMATRIX*)world);</pre><pre> uniformVS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&r.ambient, 4); uniformVS->SetFloatArray(d3dd, "material.diffuse", (FLOAT*)&r.diffuse, 4); uniformVS->SetFloatArray(d3dd, "material.specular", (FLOAT*)&r.specular, 4); uniformVS->SetFloat (d3dd, "material.power", (FLOAT)r.power);</pre><pre> // release the shader COM objects if (uniformVS) { uniformVS->Release(); uniformVS = nullptr; } if (vertexShader) { vertexShader->Release(); vertexShader = nullptr; }</pre><pre> // Populate the vertex shader constant table // // Light descriptors within the vertex shader char typ[] = "light[0].type"; char amb[] = "light[0].ambient"; char dif[] = "light[0].diffuse"; char spe[] = "light[0].specular"; char pos[] = "light[0].position"; char dir[] = "light[0].direction"; char spt[] = "light[0].spot"; char att[] = "light[0].attenuation"; char ran[] = "light[0].range"; // // Reset index in light descriptor typ[6] = index + '0'; amb[6] = index + '0'; dif[6] = index + '0'; spe[6] = index + '0'; pos[6] = index + '0'; dir[6] = index + '0'; spt[6] = index + '0'; att[6] = index + '0'; ran[6] = index + '0'; // Populate the vertex shader constant table Vector attenuation(attenuation0, attenuation1, attenuation2); Vector spot(cosf(phi/2), cosf(theta/2), falloff); Vector zero; uniformVS->SetInt(d3dd, typ, type); uniformVS->SetFloatArray(d3dd, amb, (FLOAT*)&ambient, 4); uniformVS->SetFloatArray(d3dd, dif, (FLOAT*)&diffuse, 4); uniformVS->SetFloatArray(d3dd, spe, (FLOAT*)&specular, 4); uniformVS->SetFloatArray(d3dd, pos, (FLOAT*)&zero, 3); uniformVS->SetFloatArray(d3dd, dir, (FLOAT*)&zero, 3); uniformVS->SetFloatArray(d3dd, att, (FLOAT*)&attenuation, 3); uniformVS->SetFloatArray(d3dd, spt, (FLOAT*)&spot, 3); uniformVS->SetFloat(d3dd, ran, range); rc = true;</pre><pre> char constantLightOn[] = "lightOn[0]"; constantLightOn[8] = index + '0'; char pos[] = "light[0].position"; char dir[] = "light[0].direction"; pos[6] = index + '0'; dir[6] = index + '0'; uniformVS->SetFloatArray(d3dd, pos, (FLOAT*)&p, 3); uniformVS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3); uniformVS->SetBool(d3dd, constantLightOn, true);</pre><pre> char constantLightOn[] = "lightOn[0]"; constantLightOn[8] = index + '0'; char pos[] = "light[0].position"; char dir[] = "light[0].direction"; pos[6] = index + '0'; dir[6] = index + '0'; uniformVS->SetFloatArray(d3dd, pos, (FLOAT*)&p, 3); uniformVS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3); uniformVS->SetBool(d3dd, constantLightOn, true);</pre><pre> char constantLightOn[] = "lightOn[0]"; constantLightOn[8] = index + '0'; uniformVS->SetBool(d3dd, constantLightOn, false);</pre><pre></pre><pre></pre><pre>
</pre>
** Device
** Host
** Device
 
=== To Do ===
=== Resources ===

Navigation menu