Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
TSDK
Nov 24, 2003

I got a wooden uploading this one
Wang tiling is your friend:
http://en.wikipedia.org/wiki/Wang_tiles

EDIT: Actually, it's a slightly higher level than that you want, isn't it? I'd probably look at grammar rules and markov chains.

EDIT2: Have a look at this paper:
http://graphics.stanford.edu/papers/texture-synthesis-sig00/texture.pdf
What you basically want is a reference texture with some natural looking patches of grass, water edges etc... and then use texture synthesis to make larger maps based on those smaller samples.

TSDK fucked around with this message at 18:01 on Apr 22, 2008

Adbot
ADBOT LOVES YOU

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

DBFT posted:

Apologies if I was vague

I mean procedurally generating the terrain (the grass, water, rock, etc)

If water is 0, grass is 1, rock is 2, tree is 3 and I have an array of integers 50x50 I need to go through that and assign it a value which makes the map look "natural". The joins between different terrain types etc is to be handled seperately so right now I only need to generate what type the terrain is.

One way to do it is to imagine your map as a series of layers - Sand, Rock, Grass, Water, etc. The value in your map of integers specifies the layer that occupies the center of each tile, while the adjacent numbers specify what layers occupy the neighboring tiles. Thus, if I have a terrain map like this

code:
O = Water
X = Land

O O O O
O X O O
O X X O
X X X O
Then my tiles would actually be representing this

code:
OOO OOO OOO OOO
OOO OOO OOO OOO
OOO OOO OOO OOO

OOO OOO OOO OOO
OOO OXO OOO OOO
OOO OXO OOO OOO

OOO OXO OOO OOO
OOO OXX XXX OOO
OOO OXX XXX OOO

OOO OXX XXO OOO
XXX XXX XXO OOO
XXX XXX XXX OOO
Each tile above (All X's, X's with O's across one side, etc) represents a 'variation' in the tile, based on what is occupying the neighboring cell in that direction. These variations can be smoothely transitioned so they look like shore-lines, etc.

Does that make sense?

e:

TSDK posted:

Wang tiling is your friend:
http://en.wikipedia.org/wiki/Wang_tiles

Wang Tiling is a much better approach :)

Heisenberg1276
Apr 13, 2007
If I'm not mistaken aren't the methods you gave me more to do with how the map will appear (blending one tile into another, etc.) rather than making the layout of water/land/rocks/etc look natural?

I looked up Wang Tiles but I can't see how it relates to my problem all that well, I may have not been clear though

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

DBFT posted:

If I'm not mistaken aren't the methods you gave me more to do with how the map will appear (blending one tile into another, etc.) rather than making the layout of water/land/rocks/etc look natural?

I looked up Wang Tiles but I can't see how it relates to my problem all that well, I may have not been clear though

Ah sorry, I mis-interpreted again, then.

This is probably the gold standard for what you're looking for: http://www.dwarffortresswiki.net/index.php/World_generation#How_World_Generation_Works

Heisenberg1276
Apr 13, 2007

Nuke Mexico posted:

Ah sorry, I mis-interpreted again, then.

This is probably the gold standard for what you're looking for: http://www.dwarffortresswiki.net/index.php/World_generation#How_World_Generation_Works

Thanks for that, that's the sort of thing I was looking for. If anyone else has anything to help me that would be great, this is the first time I've tried world generation

TSDK
Nov 24, 2003

I got a wooden uploading this one

DBFT posted:

If I'm not mistaken aren't the methods you gave me more to do with how the map will appear (blending one tile into another, etc.) rather than making the layout of water/land/rocks/etc look natural?
They are and they aren't. Because you're looking for a method to generate 2D maps, then the techniques you're looking for will have more in common with texture synthesis and generation than they will to the most common terrain generation techniques, which focus mainly on 3D.

It might be worth seeing if the file format for Dwarf Fortress is easy to interpret - no point writing your own generation code if you can generate one in DF and then extract the map data to your own format.

voodoo dog
Jun 6, 2001

Gun Saliva

DBFT posted:

