Changes

Jump to: navigation, search

GAM670/DPS905 Weekly Schedule 20121

23 bytes removed, 07:54, 17 February 2012
Vertex Shader Programming
==== Vertex Shader Programming ====
* Host
:: APIPlatformSettings.h - Vertex Shader Identification - select between fixed function and programmable pipelines here
<syntaxhighlight lang="cpp">
// shader file data
#define VERTEX_SHADER_ENTRY_POINT "vertexShader"
</syntaxhighlight>
:: APIBase.h - pointers into the shader - APIBase is the base class for the graphics API classes
<syntaxhighlight lang="cpp">
static IDirect3DVertexShader9* vertexShader; // vertex shader
static ID3DXConstantTable* uniformVS; // for vertex shader
</syntaxhighlight>
:: APIBase.cpp - initialize the shader pointers
<syntaxhighlight lang="cpp">
IDirect3DVertexShader9* APIBase::vertexShader = nullptr; // vertex shader
ID3DXConstantTable* APIBase::uniformVS = nullptr; // for vertex shader
</syntaxhighlight>
:: APIDisplay.h - keeps track of the current projection matrix
<syntaxhighlight lang="cpp">
Matrix projection; // projection transformation
</syntaxhighlight>
:: APIDisplay.cpp - setup() - checks the shader version
<syntaxhighlight lang="cpp">
// points to compiled shader code
d3dd->SetVertexShader(vertexShader);
</syntaxhighlight>
:: APIDisplay.cpp - setProjection() - stores the projection matrix
<syntaxhighlight lang="cpp">
this->projection = *((Matrix*)projection);
</syntaxhighlight>
:: APIDisplay.cpp - beginDrawFrame() - copies the view matrix and the camera heading to constant memory
<syntaxhighlight lang="cpp">
Matrix& v = *((Matrix*)view);
uniformVS->SetInt(d3dd, "noLights", 4);
</syntaxhighlight>
:: APIDisplay.cpp - set() - copies the lighting state to constant memory
<syntaxhighlight lang="cpp">
uniformVS->SetBool(d3dd, "lighting", b);
</syntaxhighlight>
:: APIDisplay.cpp - setWorld() - copies the world matrix to constant memory
<syntaxhighlight lang="cpp">
uniformVS->SetMatrix(d3dd, "world", (D3DXMATRIX*)world);
</syntaxhighlight>
:: APIDisplay.cpp - setReflectivity() - copies the reflectivity to constant memory
<syntaxhighlight lang="cpp">
uniformVS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&r.ambient, 4);
uniformVS->SetFloat (d3dd, "material.power", (FLOAT)r.power);
</syntaxhighlight>
:: APIDisplay.cpp - release() - releases constant memory and the vertex shader
<syntaxhighlight lang="cpp">
// release the shader COM objects
}
</syntaxhighlight>
:: APILight.cpp - setup() - copies the light properties to constant memory
<syntaxhighlight lang="cpp">
// Populate the vertex shader constant table
rc = true;
</syntaxhighlight>
:: APILight.cpp - turnOn() - repositions the light and turns it on
<syntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
uniformVS->SetBool(d3dd, constantLightOn, true);
</syntaxhighlight>
:: APILight.cpp - update() - repositions the light
<syntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
uniformVS->SetBool(d3dd, constantLightOn, true);
</syntaxhighlight>
:: APILight.cpp - turnOff() - turns off the light
<syntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
uniformVS->SetBool(d3dd, constantLightOn, false);
</syntaxhighlight>
:: APIGraphic.h - class APIXMesh - processes an X file mesh
<syntaxhighlight lang="cpp">
D3DXCOLOR* ambient;
FLOAT* power;
</syntaxhighlight>
:: APIGraphic.cpp - APIXMesh() - constructor
<syntaxhighlight lang="cpp">
ambient = nullptr;
power = nullptr;
</syntaxhighlight>
:: APIGraphic.cpp - APIXMesh() - copy constructor
<syntaxhighlight lang="cpp">
ambient = nullptr;
power = nullptr;
</syntaxhighlight>
:: APIGraphic.cpp - operator=() = assignment operator
<syntaxhighlight lang="cpp">
if (ambient)
}
</syntaxhighlight>
:: APIGraphic.cpp - setup() -
<syntaxhighlight lang="cpp">
ambient = new D3DXCOLOR[nSubsets];
power[i] = matl[i].MatD3D.Power; // 0 if it shouldn't be shiny
</syntaxhighlight>
:: APIGraphic.cpp - draw()
<syntaxhighlight lang="cpp">
uniformVS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&ambient[i], 4);
uniformVS->SetFloat(d3dd, "material.power", (FLOAT)power[i]);
</syntaxhighlight>
:: APIGraphic.cpp - suspend()
<syntaxhighlight lang="cpp">
if (ambient)
</syntaxhighlight>
* Device
:: vertexShader.hlsl - Constant Memory
<syntaxhighlight lang="cpp">
#define MLIGHTS 4
</syntaxhighlight>
:: vertexShader.hlsl - vertexShader()
<syntaxhighlight lang="cpp">
// vertexShader receives a raw vertex and returns the transformed vertex
}
</syntaxhighlight>
 
==== Fragment Shader ====
* Host

Navigation menu