Jump to content

  • Log In with Google      Sign In   
  • Create Account

phil_t

Member Since 06 Oct 2006
Offline Last Active Today, 02:56 PM

#5198045 Rendering an atmosphere

Posted by phil_t on 13 December 2014 - 05:33 PM

If your planet sphere vertices have normals, you can just render a larger version and dot the normal with the normalized (eye -> worldposition) vector to determine how much the rendered geometry is "facing" the camera. Stuff that's directly facing the camera will be invisible, stuff that's directly perpendicular (the edges of the atmosphere as seen from the viewer) will be the most visible.

 

Essentially, the dot product will give you a number between 0 and 1 (well, -1 and 1, but negative stuff is facing away and won't be rendered if culling is enabled). Then you can map that 0 to 1 range to whatever "alpha" you need... you'll probably want an exponential function in there, since the atmosphere would only tend to be truly visible at values close to 0.

 

I use something similar to render the atmosphere here:

TN.jpg




#5197892 Direct2D kills my CriticalSection...?

Posted by phil_t on 12 December 2014 - 06:23 PM


However I doubt that this is the case. I know I'm properly calling LeaveCriticalSection. Again, this code worked 100% of the time until I added the 3 Direct2D calls. I can comment them out and it works perfectly.

 

Have you inspected the receiver thread when this happens? If you're 100% certain that you are properly calling LeaveCriticalSection, then you should be able to break into the debugger (switch the TryEnterCriticalSection to EnterCriticalSection and then break into the debugger when it hangs) and see why your receiver thread is stuck between an Enter/Leave.

 

As for Direct2D being the cause of your problem, it's more likely that those calls just affected the timing of your program so as to expose a bug in your code.




#5196468 Animate textures

Posted by phil_t on 05 December 2014 - 11:29 AM

You could add a per-vertex "ring index" that would be the same for all vertices in a ring (you could stash this in the vertex color channel, if you're not using it), and then have a custom shader that colors things appropriately.




#5196363 Ambient lighting

Posted by phil_t on 04 December 2014 - 08:14 PM


I don't understand why you speak about context because when you write lighting stuff you don't need a context, that's a general stuff.

 

That's not true. It's very commonplace in games that you can produce an effect more cheaply if it only needs to work in limited scenarios. In this case you were asking for a less expensive solution than full global illumination, so it seems reasonable to assume maybe you'd be ok with some limitations.




#5196362 Blood in a top-down shooter

Posted by phil_t on 04 December 2014 - 08:11 PM


(problem 1) and the new blood overwrites the previously drawn blood (problem 2). Image before monster death and image after, both issues can be seen.
I'm probably missunderstanding how the render to texture process really works, which is causing my issues.

 

For problem 2, it looks like you just haven't set the alpha blending states properly when drawing the blood to your rendertarget. I think the problem might be this:

rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ZERO;

You're basically ignoring the alpha value that's already in your rendertarget (so when drawing a new patch of blood, the transparent areas of that sprite will now "erase" any blood already there). You might try D3D11_BLEND_INV_SRC_ALPHA for DestBlendAlpha too. (It's possible you might need to use pre-multiplied alpha everywhere in order for this to work properly though - not sure, I'd need to think about it more).

 

As for problem 1, I'm not sure. It just sounds like you're drawing it in the wrong place :P.

 

 

 


First off, is this a good way to do blood at all? I've read about decals a bit today, and am not sure if that's the way i should be going for, or if i can get decent results with this.

 

If you want the blood patches to stay forever, what you're doing now seems like a reasonable way of doing it.




#5196338 Ambient lighting

Posted by phil_t on 04 December 2014 - 05:15 PM

Yeah, we probably need more context. You can probably cheaply improve upon that if you're targeting a certain situation.

 

For instance, for an outdoor scene with a strong directional light (e.g. sun), I found this article that does a nice job explaining how to add some "ambient" light by simulating a bounce of the directional light:

http://www.iquilezles.org/www/articles/outdoorslighting/outdoorslighting.htm

 

I did something similar, but a little bit more complex:

http://mtnphil.wordpress.com/2014/05/03/global-illumination-improving-my-ambient-light-shader/




#5195514 Return value

Posted by phil_t on 30 November 2014 - 11:49 AM

You need to ask yourself what you expect to happen in your program. Is it expected behavior that sometimes you will not find a "one"? (In which case, return a null pointer, or do something like NLScotty suggests) Or is this like a failure condition indicating a bug in your program? (In which case, assert, or throw an exception).

 

Anyway, why do you want to convert it from pointers to objects?




#5195357 Improving component system

Posted by phil_t on 29 November 2014 - 11:10 AM


Should I require that when an Entity is created it will have a pointer to some sort of "SystemManager" that it can notify when Components are attached or detached?

 

Is there a reason the entity needs to be in the picture when adding/removing components? If someone else is managing the component storage, then no "notifications" are needed. Instead of "hey entity, I'm adding a foo component to you", have it be "hey worldmanagerthing, I'm adding a foo component to entity 12345".

 


And if I do that, then how would I be able to retain support for my features like disabling entities and all their children?

 

Do you have functionality for deleting an entity and all its children? Maybe this could be similar, except that instead of the entity/components being reclaimed, they could be moved to some alternate storage area while disabled.




#5195016 Problem passing a constant string into a funciton in C

Posted by phil_t on 27 November 2014 - 12:36 PM


My second problem is, "first" is not properly set to "p" in the newPost function. Have i somehow mixed up my pointers?

 

post *first;

 

This is a pointer to a post struct. Answer yourself this: where do you actually assign it a value? i.e. where do you say "ok, this is the post struct that you point to".

 


It feels a bit ugly though and i would rather if the "first" pointer was set inside the function.

 

In order to modify the value of a variable in a function, you'll need to pass its address into the function.




#5194832 is there a better way top refer to assets in a game?

Posted by phil_t on 26 November 2014 - 02:57 PM

To avoid having to do the string->index conversion every time, whatever code has the string can just do the lookup once and then store the result.

 


this screenshot was just under 15,000 calls:
 
http://www.gamedev.net/gallery/image/4895-lots-of-batch-calls/

 

That is a ton of draw calls for what I see. Are you planning to do any culling and/or instancing?




#5194004 Soft Particles and Alpha Blending

Posted by phil_t on 21 November 2014 - 12:46 PM


@MJP: Since the transparent meshes are not writing to the Z buffer, the particles are not soft when intersecting with transparent mesh.

 

So then have them write to the z buffer.




#5188536 Game State management in Entity Component System architecture

Posted by phil_t on 22 October 2014 - 10:04 AM


When it comes to ECS I can imagine the following:
 
1) We still have Game States as individual objects
 
2) Each Game State has its own list of Entities (probably some kind of "EntityManager")
 