Thanks for that, that's the sort of thing I was looking for. If anyone else has anything to help me that would be great, this is the first time I've tried world generation

What I've been using in the past is the Diamond-Square-Algorithm, but it can be a bit difficult getting it to do what you want. Still, I guess it can't hurt to take a look at it.

heeen
May 14, 2005

CAT NEVER STOPS
What is the correct way to compute a depth buffer value from world position, because this gives my slightly wrong values:
code:
	vec4 transformedpos=gl_ModelViewProjectionMatrix*vec4(actualpos,1);
	gl_FragDepth=(transformedpos.z/transformedpos.w-gl_DepthRange.near)/gl_DepthRange.diff;

StickGuy
Dec 9, 2000

We are on an expedicion. Find the moon is our mission.

heeen posted:

What is the correct way to compute a depth buffer value from world position, because this gives my slightly wrong values:
code:
	vec4 transformedpos=gl_ModelViewProjectionMatrix*vec4(actualpos,1);
	gl_FragDepth=(transformedpos.z/transformedpos.w
                     -gl_DepthRange.near)/gl_DepthRange.diff;
This is what I have in one of my shaders, but I have no idea why it's like this anymore:
code:
gl_FragDepth = ((transformedpos.z / transformedpos.w) + 1.0) * 0.5;
EDIT: If I recall correctly, transformedpos.z / transformedpos.w produces a value in [-1, 1] that needs to be mapped to [0, 1].

StickGuy fucked around with this message at 12:40 on Apr 23, 2008

stramit
Dec 9, 2004
Ask me about making games instead of gains.

heeen posted:

What is the correct way to compute a depth buffer value from world position, because this gives my slightly wrong values:
code:
	vec4 transformedpos=gl_ModelViewProjectionMatrix*vec4(actualpos,1);
	gl_FragDepth=(transformedpos.z/transformedpos.w-gl_DepthRange.near)/gl_DepthRange.diff;

I don't have a shader handy which does this, but a good place to start would be to look in the red book about how the depth value is calculated when no shader is bound. There is an overview here: http://www.opengl.org/resources/faq/technical/depthbuffer.htm see point: 12.050

If you want the quick and dirty answer, have a look at this thread here on GPGPU:
http://www.gpgpu.org/forums/viewtopic.php?p=14124.

I tested it out in my own engine on a (very) simple scene and it seemed to work okay. What you really need is the near and far plane, as the calculation is based on that (z buffer has more precision closer to the eye). My code looked like this:

code:
uniform sampler2D diffuseTextureUnit;
uniform float nearPlane;
uniform float farPlane;

varying float eyeZPos;

void main(void)
{
	gl_FragColor = texture2D(diffuseTextureUnit, gl_TexCoord[0].st);
	gl_FragDepth = farPlane / (farPlane - nearPlane) + 
                      ((farPlane * nearPlane / (nearPlane - farPlane)) / eyeZPos);
}

Heisenberg1276
Apr 13, 2007

Wuntvor posted:

What I've been using in the past is the Diamond-Square-Algorithm, but it can be a bit difficult getting it to do what you want. Still, I guess it can't hurt to take a look at it.

So I would use this to generate a hightmap then use that to decide what is land and water? I think i'll try that out as it seems it works for other people.

I think the best way for the type of game I'm trying will be to attempt something similar to dwarf fortress generating temperature, rainfall etc first then basing the map on that.

If anyone has any other suggestions please tell me

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

DBFT posted:

So I would use this to generate a hightmap then use that to decide what is land and water? I think i'll try that out as it seems it works for other people.

I think the best way for the type of game I'm trying will be to attempt something similar to dwarf fortress generating temperature, rainfall etc first then basing the map on that.

If anyone has any other suggestions please tell me

Though this method is theoretically for generating terrain geometries, Dwarf Fortress actually uses something similar to generate it's "elevation map", which in turn influences rainfall, rivers, temperature, and whatnot.

Heisenberg1276
Apr 13, 2007

Nuke Mexico posted:

