Jump to content

  • Log In with Google      Sign In   
  • Create Account

EarthBanana

Member Since 18 Mar 2013
Offline Last Active Yesterday, 05:11 PM

Posts I've Made

In Topic: Fog Shader

28 June 2016 - 11:46 PM

If you would like to do linear fog, you need something along the lines of

float linear_fog_factor(vec3 worldPos, vec3 camWorldPos, float fogNear, float fogFar)
{
	vec3 dVec = (camWorldPos - worldPos);
	float factor = (fogFar - length(dVec) ) / (fogFar - fogNear);
	factor = clamp(factor, 0.0, 1.0);
	return factor;
}

where worldPos is the interpolated world position of the fragment being rendered, camWorldPos is the world position of the camera the scene is being rendered from, fogNear is the depth where the fog should begin (in world space units), and fogFar is the depth where the fog should end.

 

For blending the fog with the final fog fragment I use something like

final_col = mix(fdat.color * light_factor, fog_color, 1 - fog_factor);

where fdat.color is a 3d vector with the color of the fragment before applying lighting, light_factor is a 3d vector calculated based on the scene lighting, fog_color is a 3d vector with the color of the fog, and fog_factor is the value returned by the previous function.

 

Note that doing fog in this manner can be tricky because you are only "fogging" your geometry and not the background itself. If you have a solid color background, you can make the fog color the same as the background. But if you have a 2d texture or skybox or something it is a bit trickier to make the fog look right.

 

This is a good starting point though. You can work other things out yourself.

 

EDIT: By the way - please use code tags around source code snippets. It looks much prettier.


In Topic: vs 2015:problems with linking SOIL lib.

28 June 2016 - 12:51 PM

Soil is small enough it may be worth it to simply include the source in your project

In Topic: General questions about game engines and frameworks

26 June 2016 - 08:26 PM

I agree with SotL in all above articles.

 

Making an "engine" is fun - but making a game will lead you to a finished project. And finished projects are good for the heart and soul.


In Topic: General questions about game engines and frameworks

26 June 2016 - 11:35 AM

OpenGL and DirectX are low level APIs that give you indirect access to the GPU and allow you to draw things to the screen using hardware.

 

SFML has 5 modules: system, window, audio, networking, and graphics. The graphics module uses OpenGL to draw things, and the window module creates an OpenGL context. The other 3 modules, as far as I know, do not use OpenGL.

 

So to answer the second part of your question - SFML and SDL are not substitutes for OpenGL/DirectX - they do provide a set of functions/classes that wrap OpenGL to try to make it a bit easier to use. You can, with both SFML and SDL, use your own OpenGL code in conjunction with theirs and their documentation shows exactly how to do this.

 

You cannot use Direct3D with SFML/SDL - though you could probably use it with SFML if you only use the audio, networking, and system modules.

 

EDIT: Also - SFML is a good framework to use if your wanting to learn to build your own engine in my opinion. It will take care of a lot of details to get you up and running - and as you learn you can disable modules replacing them with your own code if you would like - or with other libraries specific for the task at hand. For example - you could start with having SFML load your images from file, then later change that out with stb_image or devIL if you like.


In Topic: Programming Game Outputs to control physical objects

23 June 2016 - 10:04 PM

If your asking if its possible to have the game be on a pc and then control lights or other devices based on the pc game, yes it is possible. I would suggest, as mentioned above, looking in to getting a micro-controller and then either get a blue-tooth chip or wifi chip for it and have your game connect to the micro-controller through that. Wifi is probably the easiest - there are lots of microcontrollers that come with wifi built in (some arduinos, raspberri pis, intel edison, etc).

 

If using wifi you would connect the microcontroller to the network and then open up a socket on the microcontroller on some port of your choosing and connect to that from the pc game. Then come up with some data format so that you can send commands/information to the microcontroller through the open socket. The microcontroller would then control the physical devices based on those commands.

 

To open the socket and control physical devices from the microcontroller you would need to write code which will execute on the microcontroller. How to do this is highly dependent on the microcontroller - for arduino you can use the arduino IDE which will cross compile c++ code and transfer the executable to the arduino through a USB connection to the computer. Most microcontrollers will have some IDE of this nature - that allow you to develop on the PC, cross compile, and transfer the executable to the microcontroller. Many will even allow you to debug the executable remotely from your PC.

 

I hope this helps.


PARTNERS