Open main menu

CDOT Wiki β

Changes

GAM670/DPS905 Weekly Schedule 20121

15,494 bytes added, 07:00, 21 March 2012
This Week
*** [http://msdn.microsoft.com/en-us/library/bb509617%28v=vs.85%29.aspx length()] - length of a vector
*** [http://msdn.microsoft.com/en-us/library/bb509645%28v=vs.85%29.aspx saturate()] - clamp scalar, vector, or matrix to [0, 1]
* effects.fx- for unlit vertices and fragments
: Uniform data
<syntaxhighlight lang="cpp">
return output;
}
</syntaxhighlight>
: techniques - opaque and translucent
<syntaxhighlight lang="cpp">
technique opaque {
pass {
AlphaBlendEnable = false;
VertexShader = compile vs_3_0 unlitVShader();
PixelShader = compile ps_3_0 unlitFShader();
}
}
</syntaxhighlight>
 
<syntaxhighlight lang="cpp">
technique translucent {
pass {
AlphaBlendEnable = true;
VertexShader = compile vs_3_0 unlitVShader();
PixelShader = compile ps_3_0 unlitFShader();
}
}
</syntaxhighlight>
 
=== To Do ===
=== Resources ===
 
 
== Week 10 - Mar 18 ==
=== This Week ===
* Texturing - Identification
: connection between Design.cpp and effects.fx
** iTexture.h
:: add texture and texture state identifier
<syntaxhighlight lang="cpp">
iTexture* CreateTexture(const wchar_t* file, const char* str,
const char* isOn);
</syntaxhighlight>
** Texture.h
:
<syntaxhighlight lang="cpp">
Texture(const wchar_t*, const char*, const char*);
</syntaxhighlight>
** Texture.cpp
:
<syntaxhighlight lang="cpp">
// constructor initializes the texture identifier
//
Texture::Texture(const wchar_t* file, const char* str,
const char* isOn) : filter(0u) {
 
if (file) {
int len = strlen(file);
this->file = new wchar_t[len + 1];
strcpy(this->file, file, len);
}
else
this->file = nullptr;
 
tex = nullptr;
#if PIPELINE == FIXED_FUNCTION
#elif PIPELINE == PROGRAMMABLE
#elif PIPELINE == PROGRAMMABLE_EFFECT
textureHandle = effect->GetParameterByName(0, str);
textureonHandle = effect->GetParameterByName(0, isOn);
#endif
}
</syntaxhighlight>
:
<syntaxhighlight lang="cpp">
effect->SetTexture(textureHandle, tex);
effect->SetBool(textureonHandle, true);
</syntaxhighlight>
** iAPITexture.h
:: add texture and texture state identifier
<syntaxhighlight lang="cpp">
iAPITexture* CreateAPITexture(const wchar_t* file, const char* str,
const char* isOn);
</syntaxhighlight>
** APITexture.h
:
<syntaxhighlight lang="cpp">
D3DXHANDLE textureHandle; // points to texture
D3DXHANDLE textureonHandle; // points to texture on status
public:
APITexture(const wchar_t*, const char*, const char*);
</syntaxhighlight>
** APITexture.cpp
:
<syntaxhighlight lang="cpp">
// constructor initializes the texture identifier
//
APITexture::APITexture(const wchar_t* file, const char* str,
const char* isOn, AddressMode m) : filter(0u), mode(m) {
 
if (file) {
int len = strlen(file);
this->file = new wchar_t[len + 1];
strcpy(this->file, file, len);
}
else
this->file = nullptr;
 
tex = nullptr;
target = nullptr;
#if PIPELINE == FIXED_FUNCTION
#elif PIPELINE == PROGRAMMABLE
#elif PIPELINE == PROGRAMMABLE_EFFECT
textureHandle = effect->GetParameterByName(0, str);
textureonHandle = effect->GetParameterByName(0, isOn);
#endif
}
</syntaxhighlight>
:
<syntaxhighlight lang="cpp">
effect->SetTexture(textureHandle, tex);
effect->SetBool(textureonHandle, true);
</syntaxhighlight>
* Texturing - Tiling
: [http://msdn.microsoft.com/en-us/library/windows/desktop/bb206245%28v=vs.85%29.aspx Texture Coordinates]
** iGraphic.h
:: add u v parameters, both of which default to 1
<syntaxhighlight lang="cpp">
iGraphic* CreateBox(float, float, float, float, float, float,
float = 1, float = 1);
iGraphic* CreateIBox(float, float, float, float, float, float,
float = 1, float = 1);
iGraphic* CreateRectangleList(float, float, float, float,
float = 1, float = 1);
iGraphic* CreateIRectangleList(float, float, float, float,
float = 1, float = 1);
iGraphic* CreateMeshBox(float, float, float, float, float,
float, float = 1, float = 1);
</syntaxhighlight>
** Graphic.cpp
:: extend add functions to include u v parameters
<syntaxhighlight lang="cpp">
//-------------------------------- Graphic Structures -------------------------
//
// prototypes for add() function used by the Create...() functions
void add(VertexList<Vertex>*, const Vector&, const Vector&, const Vector&,
const Vector&, const Vector&, float = 1, float = 1);
void add(IndexedList<Vertex>*, const Vector&, const Vector&, const Vector&,
const Vector&, const Vector&, float = 1, float = 1);
void add(CustomMesh<Vertex>*, const Vector&, const Vector&, const Vector&,
const Vector&, const Vector&, float = 1, float = 1);
 
// CreateBox builds a triangle vertex list for a brick-like box from two
// extreme points one face at a time with all faces having the same attributes
//
iGraphic* CreateBox(float minx, float miny, float minz, float maxx,
float maxy, float maxz, float u, float v) {
VertexList<Vertex>* vertexList =
(VertexList<Vertex>*)CreateVertexList<Vertex>(TRIANGLE_LIST, 12);
 
float x = (minx + maxx) / 2;
float y = (miny + maxy) / 2;
float z = (minz + maxz) / 2;
minx -= x;
miny -= y;
minz -= z;
maxx -= x;
maxy -= y;
maxz -= z;
// bounding sphere
float max;
max = maxx > maxy ? maxx : maxy;
max = maxz > max ? maxz : max;
vertexList->setRadius(1.73205f * max);
// locate centroid at origin
Vector p1 = Vector(minx, miny, minz),
p2 = Vector(minx, maxy, minz),
p3 = Vector(maxx, maxy, minz),
p4 = Vector(maxx, miny, minz),
p5 = Vector(minx, miny, maxz),
p6 = Vector(minx, maxy, maxz),
p7 = Vector(maxx, maxy, maxz),
p8 = Vector(maxx, miny, maxz);
add(vertexList, p1, p2, p3, p4, Vector(0, 0, -1), u, v); // front
add(vertexList, p4, p3, p7, p8, Vector(1, 0, 0), u, v); // right
add(vertexList, p8, p7, p6, p5, Vector(0, 0, 1), u, v); // back
add(vertexList, p6, p2, p1, p5, Vector(-1, 0, 0), u, v); // left
add(vertexList, p1, p4, p8, p5, Vector(0, -1, 0), u, v); // bottom
add(vertexList, p2, p6, p7, p3, Vector(0, 1, 0), u, v); // top
 
return vertexList;
}
 
iGraphic* CreateIBox(float minx, float miny, float minz, float maxx,
float maxy, float maxz, float u, float v) {
IndexedList<Vertex>* indexedList = (IndexedList<Vertex>*)
CreateIndexedList<Vertex, unsigned short>(TRIANGLE_LIST, 12);
 
float x = (minx + maxx) / 2;
float y = (miny + maxy) / 2;
float z = (minz + maxz) / 2;
minx -= x;
miny -= y;
minz -= z;
maxx -= x;
maxy -= y;
maxz -= z;
// bounding sphere
float max;
max = maxx > maxy ? maxx : maxy;
max = maxz > max ? maxz : max;
indexedList->setRadius(1.73205f * max);
// locate centroid at origin
Vector p1 = Vector(minx, miny, minz),
p2 = Vector(minx, maxy, minz),
p3 = Vector(maxx, maxy, minz),
p4 = Vector(maxx, miny, minz),
p5 = Vector(minx, miny, maxz),
p6 = Vector(minx, maxy, maxz),
p7 = Vector(maxx, maxy, maxz),
p8 = Vector(maxx, miny, maxz);
add(indexedList, p1, p2, p3, p4, Vector(0, 0, -1), u, v); // front
add(indexedList, p4, p3, p7, p8, Vector(1, 0, 0), u, v); // right
add(indexedList, p8, p7, p6, p5, Vector(0, 0, 1), u, v); // back
add(indexedList, p6, p2, p1, p5, Vector(-1, 0, 0), u, v); // left
add(indexedList, p1, p4, p8, p5, Vector(0, -1, 0), u, v); // bottom
add(indexedList, p2, p6, p7, p3, Vector(0, 1, 0), u, v); // top
 
return indexedList;
}
 
// CreateRectangleList builds a triangle list in the x-y plane from its two
// extreme points
//
iGraphic* CreateRectangleList(float minx, float miny, float maxx, float maxy,
float u, float v) {
VertexList<Vertex>* vertexList =
(VertexList<Vertex>*)CreateVertexList<Vertex>(TRIANGLE_LIST, 2);
 
float x = (minx + maxx) / 2, y = (miny + maxy) / 2;
minx -= x;
miny -= y;
maxx -= x;
maxy -= y;
// bounding sphere
float max;
max = maxx > maxy ? maxx : maxy;
vertexList->setRadius(1.73205f * max);
// locate centroid at origin
Vector p1 = Vector(minx, miny, 0),
p2 = Vector(minx, maxy, 0),
p3 = Vector(maxx, maxy, 0),
p4 = Vector(maxx, miny, 0);
add(vertexList, p1, p2, p3, p4, Vector(0, 0, -1), u, v);
return vertexList;
}
 
// CreateIRectangleList builds an indexed triangle list in the x-y plane from
// its two extreme points
//
iGraphic* CreateIRectangleList(float minx, float miny, float maxx, float maxy,
float u, float v) {
IndexedList<Vertex>* indexedList = (IndexedList<Vertex>*)
CreateIndexedList<Vertex, unsigned short>(TRIANGLE_LIST, 2);
 
float x = (minx + maxx) / 2, y = (miny + maxy) / 2;
minx -= x;
miny -= y;
maxx -= x;
maxy -= y;
// bounding sphere
float max;
max = maxx > maxy ? maxx : maxy;
indexedList->setRadius(1.73205f * max);
// locate centroid at origin
Vector p1 = Vector(minx, miny, 0),
p2 = Vector(minx, maxy, 0),
p3 = Vector(maxx, maxy, 0),
p4 = Vector(maxx, miny, 0);
add(indexedList, p1, p2, p3, p4, Vector(0, 0, -1), u, v);
return indexedList;
}
 
// CreateIRectangleList builds an indexed triangle list in the x-y plane from
// its two extreme points
//
iGraphic* CreateBRectangleList(float minx, float miny, float maxx, float maxy,
float u, float v) {
IndexedList<BumpVertex>* indexedList = (IndexedList<BumpVertex>*)
CreateIndexedList<BumpVertex, unsigned short>(TRIANGLE_LIST, 2);
 
float x = (minx + maxx) / 2, y = (miny + maxy) / 2;
minx -= x;
miny -= y;
maxx -= x;
maxy -= y;
// bounding sphere
float max;
max = maxx > maxy ? maxx : maxy;
indexedList->setRadius(1.73205f * max);
// locate centroid at origin
Vector p1 = Vector(minx, miny, 0),
p2 = Vector(minx, maxy, 0),
p3 = Vector(maxx, maxy, 0),
p4 = Vector(maxx, miny, 0);
add(indexedList, p1, p2, p3, p4, Vector(0, 0, -1), u, v);
return indexedList;
}
 
// CreateMeshBox builds a mesh for a brick-like box from two extreme points one
// face at a time with each faces having distinct attributes
//
iGraphic* CreateMeshBox(float minx, float miny, float minz, float maxx,
float maxy, float maxz, float u, float v) {
 
unsigned attribute[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5};
 
CustomMesh<>* mesh = (CustomMesh<>*)
CreateCustomMesh<Vertex, unsigned short>(attribute, 12, 36, 24, 6);
 
float x = (minx + maxx) / 2, y = (miny + maxy) / 2, z = (minz + maxz) / 2;
minx -= x;
miny -= y;
minz -= z;
maxx -= x;
maxy -= y;
maxz -= z;
// bounding sphere
float max;
max = maxx > maxy ? maxx : maxy;
max = maxz > max ? maxz : max;
mesh->setRadius(1.73205f * max);
// one face at a time
Vector p1 = Vector(minx, miny, minz),
p2 = Vector(minx, maxy, minz),
p3 = Vector(maxx, maxy, minz),
p4 = Vector(maxx, miny, minz),
p5 = Vector(minx, miny, maxz),
p6 = Vector(minx, maxy, maxz),
p7 = Vector(maxx, maxy, maxz),
p8 = Vector(maxx, miny, maxz);
add(mesh, p1, p2, p3, p4, Vector(0, 0, -1), u, v); // front
add(mesh, p4, p3, p7, p8, Vector(1, 0, 0), u, v); // right
add(mesh, p8, p7, p6, p5, Vector(0, 0, 1), u, v); // back
add(mesh, p6, p2, p1, p5, Vector(-1, 0, 0), u, v); // left
add(mesh, p1, p4, p8, p5, Vector(0, -1, 0), u, v); // bottom
add(mesh, p2, p6, p7, p3, Vector(0, 1, 0), u, v); // top
 
return mesh;
}
 
void add(VertexList<Vertex>* vertexList, const Vector& p1, const Vector& p2,
const Vector& p3, const Vector& p4, const Vector& n, float u, float v) {
 
vertexList->add(Vertex(p1, n, 0, v));
vertexList->add(Vertex(p2, n, 0, 0));
vertexList->add(Vertex(p3, n, u, 0));
vertexList->add(Vertex(p1, n, 0, v));
vertexList->add(Vertex(p3, n, u, 0));
vertexList->add(Vertex(p4, n, u, v));
}
 
void add(IndexedList<Vertex>* indexedList, const Vector& p1, const Vector& p2,
const Vector& p3, const Vector& p4, const Vector& n, float u, float v) {
 
unsigned v1 = indexedList->add(Vertex(p1, n, 0, v));
unsigned v2 = indexedList->add(Vertex(p2, n, 0, 0));
unsigned v3 = indexedList->add(Vertex(p3, n, u, 0));
unsigned v4 = indexedList->add(Vertex(p4, n, u, v));
indexedList->add(v1);
indexedList->add(v2);
indexedList->add(v3);
indexedList->add(v1);
indexedList->add(v3);
indexedList->add(v4);
}
 
void add(CustomMesh<Vertex>* mesh, const Vector& p1, const Vector& p2,
const Vector& p3, const Vector& p4, const Vector& n, float u, float v) {
 
unsigned v1 = mesh->add(Vertex(p1, n, 0, v));
unsigned v2 = mesh->add(Vertex(p2, n, 0, 0));
unsigned v3 = mesh->add(Vertex(p3, n, u, 0));
unsigned v4 = mesh->add(Vertex(p4, n, u, v));
mesh->add(v1);
mesh->add(v2);
mesh->add(v3);
mesh->add(v1);
mesh->add(v3);
mesh->add(v4);
}
 
</syntaxhighlight>
* Texturing - Address Modes
: [http://msdn.microsoft.com/en-us/library/windows/desktop/bb206239%28v=vs.85%29.aspx Direct3D9 Addressing Modes]
** APITexture.h
:
<syntaxhighlight lang="cpp">
D3DXHANDLE textureMode; // points to texture mode
</syntaxhighlight>
** APITexture.cpp
:
<syntaxhighlight lang="cpp">
effect->SetInt(textureMode, (int)mode);
</syntaxhighlight>
** effects.fx - uniform variables
::
<syntaxhighlight lang="cpp">
// Addressing Modes
#define TEX_WRAP 0
#define TEX_CLAMP 1
#define TEX_MIRROR 2
 
//...
 
bool tex_1_On; // texture switch
int tex_mode; // addressing mode
texture tex_1;
 
sampler2D tex_1_ww = sampler_state {
texture = <tex_1>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
 
sampler2D tex_1_mm = sampler_state {
texture = <tex_1>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = MIRROR;
AddressV = MIRROR;
};
 
sampler2D tex_1_cc = sampler_state {
texture = <tex_1>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
 
</syntaxhighlight>
** effects.fx - fragment shader
:
<syntaxhighlight lang="cpp">
// sample the texture
//
if (tex_1_On) {
if (tex_mode == TEX_CLAMP)
output *= tex2D(tex_1_cc, input.texCoord);
else if (tex_mode == TEX_WRAP)
output *= tex2D(tex_1_ww, input.texCoord);
else if (tex_mode == TEX_MIRROR)
output *= tex2D(tex_1_mm, input.texCoord);
}
</syntaxhighlight>
* Texturing - Multi-Texturing
** effects.fx - uniform variables
:
<syntaxhighlight lang="cpp">
bool tex_2_On; // texture switch
texture tex_2;
 
sampler2D tex_2_ww = sampler_state {
texture = <tex_2>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
 
sampler2D tex_2_mm = sampler_state {
texture = <tex_2>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = MIRROR;
AddressV = MIRROR;
};
 
sampler2D tex_2_cc = sampler_state {
texture = <tex_2>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
 
</syntaxhighlight>
** effects.fx - fragment shader
:
<syntaxhighlight lang="cpp">
if (tex_2_On) {
if (tex_mode == TEX_CLAMP)
output *= tex2D(tex_2_cc, input.texCoord);
else if (tex_mode == TEX_WRAP)
output *= tex2D(tex_2_ww, input.texCoord);
else if (tex_mode == TEX_MIRROR)
output *= tex2D(tex_2_mm, input.texCoord);
}
</syntaxhighlight>
 
=== To Do ===
=== Resources ===
 
<!--
== Week 10 11 - Mar 18 25 ===== This Week === <syntaxhighlight lang="cpp"></syntaxhighlight> === To Do ====== Resources ===--><!--== Week 12 - Apr 1 ==
=== This Week ===