Though this method is theoretically for generating terrain geometries, Dwarf Fortress actually uses something similar to generate it's "elevation map", which in turn influences rainfall, rivers, temperature, and whatnot.

Then it's decided, generating an elevation map using the diamond square algorithm just as soon as I can figure out how to implement it correctly. I'll no doubt be back asking for more help in the future but you guys have been a great help so far thanks.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

DBFT posted:

Then it's decided, generating an elevation map using the diamond square algorithm just as soon as I can figure out how to implement it correctly. I'll no doubt be back asking for more help in the future but you guys have been a great help so far thanks.

As a side note, the nice thing about the "multi-pass" method that dwarf fortress uses is that, in theory, each layer (rainfall, temperature, elevation, goodness/evilness, etc) can be both randomly generated for gross content construction and then hand-edited to help maximize "fun-factor". While I'm a big fan of procedural generation systems, I find that they're pretty much useless unless they allow for at least some kind of human intervention to make it ultimately 'fit' gameplay designs. This isn't as important for a sandbox game like dwarf fortress, but is necessary if you want to use tools like this for building more linear content.

Heisenberg1276
Apr 13, 2007

Nuke Mexico posted:

As a side note, the nice thing about the "multi-pass" method that dwarf fortress uses is that, in theory, each layer (rainfall, temperature, elevation, goodness/evilness, etc) can be both randomly generated for gross content construction and then hand-edited to help maximize "fun-factor". While I'm a big fan of procedural generation systems, I find that they're pretty much useless unless they allow for at least some kind of human intervention to make it ultimately 'fit' gameplay designs. This isn't as important for a sandbox game like dwarf fortress, but is necessary if you want to use tools like this for building more linear content.

Well the game is a sandbox and the main aim of the game is to explore the (randomly generated) island and colonize it (cut down trees, build huts, etc. etc). There's obviously more to it but what I'm saying is that human interaction in the island generation will hopefully be kept to a minimum.

First i'll try to get the heightmap generated and see where it goes from there, If need be I suppose I will have to allow human intervention.

EDIT:

Random Fractal Terrain posted:

For the square step, we use the same range for generating the random values. There are four diamonds at this stage; they all meet in the center of the array, so we calculate four diamond centers. The corners of the diamonds are averaged to find the base for the new values. Figure c shows the new values in black and existing values in gray.

Should I be able to join the dots and see diamonds because I can't? I can't really see what is a diamond and what is a square?

Heisenberg1276 fucked around with this message at 18:04 on Apr 23, 2008

voodoo dog
Jun 6, 2001

Gun Saliva

DBFT posted:

Should I be able to join the dots and see diamonds because I can't? I can't really see what is a diamond and what is a square?
What might be confusing you is that after the first step, there aren't really four diamonds, unless you imagine four points outside of the actual area. I hope this makes sense..

Also, here you can find an implementation of this algorithm in C#. I wrote it quite a while ago, and it really isn't very readable, but maybe it'll still help you. The code skips the first three steps and does them manually, though, I probably wouldn't do it that way again. Basically, I was just trying to make it generate maps that would always have negative values at the borders and positive ones in the middle.

I think I only used it to separate land from water, the way I did that was that I took an arbitrary value (like 0.0) as a starting point, calculated the water percentage and in several steps adjusted that value until it was close enough to the land percentage that I wanted.

Hope this helps a bit, good luck. :) (and if you want to, you could also contact me on aim).

heeen
May 14, 2005

CAT NEVER STOPS
Ok, the calculation seems to be correct, yet it seems to be z-culled away, any ideas?
I'm raycasting triangles into triangles that lie in front of the former, if that makes sense.
Here is what it looked like with my (apparently wrong) depth calculation. You can see the pool bleed into the border.


edit:
code:
	vec4 transformedpos=gl_ModelViewMatrix*vec4(actualpos,1);
	float near=1.0;
	float far=2048.0;
	float depthcalc=(far / (far - near) + ((far * near / (near - far)) / transformedpos.z));
	gl_FragDepth =  depthcalc;

Vinlaen
Feb 19, 2008

