154
edits
Changes
→Vertex Shader Programming
==== Vertex Shader Programming ====
* Host
<syntaxhighlight lang="cpp">
// shader file data
#define VERTEX_SHADER_ENTRY_POINT "vertexShader"
</syntaxhighlight>
<syntaxhighlight lang="cpp">
static IDirect3DVertexShader9* vertexShader; // vertex shader
static ID3DXConstantTable* uniformVS; // for vertex shader
</syntaxhighlight>
<syntaxhighlight lang="cpp">
IDirect3DVertexShader9* APIBase::vertexShader = nullptr; // vertex shader
ID3DXConstantTable* APIBase::uniformVS = nullptr; // for vertex shader
</syntaxhighlight>
<syntaxhighlight lang="cpp">
Matrix projection; // projection transformation
</syntaxhighlight>
<syntaxhighlight lang="cpp">
// points to compiled shader code
d3dd->SetVertexShader(vertexShader);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
this->projection = *((Matrix*)projection);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
Matrix& v = *((Matrix*)view);
uniformVS->SetInt(d3dd, "noLights", 4);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
uniformVS->SetBool(d3dd, "lighting", b);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
uniformVS->SetMatrix(d3dd, "world", (D3DXMATRIX*)world);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
uniformVS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&r.ambient, 4);
uniformVS->SetFloat (d3dd, "material.power", (FLOAT)r.power);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
// release the shader COM objects
}
</syntaxhighlight>
<syntaxhighlight lang="cpp">
// Populate the vertex shader constant table
rc = true;
</syntaxhighlight>
<syntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
uniformVS->SetBool(d3dd, constantLightOn, true);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
uniformVS->SetBool(d3dd, constantLightOn, true);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
char constantLightOn[] = "lightOn[0]";
uniformVS->SetBool(d3dd, constantLightOn, false);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
D3DXCOLOR* ambient;
FLOAT* power;
</syntaxhighlight>
<syntaxhighlight lang="cpp">
ambient = nullptr;
power = nullptr;
</syntaxhighlight>
<syntaxhighlight lang="cpp">
ambient = nullptr;
power = nullptr;
</syntaxhighlight>
<syntaxhighlight lang="cpp">
if (ambient)
}
</syntaxhighlight>
<syntaxhighlight lang="cpp">
ambient = new D3DXCOLOR[nSubsets];
power[i] = matl[i].MatD3D.Power; // 0 if it shouldn't be shiny
</syntaxhighlight>
<syntaxhighlight lang="cpp">
uniformVS->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&ambient[i], 4);
uniformVS->SetFloat(d3dd, "material.power", (FLOAT)power[i]);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
if (ambient)
</syntaxhighlight>
* Device
<syntaxhighlight lang="cpp">
#define MLIGHTS 4
</syntaxhighlight>
<syntaxhighlight lang="cpp">
// vertexShader receives a raw vertex and returns the transformed vertex
}
</syntaxhighlight>
==== Fragment Shader ====
* Host