Changes

Jump to: navigation, search

GAM670/DPS905 Weekly Schedule 20121

1,715 bytes added, 10:31, 15 February 2012
This Week
** Host
:: APIPlatformSettings.h - Vertex Shader Identification - select between fixed function and programmable pipelines here
<presyntaxhighlight lang="cpp">
// shader file data
#define VERTEX_SHADER_FILE L"vertexShader.hlsl"
#define VERTEX_SHADER_ENTRY_POINT "vertexShader"
</presyntaxhighlight>
:: APIBase.h - pointers into the shader - APIBase is the base class for the graphics API classes
<presyntaxhighlight lang="cpp">
static IDirect3DVertexShader9* vertexShader; // vertex shader
static ID3DXConstantTable* uniformVS; // for vertex shader
</presyntaxhighlight>
:: APIBase.cpp - initialize the shader pointers
<presyntaxhighlight lang="cpp">
IDirect3DVertexShader9* APIBase::vertexShader = nullptr; // vertex shader
ID3DXConstantTable* APIBase::uniformVS = nullptr; // for vertex shader
</presyntaxhighlight>
:: APIDisplay.h - keeps track of the current projection matrix
<presyntaxhighlight lang="cpp">
Matrix projection; // projection transformation
</presyntaxhighlight>
:: APIDisplay.cpp - setup() - checks the shader version
<presyntaxhighlight lang="cpp">
// points to compiled shader code
LPD3DXBUFFER compiledCodeVS = nullptr;
if (caps.VertexShaderVersion < D3DVS_VERSION(2,0))
error(L"APIDisplay::09 Device does not support vertex shader 2_0");
</presyntaxhighlight>
compiles the shader hlsl code, retrieves address of constant memory and vertex shader
<presyntaxhighlight lang="cpp">
// compile the vertex shader source code
else if (FAILED(D3DXCompileShaderFromFile(VERTEX_SHADER_FILE, NULL,
else {
compiledCodeVS->Release();
</presyntaxhighlight>
sets the current vertex shader
<presyntaxhighlight lang="cpp">
d3dd->SetVertexShader(vertexShader);
</presyntaxhighlight>
:: APIDisplay.cpp - setProjection() - stores the projection matrix
<presyntaxhighlight lang="cpp">
this->projection = *((Matrix*)projection);
</presyntaxhighlight>
:: APIDisplay.cpp - beginDrawFrame() - copies the view matrix and the camera heading to constant memory
<presyntaxhighlight lang="cpp">
Matrix& v = *((Matrix*)view);
Matrix viewProjection = v * projection;
// Required for specular lighting calculations
uniformVS->SetFloatArray(d3dd, "heading", (FLOAT*)&heading, 3);
</presyntaxhighlight><presyntaxhighlight lang="cpp">
Colour colour(red, green, blue);
uniformVS->SetFloatArray(d3dd, "ambient", (FLOAT*)&colour, 4);
uniformVS->SetInt(d3dd, "noLights", 4);
</presyntaxhighlight>
:: APIDisplay.cpp - set() - copies the lighting state to constant memory
<presyntaxhighlight lang="cpp">
uniformVS->SetBool(d3dd, "lighting", b);
</presyntaxhighlight>
:: APIDisplay.cpp - setWorld() - copies the world matrix to constant memory
<presyntaxhighlight lang="cpp">
uniformVS->SetMatrix(d3dd, "world", (D3DXMATRIX*)world);
</presyntaxhighlight>
:: APIDisplay.cpp - setReflectivity() - copies the reflectivity to constant memory
<presyntaxhighlight lang="cpp">
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);
</presyntaxhighlight>
:: APIDisplay.cpp - release() - releases constant memory and the vertex shader
<presyntaxhighlight lang="cpp">
// release the shader COM objects
if (uniformVS) {
vertexShader = nullptr;
}
</presyntaxhighlight>
:: APILight.cpp - setup() - copies the light properties to constant memory
<presyntaxhighlight lang="cpp">
// Populate the vertex shader constant table
//
uniformVS->SetFloat(d3dd, ran, range);
rc = true;
</presyntaxhighlight>
:: APILight.cpp - turnOn() - repositions the light and turns it on
<presyntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
constantLightOn[8] = index + '0';
uniformVS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3);
uniformVS->SetBool(d3dd, constantLightOn, true);
</presyntaxhighlight>
:: APILight.cpp - update() - repositions the light
<presyntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
constantLightOn[8] = index + '0';
uniformVS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3);
uniformVS->SetBool(d3dd, constantLightOn, true);
</presyntaxhighlight>
:: APILight.cpp - turnOff() - turns off the light
<presyntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
constantLightOn[8] = index + '0';
uniformVS->SetBool(d3dd, constantLightOn, false);
</presyntaxhighlight>
:: APIGraphic.h - class APIXMesh - processes an X file mesh
<presyntaxhighlight lang="cpp">
D3DXCOLOR* ambient;
D3DXCOLOR* diffuse;
D3DXCOLOR* specular;
FLOAT* power;
</presyntaxhighlight>
:: APIGraphic.cpp - APIXMesh() - constructor
<presyntaxhighlight lang="cpp">
ambient = nullptr;
diffuse = nullptr;
specular = nullptr;
power = nullptr;
</presyntaxhighlight>
:: APIGraphic.cpp - APIXMesh() - copy constructor
<presyntaxhighlight lang="cpp">
ambient = nullptr;
diffuse = nullptr;
specular = nullptr;
power = nullptr;
</presyntaxhighlight>
:: APIGraphic.cpp - operator=() = assignment operator
<presyntaxhighlight lang="cpp">
if (ambient)
delete [] ambient;
specular = new D3DXCOLOR[src.nSubsets];
power = new FLOAT[src.nSubsets];
</presyntaxhighlight><presyntaxhighlight lang="cpp">
for (unsigned i = 0; i < nSubsets; i++) {
ambient[i] = src.ambient[i];
power[i] = src.power[i];
}
</presyntaxhighlight>
:: APIGraphic.cpp - setup() -
<presyntaxhighlight lang="cpp">
ambient = new D3DXCOLOR[nSubsets];
diffuse = new D3DXCOLOR[nSubsets];
specular = new D3DXCOLOR[nSubsets];
power = new FLOAT[nSubsets];
</presyntaxhighlight><presyntaxhighlight lang="cpp">
ambient[i].r = matl[i].MatD3D.Diffuse.r * 0.7f;
ambient[i].g = matl[i].MatD3D.Diffuse.g * 0.7f;
specular[i] = matl[i].MatD3D.Specular; // shine from lights
power[i] = matl[i].MatD3D.Power; // 0 if it shouldn't be shiny
</presyntaxhighlight>
:: APIGraphic.cpp - draw()
<presyntaxhighlight lang="cpp">
uniformVS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&ambient[i], 4);
uniformVS->SetFloatArray(d3dd, "material.diffuse", (FLOAT*)&diffuse[i], 4);
uniformVS->SetFloatArray(d3dd, "material.specular", (FLOAT*)&specular[i], 4);
uniformVS->SetFloat(d3dd, "material.power", (FLOAT)power[i]);
</presyntaxhighlight>
:: APIGraphic.cpp - suspend()
<presyntaxhighlight lang="cpp">
if (ambient)
delete [] ambient;
if (power)
delete [] power;
</presyntaxhighlight>
** Device
:: vertexShader.hlsl - Constant Memory
<presyntaxhighlight lang="cpp">
#define MLIGHTS 4
#define POINT_LIGHT 0
bool litVertex; // omit lighting calculations - already lit
</presyntaxhighlight>
:: vertexShader.hlsl - vertexShader()
<presyntaxhighlight lang="cpp">
// vertexShader receives a raw vertex and returns the transformed vertex
//
return transformed;
}
</presyntaxhighlight>
* Fragment Shader
:* Host
:: APIPlatformSettings.h
<presyntaxhighlight lang="cpp">
#define FRAGMENT_SHADER_FILE L"fragmentShader.hlsl"
#define FRAGMENT_SHADER_ENTRY_POINT "fragmentShader"
</presyntaxhighlight>
:: APIBase.h
<presyntaxhighlight lang="cpp">
// Fragment Shader Support
static IDirect3DPixelShader9* fragmentShader; // fragment shader
static ID3DXConstantTable* uniformFS; // for fragment shader
</presyntaxhighlight>
:: APIBase.cpp
<presyntaxhighlight lang="cpp">
IDirect3DPixelShader9* APIBase::fragmentShader = nullptr; // fragment shader
ID3DXConstantTable* APIBase::uniformFS = nullptr; // for fragment shader
</presyntaxhighlight>
:: APIDisplay.cpp - setup()
<presyntaxhighlight lang="cpp">
LPD3DXBUFFER compiledCodeFS = nullptr;
else if (caps.PixelShaderVersion < D3DPS_VERSION(3,0))
error(L"Display::10 Device does not support pixel shader 3_0");
</presyntaxhighlight><presyntaxhighlight lang="cpp">
// compile the fragment shader source code
else if (FAILED(D3DXCompileShaderFromFile(FRAGMENT_SHADER_FILE, NULL,
else {
compiledCodeFS->Release();
</presyntaxhighlight><presyntaxhighlight lang="cpp">
d3dd->SetPixelShader(fragmentShader);
</presyntaxhighlight>
:: APIDisplay.cpp - beginDrawFrame()
<presyntaxhighlight lang="cpp">
Colour colour(red, green, blue);
uniformFS->SetFloatArray(d3dd, "ambient", (FLOAT*)&colour, 4);
uniformFS->SetInt(d3dd, "noLights", 4);
</presyntaxhighlight>
:: APIDisplay.cpp - set()
<presyntaxhighlight lang="cpp">
uniformFS->SetBool(d3dd, "lighting", b);
</presyntaxhighlight>
:: APIDisplay.cpp - setReflectivity()
<presyntaxhighlight lang="cpp">
uniformFS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&r.ambient, 4);
uniformFS->SetFloatArray(d3dd, "material.diffuse", (FLOAT*)&r.diffuse, 4);
uniformFS->SetFloatArray(d3dd, "material.specular", (FLOAT*)&r.specular, 4);
uniformFS->SetFloat (d3dd, "material.power", (FLOAT)r.power);
</presyntaxhighlight>
:: APIDisplay.cpp - release()
<presyntaxhighlight lang="cpp">
}
if (uniformFS) {
fragmentShader = nullptr;
}
</presyntaxhighlight>
:: APIGraphic.cpp - APIXMesh::draw()
<presyntaxhighlight lang="cpp">
uniformFS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&ambient[i], 4);
uniformFS->SetFloatArray(d3dd, "material.diffuse", (FLOAT*)&diffuse[i], 4);
uniformFS->SetFloatArray(d3dd, "material.specular", (FLOAT*)&specular[i], 4);
uniformFS->SetFloat(d3dd, "material.power", (FLOAT)power[i]);
</presyntaxhighlight>
:: APILight.cpp - setup()
<presyntaxhighlight lang="cpp">
uniformFS->SetInt(d3dd, typ, type);
uniformFS->SetFloatArray(d3dd, amb, (FLOAT*)&ambient, 4);
uniformFS->SetFloatArray(d3dd, spt, (FLOAT*)&spot, 3);
uniformFS->SetFloat(d3dd, ran, range);
</presyntaxhighlight>
:: APILight.cpp - turnOn()
<presyntaxhighlight lang="cpp">
uniformFS->SetFloatArray(d3dd, pos, (FLOAT*)&p, 3);
uniformFS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3);
uniformFS->SetBool(d3dd, constantLightOn, true);
</presyntaxhighlight><presyntaxhighlight lang="cpp">
uniformFS->SetFloatArray(d3dd, pos, (FLOAT*)&p, 3);
uniformFS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3);
uniformFS->SetBool(d3dd, constantLightOn, true);
</presyntaxhighlight>
:: APILight.cpp - update()
<presyntaxhighlight lang="cpp">
uniformFS->SetFloatArray(d3dd, pos, (FLOAT*)&p, 3);
uniformFS->SetFloatArray(d3dd, dir, (FLOAT*)&o, 3);
uniformFS->SetBool(d3dd, constantLightOn, true);
</presyntaxhighlight>
:: APILight.cpp - turnOff()
<presyntaxhighlight lang="cpp">
uniformFS->SetBool(d3dd, constantLightOn, false);
</presyntaxhighlight>
:: APITexture.cpp - attach()
<presyntaxhighlight lang="cpp">
char str[] = "texOn";
uniformFS->SetBool(d3dd, str, true);
</presyntaxhighlight>
:: APITexture.cpp - detach()
<presyntaxhighlight lang="cpp">
char str[] = "texOn";
uniformFS->SetBool(d3dd, str, false);
</presyntaxhighlight>
** Device
:: fragmentShader.hlsl - Constant Memory
<presyntaxhighlight lang="cpp">
#define MLIGHTS 4
#define MTEXTURES 2
sampler2D tex; // set by the application
</presyntaxhighlight>
:: fragmentShader.hlsl - fragmentShader()
<presyntaxhighlight lang="cpp">
// The fragment shader receives raw fragment data and returns a pixel colour
//
return colour;
}
</presyntaxhighlight>
=== To Do ===
1
edit

Navigation menu