What are some of the most complete game engines for a indie developer?

I'd like an engine to support simple networking (eg. synchronizing player movement) and allow me to create objects for the player to interact with.

For example, I'd like to create an alarm clock that players can select and it would prompt them for a time (eg. custom scripted dialog box), and then at a set time everybody on the server would have an event fired making them lose health or whatever.

I don't want to have to worry about the engine at all (eg. object selection, collisions, networking, etc).

Does anything like this exist at all?

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

Vinlaen posted:

What are some of the most complete game engines for a indie developer?

I'd like an engine to support simple networking (eg. synchronizing player movement) and allow me to create objects for the player to interact with.

For example, I'd like to create an alarm clock that players can select and it would prompt them for a time (eg. custom scripted dialog box), and then at a set time everybody on the server would have an event fired making them lose health or whatever.

I don't want to have to worry about the engine at all (eg. object selection, collisions, networking, etc).

Does anything like this exist at all?

Look at Ogre 3D or Torque

haveblue
Aug 15, 2005



Toilet Rascal
The Torque engine from GarageGames would do that. Or Unity.

StickGuy
Dec 9, 2000

We are on an expedicion. Find the moon is our mission.

heeen posted:

Ok, the calculation seems to be correct, yet it seems to be z-culled away, any ideas?
I'm raycasting triangles into triangles that lie in front of the former, if that makes sense.
Here is what it looked like with my (apparently wrong) depth calculation. You can see the pool bleed into the border.

edit:
code:
	vec4 transformedpos=gl_ModelViewMatrix*vec4(actualpos,1);
	float near=1.0;
	float far=2048.0;
	float depthcalc=(far / (far - near) + ((far * near / (near - far)) / transformedpos.z));
	gl_FragDepth =  depthcalc;
According to the OpenGL specification, that depth calculation is not relevant here. According to Section 2.11, we arrive at a point's normalized device coordinates as follows:
code:
    vec4 transformedpos = gl_ModelViewProjectionMatrix * vec4(actualpos,1);
    vec3 devicepos = transformedpos.xyz / transformedpos.w;
According to Section 2.11.1, we compute the z window coordinate like so:
code:
    float zpos = ((f - n) / 2) * devicepos.z + (n + f) / 2;
Note that, according to the same section, n and f are clamped to [0, 1] and specified with a call to glDepthRange. By default, they are 0 and 1 (See the man page for more information). Thus the calculation, in that case, becomes:
code:
    float zpos = 0.5 * devicepos.z + 0.5;
This is all relevant because in Section 3.11.2, under "Shader Outputs", it specifies that "The final fragment depth written by a
fragment shader is first clamped to [0, 1] and then converted to fixed-point as if it were a window z value (see section 2.11.1)."

Enjoy.

EDIT: Swapped gl_ModelViewMatrix with gl_ModelViewProjectionMatrix.

StickGuy fucked around with this message at 06:42 on Apr 24, 2008

Vinlaen
Feb 19, 2008

Nuke Mexico posted:

Look at Ogre 3D or Torque

HB posted:

The Torque engine from GarageGames would do that. Or Unity.
Thanks for the suggestions!

Unfortunately, Unity3D can only be authored on a Mac and I actually own Torque but it's incredibly difficult to modify and requires hard-core C++ knowledge to do anything "outside the box". (eg. anything except a FPS)

