Open main menu

CDOT Wiki β

Changes

GAM670/DPS905 Weekly Schedule 20121

3,845 bytes added, 08:00, 21 March 2012
This Week
== 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
iGraphic* CreateIBox(float, float, float, float, float, float,
float = 1, float = 1);
iGraphic* CreateGrid(float, float, int);
iGraphic* TriangleList(const wchar_t* file);
iGraphic* TriangleList(const wchar_t*, const Colour&);
iGraphic* CreateRectangleList(float, float, float, float,
float = 1, float = 1);
iGraphic* CreateIRectangleList(float, float, float, float,
float = 1, float = 1);
iGraphic* CreateMesh(PrimitiveType, float*, int*);
iGraphic* CreateMesh(const wchar_t*);
iGraphic* CreateMeshBox(float, float, float, float, float,
float, float = 1, float = 1);
return indexedList;
}
 
// CreateGrid builds a grid-like line list of n by n lines in the x-z plane
//
iGraphic* CreateGrid(float min, float max, int n) {
VertexList<Vertex>* vertexList =
(VertexList<Vertex>*)CreateVertexList<Vertex>(LINE_LIST, 2*n+2);
 
float x = (min + max) / 2;
min -= x;
max -= x;
// bounding sphere
vertexList->setRadius(1.73205f * max);
float cur = min, inc = (max - min) / float(n - 1);
for (int i = 0; i < n; i++, cur += inc) {
// in the local x direction
vertexList->add(Vertex(Vector(min, 0, cur), Vector(0, 1, 0)));
vertexList->add(Vertex(Vector(max, 0, cur), Vector(0, 1, 0)));
// in the local z direction
vertexList->add(Vertex(Vector(cur, 0, min), Vector(0, 1, 0)));
vertexList->add(Vertex(Vector(cur, 0, max), Vector(0, 1, 0)));
}
 
return vertexList;
}
</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>