struct ObjModelVert
{
float m_position[3];
float m_normal[3];
float m_uv[2];
};
struct ObjModel
{
vector<ObjModelVert> m_vertices;
vector<int> m_indices;
};
bool ObjLoader::LoadFromFile(wchar_t* filename)
{
ifstream fin;
char* buffer;
int filesize;
Tokenizer tokenStream, lineStream, faceStream;
vector<float> verts;
vector<float> norms;
vector<float> texC;
// Assume we have the following member in this class:
// ObjModel m_loadedModel;
string tempLine, token;
fin.open(filename, ios_base::in);
if (fin.fail())
return false;
fin.seekg(0, ios_base::end);
filesize = static_cast<int>(fin.tellg());
fin.seekg(0, ios_base::beg);
buffer = new char[filesize];
memset(buffer, '\0', filesize);
fin.read(buffer, filesize);
fin.close();
// Send buffer to tokenstream
tokenStream.SetStream(buffer);
if (buffer)
{
delete[] buffer;
buffer = 0;
}
char lineDelimiters[2] = { '\n', ' ' };
while (tokenStream.MoveToNextLine(&tempLine))
{
lineStream.SetStream((char*)tempLine.c_str());
tokenStream.GetNextToken(0, 0, 0);
if (!lineStream.GetNextToken(&token, lineDelimiters, 2))
continue;
if (strcmp(token.c_str(), "v") == 0)
{
lineStream.GetNextToken(&token, lineDelimiters, 2);
verts.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
verts.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
verts.push_back((float)atof(token.c_str()));
}
else if (strcmp(token.c_str(), "vn") == 0)
{
lineStream.GetNextToken(&token, lineDelimiters, 2);
norms.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
norms.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
norms.push_back((float)atof(token.c_str()));
}
else if (strcmp(token.c_str(), "vt") == 0)
{
lineStream.GetNextToken(&token, lineDelimiters, 2);
texC.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
texC.push_back((float)atof(token.c_str()));
}
else if (strcmp(token.c_str(), "f") == 0)
{
char faceTokens[3] = { '\n', ' ', '/' };
string faceIndex;
faceStream.SetStream((char*)tempLine.c_str());
faceStream.GetNextToken(0, 0, 0);
// OBJ has face indices as 1 based rather than 0 based. Also this data doesn't need any special re-ordering
// so we can copy it to our loaded model object directly.
faceStream.GetNextToken(&faceIndex, faceTokens, 3);
m_loadedModel.m_indices.push_back((int)atoi(faceIndex.c_str()) - 1);
faceStream.GetNextToken(&faceIndex, faceTokens, 3);
m_loadedModel.m_indices.push_back((int)atoi(faceIndex.c_str()) - 1);
faceStream.GetNextToken(&faceIndex, faceTokens, 3);
m_loadedModel.m_indices.push_back((int)atoi(faceIndex.c_str()) - 1);
}
token[0] = '\0';
}
int vIndex = 0, nIndex = 0, tIndex = 0;
for(; vIndex < verts.size(); vIndex += 3, nIndex += 3, tIndex +=2)
{
ObjModelVert newVert;
// Position Data
newVert.m_position[0] = verts[vIndex]; // You could probably just do a memcpy here and grab all components at once, but I'll be explicit in this case.
newVert.m_position[1] = verts[vIndex + 1];
newVert.m_position[2] = verts[vIndex + 2];
// Normal data
newVert.m_normal[0] = norms[nIndex];
newVert.m_normal[1] = norms[nIndex + 1];
newVert.m_normal[2] = norms[nIndex + 2];
// Tex Coordinates
newVert.m_uv[0] = texC[tIndex];
newVert.m_uv[1] = texC[tIndex + 1];
m_loadedModel.m_vertices.push_back(newVert);
}
// Don't need to clean up the temporary vectors since they were allocated on the stack, they'll automatically get cleaned up when they go out of scope.
return true;
}
- Viewing Profile: Reputation: AdeptStrain
Community Stats
- Group Members
- Active Posts 25
- Profile Views 587
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
User Tools
#5007427 Quick texturing question
Posted by AdeptStrain
on 05 December 2012 - 10:14 AM
#5007113 Terrain Multi-texture
Posted by AdeptStrain
on 04 December 2012 - 10:15 AM
http://www.gamerende...ture-splatting/
Basically, you have an RGBA texture that has each channel dedicated to 1 texture (so, grass could be the red channel and sand the green channel). Then in your shader code you just sample all your textures and multiply them by the blend specified in the blend map:
float4 sand = textureSampler.Sample(textureSand, input.Tex); float4 grass = textureSampler.Sample(textureGrass, input.Tex); // Add up to 2 more textures (of course you can exceed that limit in various ways, but I'll keep it simple). float4 blend = textureSampler.Sample(textureBlendMap, input.Tex); float4 finalColor = grass * blend.r + sand * blend.g /*add other channels here*/; return finalColor;
#5006662 hundreds of errors and warnings in xnamath.h
Posted by AdeptStrain
on 03 December 2012 - 10:18 AM
Solved!
I had to #include <d3dx11.h> first.
1 rep for Erik!
You don't actually need <d3dx11.h>, just <windows.h> - as Eric mentioned above. XNAMath isn't DX11 specific.
#4986784 .fx file error - Box comes out blue
Posted by AdeptStrain
on 04 October 2012 - 09:16 AM
As noted, it's my DX10 code; I need to get a new video card. And other expenses...
Yea, looks like uninitialized memory to me (that 1.#Q is a good hint and probably NaN). I'd look at the Direct3D 11 Tutorials that come with the SDK (specifically tutorial #4) and create a constant buffer, fill it with the data you want, and then set it for your pixel shader so it can access the data. Very simple process and will give you more control/better results of your data anyway.
I've used SlimDX before and its going to be VERY similar to the D3D tutorial (just more object based since SlimDX is a simple wrapper on top of the normal SDK).
Edit: Just to clarify, I meant to ask if DX10 versus DX11 changes the tutorial I should look at, but the question probably wasn't clear. Don't want to implement DX11 code that has a silent error if ported to DX10 or something, after all.
Ah, sorry, missed that. Regardless, Tutorial 4+ in the DirectX10 Tutorials directory of the SDK shows the same stuff. Looks like there is some small differences between 10 and 11 but not much.
#4986443 .fx file error - Box comes out blue
Posted by AdeptStrain
on 03 October 2012 - 10:32 AM
If I am, I haven't found it. And I've looked using multiple techniques. Plus, that changing (and using both) the blue and alpha colours causes the box to change colours, makes it unlikely. (What I mean is, trying something swizzling blue, alpha and green on Material.Diffuse gets yellow. Which is one way I know it's reading the blue and alpha colours correctly).
And you're not setting the constant buffer values anywhere in code? I've never seen a constant buffer initialized in a shader... only declared. Slightly shocked that works.
You can verify exactly what values its reading and see what the cbuffer is actually filled with if you run it through PIX.
#4973959 Annoying issue with MRTs.
Posted by AdeptStrain
on 27 August 2012 - 07:33 PM
Trying my hand at implementing deferred shading but I'm running into an issue where my values are being set properly on the render targets (I can see them in pix), but when I go to render the fullscreen quad - I get nothing. Infact Pix even says the pixel shader is returning the color I expect, but the final frame buffer value is always black.
The high level view of my code goes like this:
- Create 3 Render Targets(Diffuse, Normal, Depth)
- Set those 3 Render targets before drawing.
- Render...
- Set the Render Target to the original backbuffer and depth buffer (Actually right now I'm using the same depth buffer for the MRTs and the final quad...but Pix isn't saying the pixel is being thrown away due to depth issues, at least that I can tell).

EDIT: I just noticed the damn alpha value. I hate Occam, his stupid razor, and I hope he jumped off a cliff (like I will soon be doing).
- Home
- » Viewing Profile: Reputation: AdeptStrain

Find content