Also, Ogre3D is only a rendering engine and won't do anything else... I'm looking for a one-stop complete package :(

haveblue
Aug 15, 2005



Toilet Rascal
e: double post

haveblue
Aug 15, 2005



Toilet Rascal
If you don't intend to sell your game, you could make it a total conversion for an Unreal or Source title.

And I didn't realize Unity didn't have a Windows editor.

Vinlaen
Feb 19, 2008

HB posted:

If you don't intend to sell your game, you could make it a total conversion for an Unreal or Source title.

And I didn't realize Unity didn't have a Windows editor.
That would require everbody to own Unreal if they wanted to play it :(

Maybe nothing exists like I'm trying to find...

(I'm sorry if it seems like I'm being difficult!)

Vinlaen
Feb 19, 2008

Darnit -- double post.

heeen
May 14, 2005

CAT NEVER STOPS

StickGuy posted:

Enjoy.
Thanks for your effort, but it doesn't work :shobon:

code:

	vec4 transformedpos=gl_ModelViewMatrix*vec4(actualpos,1);
	float devicez = transformedpos.z / transformedpos.w;
// #1	gl_FragDepth = ((gl_DepthRange.far - gl_DepthRange.near) / 2) * devicez + (gl_DepthRange.near + gl_DepthRange.far) / 2;
// #2	gl_FragDepth =  0.5 * devicez + 0.5;

neither of these work :(

edit
alright, I think I found the error in your quote, did you mean to write gl_ModelViewProjectionMatrix? because it seems to work :)


Edit: http://heeen.de/proj/refract.avi :c00l: http://www.youtube.com/watch?v=hqLobCH8PFo

heeen fucked around with this message at 23:48 on Apr 23, 2008

StickGuy
Dec 9, 2000

We are on an expedicion. Find the moon is our mission.
Sorry about the typo. The video looks pretty nice.

TSDK
Nov 24, 2003

I got a wooden uploading this one
Looking good so far.

This is a pretty good method for adding caustic effects, if you want to bump the bling up a notch.

EDIT: There's also a nice technique which uses the water surface mesh rendered as triangles into a texture and projected onto the underwater geometry, where the brightness of the triangles is adjusted based on the size/gradient of the triangle relative to the rest size. This gives you sharper caustics, but I can't find a paper on it at the minute. They used that technique in the PS3 Big Duck demo.

TSDK fucked around with this message at 10:41 on Apr 24, 2008

forelle
Oct 9, 2004

Two fine trout
Nap Ghost

TSDK posted:

Looking good so far.

This is a pretty good method for adding caustic effects, if you want to bump the bling up a notch.


Ooooh I invented something similar to this (but not as good) back in 2000ish.

http://www.patentstorm.us/patents/6809729.html

drat, "Don't publish but patent" companies.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Nuke Mexico posted:

Ah sorry, I mis-interpreted again, then.

This is probably the gold standard for what you're looking for: http://www.dwarffortresswiki.net/index.php/World_generation#How_World_Generation_Works

While on the topic of Dwarf Fortress, is there anywhere he goes over his general approaches to solving certain problems? As a pet project, I was going to work on a very simple game with similar concepts.

My approach to the jobs would be to have each category of job (glassmaking, masonry, etc.) have its own priority queue, to manage which job inside that category was the most important. Then, when an actor needs to get a job, he looks at all the priority queues he has access to (say, for example, he doesn't have cheesemaking, he would skip that queue) and grabs the highest priority of the bunch.

That seems to work pretty well, but the stl priority queue doesn't seem to have any iterator at all, so getting a complete list of jobs available would require maintaining a separate list of pointers. Although, I'd probably have to do that anyways, because using my system wouldn't allow for 'in progress' jobs to remain in the queue. I guess I could just set their priority to 0 while they are in progress, and restore it to the previous priority if the job fails. Then I could keep it in the queue. (Although I'd have to extend the stl implementation a bit, in which case I might as well write a basic iterator for it.)

Anyone know where I could get more information about writing this style of AI? I'm not trying to do anything crazy complex with it, but I am trying to build an easily maintainable, expandable code base.

TSDK
Nov 24, 2003

I got a wooden uploading this one

forelle posted:

Ooooh I invented something similar to this (but not as good) back in 2000ish.

http://www.patentstorm.us/patents/6809729.html

drat, "Don't publish but patent" companies.
What the hell? Issued 2004? Hell, I think I've almost got prior art on that sucker as well.

DacTheHork
Apr 25, 2008

by Fistgrrl
I am a big book person and was wondering if people could post a list of key Game Development books or list of ones they have found useful (specific to game development not general programming).

Here is the list of current Game Development books I own:

Introduction to 3d Game Programming (dx9) - Frank D. Luna
Real Time Collision Detection - Ericson
3D Game Engine Design (1st ed) - David H. Eberly
Game Programming Gems 1-4

For the next round of purchases I was thinking of getting the following books:

Game Physics - David H. Eberly
Artificial Intelligence for Games - Ian Millington

Are there any key books or concepts I am missing out on? Also any recommendations on books would be helpful.

forelle
Oct 9, 2004

Two fine trout
Nap Ghost

TSDK posted:

What the hell? Issued 2004? Hell, I think I've almost got prior art on that sucker as well.

This is the patent I wrote, I can't imagine why they wanted to patent it though. I since found out about 4 other people who "invented" the same method at about the same time as me.

The main crux was the the ability to integrated pretty minimally into a fixed function GL pipeline. But it was first submitted in 2000 (in the UK at least)

forelle fucked around with this message at 01:34 on Apr 26, 2008

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Pfhreak posted:

That seems to work pretty well, but the stl priority queue doesn't seem to have any iterator at all, so getting a complete list of jobs available would require maintaining a separate list of pointers.
One isn't provided, because that would allow operations to be performed on it that would corrupt the ordering. If you need an iterator, they say to use a vector and the heap functions from <algorithm>.

The Monarch
Jul 8, 2006

Can someone send me a link that outlines (in a non coding language specific way) what I need to do for a first person camera? I'm just thinking about the best way to do it (I'm using XNA) but I'd like to see some other stuff and get some ideas.

Also, for anyone experienced with XNA, is there a link that explains the steps that XNA does take to render a model? I'm trying to figure out how to have my rendering in a seperate class, or at least be able to prepare the model (so my game.cs isn't filled with dozens of different model files and stuff), but all the tutorials I find are just "this is how you draw a model: copy this code in this method, this in that, and this code in the draw method and it works". I also have no idea what this does, and how I can break it apart:

