OpenGL 3D Game Tutorial 16: Fog

preview_player
Показать описание
LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we implement 3D fog in OpenGL!

Improved OBJ Parser:

Common Mistakes:

- Make sure that you load the sky colour to the TERRAIN shader, and not the entity shader, before rendering the terrain (see 8:35 in the video).

End of video music- Kai Engel, "Waking Stars":
Рекомендации по теме
Комментарии
Автор

Thanks ThinMatrix for your amazing tutorials. You explain things very clearly and are easy to follow. I'm really enjoying going through these tutorials.

dcaucett
Автор

That bit of shader wizardry was precisely what I needed! Undying thanks to you.

MichaelProstka
Автор

i have looked in many places to see how to implement fog in modern opengl, but the one who helped me the most was you :D thank you

emetaeg
Автор

All is working perfectly! Thank you, man :3

stnger
Автор

i have this errors:



ERROR: 0:35: 'assign' : l-value required "visibility" (can't modify an attribute)
ERROR: 0:36: 'assign' : l-value required "visibility" (can't modify an attribute)


Could not compile shader!

AlbertoMF
Автор

i love your tutorials so much, keep up the great work ;)

simondaniel
Автор

Hello ThinMatrix,
Is there any plan for creating a tutorial for ambient occlusion?

iamdipankarj
Автор

Omg I just found out my mistake and it was a stupid one lol, I was listening to you in the backround and I put color as "Color" meanwhile in the beginning I was using "Colour" to be as exact as possible to you. LOL

ishansethi
Автор

Can you have fog with skyboxes or would you just fade the objects' transparency in that case?

meanmole
Автор

Thanks for all the tutorials that you have done...seriously in the 3 years I have studied in the university computer science, teachers never teach me things like displays, or renders, or buffer, etc., you are really good, and obviously I'm already subscribed and liked all the videos that I have watched.

Now I'm recently finished this tutorial and the fog works nice, first without the improved obj parser and second with the obj parser

But I have a question about the improved obj parser:

¿Do I have to erase some older methods or classes? If so....
¿Which ones do I have to delete?

Thanks man this is like the holy grial of making games in java.

razorblade
Автор

Umm, any help? ERROR: 0:41: 'constructor' : not enough data provided for construction


Could not compile shader!

HungryFox
Автор

Is there a way of making this fog half a color? Like half screen up, is color blue, and half screen down is red.

da_kgamer
Автор

I tried following the steps but all my screen is dark fog and not just in the center, this is my shader
#version 460 core

layout (location = 0) in vec3 vTextureCoords;

layout (location = 0) out vec4 fragColor;

uniform samplerCube texture_diffuse1;
uniform samplerCube texture_diffuse2;
uniform float use_blending;
uniform float blend_factor;
uniform float use_fog;
uniform vec3 fog_colour;

const float lower_limit = 0.0; // center of the screen
const float upper_limit = 30.0; // slightly above the horizon

void main()
{
vec4 texture1 = texture(texture_diffuse1, vTextureCoords);
vec4 texture2 = texture(texture_diffuse2, vTextureCoords);
vec4 finalColour = texture1;
if (int(use_blending) == 1) {
finalColour = mix(texture1, texture2, blend_factor);
}

if (int(use_fog) == 1) {
float fog_factor = clamp((vTextureCoords.y - lower_limit) / (upper_limit - lower_limit), 0.0, 1.0);
finalColour = mix(vec4(fog_colour, 1.0), finalColour, fog_factor);
}

fragColor = finalColour;
} any help please

kafkaphoenix
Автор

For some reason my game crashed and the console says this:

Fri Dec 30 13:14:30 GMT-04:00 2016 INFO:Use Java PNG Loader = true
Could not compile shader.
ERROR: 0:42: 'mix' : no matching overloaded function found (using implicit conversion)
ERROR: 0:42: 'assign' : cannot convert from 'const float' to 'FragUserData 4-component vector of float'

can someone help me please?

justanotheremailaccount
Автор

Yeahhh I am your 500th like!!! I feel so happy right now

PretMetInternet
Автор

Add this method to the Loader file:
public RawModel loadToVAO(ModelData modelData) {
return loadToVAO(modelData.getVertices(), modelData.getTextureCoordinates(), modelData.getNormals(), modelData.getIndices());
}
Makes life easier when loading multiple models.

haxic
Автор

OMG Finally I find a tutorial like that, that is great. I am also game programmer student, in school my teachers basically just teach us the basic concept of 3D graphic pipeline, we never really get into it. Later on, we get start use Unity. But that is not what I want, I want more freedom to make my game and more understanding to OpenGL. Thank you much. Except more your great video.

rgrvisin
Автор

Hey, sorry for necro-ing such an old vid, but while doing this fog part, i came across an issue where any color other than black for skycolour looks off, its like the whole screen gets an overlay of that color, ivelooked over the code alot but i cant figure out whats wrong

florence
Автор

Hm... in my case, the new OBJFileLoader does not load the Tree1.obj in the dropbox collection. Blows up with array index out of bounds.

javawriter
Автор

why don't you use the object Colour(r, g, b) istead of float for each colour?

juleseschbach