3) Game States have their own initialization logic: they can create their own entities during init. This logic is executed when the Game State is created or when it becomes active. We have a GameStateManager object to manage Game States life cycle
 
4) Entity Systems belong to the Game (not the Game States) but they only process those Entities that are contained by the currently active Game State
 
Please share your thoughts

 

I think this is reasonable. I assume by "game states", you're talking about things like, main menu, lobbies, actual game play, etc... If you have separate lists of entities, you might possibly want separate instances of each system too. It really depends on your needs. For instance, think about how the rendering system(s) will work when transitioning between game states (can you have more than one game state active at a time?).

 

 


in all of these examples, the "state" had its own render, input, and update methods. 

 

That seems a bit strange to me. Why would the render methods differ? At any rate, if the OP is using an ECS, I wouldn't expect the game state to have render or input methods - that functionality should be handled by the render and input systems (which are the same for all game states) and the entities that belong to that game state.

 

 


Consider the full on approach where you have an entity that for everything and game objects are bags of entities. So a character running around the game would have ...
 
SkinnedMeshEntity, WeaponEntity, HealthEntity, BackpackEntity, etc.   Each of those would have it's own bag of entities. (TransformEntity, CollisionBoxEntity, ......)

 

Most of those would be components, not entities (e.g. HealthComponent, TransformComponent, CollisionComponent).

 

 


The weapon needs bullets, so it has a reference to a BulletMagazineEntity. A skinned mesh needs an animation entity. A character needs a target to shoot at, which is an entity.... you see were this is going?

 

Yes. This is one good reason why code should not exist in components. Components can be related by the fact that they are attached to the same entity, and the systems (with the code) can reason over them.

 


or an open world type game.
 
If you are thinking of the latter, I would avoid ECS like the plague. The problems when you start streaming out objects that are refenced by entities can stall development completely. You have an object (bag of entities) that is leaving the game area but objects that are still in the game area have references to them. Next update they try to extract information from the object that doesn't exist anymore with random and probably fatal results.

 

This problem has nothing whatsoever to do with ECS. You would have to solve exactly the same issues if you were using a more traditional OOP architecture (or whatever). "some game objects are streamed out of the world and other active game objects may have references to them". If anything, using an ECS (or any data-oriented framework) would make this more straightforward because you generally have more knowledge on where your data is. For example, a "TargetingComponent" would ideally be re-usable for any game object that needs to target another - so your code that reasons over what happens when parts of the world stream in/out only needs to look through TargetingComponents, rather than this information being hidden behind some "OOP wall" on an object.




#5188339 Is there a way for me to see my game`s performance or frame rate?

Posted by phil_t on 21 October 2014 - 11:15 AM

In any serious project, I build a performance measurement system into the game. I categorize sections of the draw and update loops and can pop up a display in game that shows how long each section took, or any spikes that took place recently.

 

From there, I can get a better idea of what to look at: if I need to use a CPU profiler to get more info about a section of game code, or if I should use a GPU profiler (e.g. Intel GPA) to see what's up.




#5188242 Terrain lighting artifacts

Posted by phil_t on 20 October 2014 - 10:36 PM

As has been explained several times already in this thread, this is just the way it is. When you triangulate quads and interpolate between 3 points, you will have "artifacts" that depend on how you triangulate it.

 

There are various mitigations:

- Sample the normals from a texture in your pixel shader. That way you'll be interpolating between 4 points, and not 3.

- Orient your triangulation along the slope line

- Increase the resolution of your height map

- Put a texture on it so it's not so noticeable




#5187438 "Bind" Entities to Entity

Posted by phil_t on 16 October 2014 - 11:37 AM

You need to implement some kind of parent/child hierarchy. This could be done with Transform components on entities. e.g. an entity could have a Transform component, and that Transform component contains some reference to the parent entity (or the Transform on the parent entity).

 

I talk briefly about how I go about this here: http://mtnphil.wordpress.com/2014/06/09/managing-game-object-hierarchy-in-an-entity-component-system/

 

Elephant seems like an old framework that hasn't been updated in years. It also seems to put code logic in the components themselves, as opposed to systems that operate over components (as is more common these days). You might want to check out Artemis, or something based on Artemis. I'm sure there are examples using it that have solutions to visual parent-child hierarchies.






PARTNERS