code:
foreach (ModelMesh mesh in terrainModel.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation)
                        * Matrix.CreateTranslation(modelPosition);
                    effect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                        aspectRatio, 1.0f, 10000.0f);
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
so I basically just copy and paste that for each model that I need to draw, which I know isn't right. I'm learning a lot with XNA but my programming experience is really low so a lot of this stuff is new to me.

The Monarch fucked around with this message at 00:26 on Apr 28, 2008

Plank Walker
Aug 11, 2005
I just started working on a C++ Direct3D project and am having a hard time figuring out how to use texture states. I'm trying to make a bump-mapped model of the earth. Right now, I can render a sphere with the earth texture on it, and I have it orbiting around a center point map. After searching google and MSDN for tips on bump mapping, i came across the following code:

code:
d3ddev->SetMaterial(&material[i]);
if(texture[i] != NULL)

d3ddev->SetTexture(0, texture[i]);
d3ddev->SetTexture(1, earthBump[i]);
d3ddev->SetTexture(2, specularTex[i]);

d3ddev->SetTextureStageState( 0, D3DTSS_COLOROP,  D3DTOP_MODULATE);
d3ddev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
d3ddev->SetTextureStageState( 0, D3DTSS_ALPHAOP,  D3DTOP_SELECTARG1 );
d3ddev->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 1 );
				
d3ddev->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP,  D3DTOP_BUMPENVMAPLUMINANCE);
d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
	
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT00, F2DW(1.0f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT01, F2DW(0.0f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT10, F2DW(0.0f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT11, F2DW(1.0f) );

d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVLSCALE, F2DW(0.01f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVLOFFSET, F2DW(1.0f) );
			
d3ddev->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );
d3ddev->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_ADD);
d3ddev->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT );
Using this results in a (still flat) image of the specularTex texture. Also, the ambient light becomes a lot more intense (i.e. the dark side of the earth is a lot brighter than just using the earth texture) and the side facing the point light becomes pure white. Most importantly, I don't notice any bump mapping occurring.

I'm using texture images from this site: http://planetpixelemporium.com/earth.html
Texture[i] is just the color map of the Earth, earthBump is the grayscale height map, and specularTex is the third texture from the above site.

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear
I have to present my independent study (XNA rts game) tommorrow, and I need some help cleaning it up. Anyone going to be around on AIM or IRC later tonight? I'm kind of bad at math things, which is where I need to make it look nice - mostly loop timing stuff.

Hover
Jun 14, 2003

Your post hits a tree.
The tree is an ent.
The tree is angry.

The Monarch posted:

Can someone send me a link that outlines (in a non coding language specific way) what I need to do for a first person camera? I'm just thinking about the best way to do it (I'm using XNA) but I'd like to see some other stuff and get some ideas.

Also, for anyone experienced with XNA, is there a link that explains the steps that XNA does take to render a model? I'm trying to figure out how to have my rendering in a seperate class, or at least be able to prepare the model (so my game.cs isn't filled with dozens of different model files and stuff), but all the tutorials I find are just "this is how you draw a model: copy this code in this method, this in that, and this code in the draw method and it works". I also have no idea what this does, and how I can break it apart:

*snip*

so I basically just copy and paste that for each model that I need to draw, which I know isn't right. I'm learning a lot with XNA but my programming experience is really low so a lot of this stuff is new to me.

Alright, I'm going to try to break the code apart for you. I've never used XNA specifically but I'm learning DirectX and have a fairly good understanding of the process of rendering something in 3D, so hopefully I can give you a good head start.

code:
foreach (ModelMesh mesh in terrainModel.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
XNA stuff here, but it seems like this is going through all the meshes in whatever terrainModel is, which I assume is the object you're trying to render. Then it's going through each effect, and I have no idea what that is. But moving on...

code:
                    effect.EnableDefaultLighting();
Enables default lighting. Who would have thought?

code:
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation)
                        * Matrix.CreateTranslation(modelPosition);
Sets the location of the object. It first applies everything from its parent, then rotates it as it needs to be rotated, then translates it to where it needs to be. However, the rotation only seems to be around the Y axis. Again, I don't know XNA, but this seems like it could be problematic.

code:
                    effect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);

Set the camera up. You only need to do this once, not for each model you're putting in the program, assuming XNA doesn't have some crazy thing for cameras.

code:

                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                        aspectRatio, 1.0f, 10000.0f);

Sets the perspective. Like the camera, this only needs to be done once assuming I'm not missing something.

code:

                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
And then it draws. Hopefully this is helpful. If I've messed up anywhere, let me know. Like I said, I'm only learning DirectX but I know graphics a bit and some of this stuff seemed familiar.

Adbot
ADBOT LOVES YOU

The Monarch
Jul 8, 2006

Hover posted:

Alright, I'm going to try to break the code apart for you. I've never used XNA specifically but I'm learning DirectX and have a fairly good understanding of the process of rendering something in 3D, so hopefully I can give you a good head start.

XNA stuff here, but it seems like this is going through all the meshes in whatever terrainModel is, which I assume is the object you're trying to render. Then it's going through each effect, and I have no idea what that is. But moving on...

Enables default lighting. Who would have thought?

Sets the location of the object. It first applies everything from its parent, then rotates it as it needs to be rotated, then translates it to where it needs to be. However, the rotation only seems to be around the Y axis. Again, I don't know XNA, but this seems like it could be problematic.

Set the camera up. You only need to do this once, not for each model you're putting in the program, assuming XNA doesn't have some crazy thing for cameras.

Sets the perspective. Like the camera, this only needs to be done once assuming I'm not missing something.

And then it draws. Hopefully this is helpful. If I've messed up anywhere, let me know. Like I said, I'm only learning DirectX but I know graphics a bit and some of this stuff seemed familiar.

Thanks, I'm starting to get the hang of this and even though I sort of new what you're saying here already splitting it up did help. I still don't like the fact that I have to start this whole loop:

code:
foreach (ModelMesh mesh in terrainModel.Meshes) {
   foreach (BasicEffect effect in mesh.Effects) {
for each model (minus the camera and projection stuff) but I guess there's no other way.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply