Dad72 Posted December 20, 2013 Share Posted December 20, 2013 Hi, When I put fog on my scene it is active only from the outer limit of the ground and not from the camera. If I have a terrain of 1000 * 1000 my fog begins very far from the camera if i am on the ground in the middle.It should be visible on the ground also, no? If I does not of ground it works very well.I've try the mode LINEAR, EXP and EXP2, same observation. and my shadows do not work. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 20, 2013 Share Posted December 20, 2013 Could you share a scene somewhere? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 20, 2013 Author Share Posted December 20, 2013 Yes, I've recreate a scene more slight to reproduce the problem.This is the online version:Terrain.htmland the downloadable version:Fog.zip Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 21, 2013 Share Posted December 21, 2013 This is because you use a custom shader for the ground. If you need fog support, you have to code it in your shader Here is an extract of the code I used in the StandardMaterial: #define FOGMODE_NONE 0.#define FOGMODE_EXP 1.#define FOGMODE_EXP2 2.#define FOGMODE_LINEAR 3.#define E 2.71828uniform vec4 vFogInfos;uniform vec3 vFogColor;varying float fFogDistance;float CalcFogFactor(){float fogCoeff = 1.0;float fogStart = vFogInfos.y;float fogEnd = vFogInfos.z;float fogDensity = vFogInfos.w;if (FOGMODE_LINEAR == vFogInfos.x){fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);}else if (FOGMODE_EXP == vFogInfos.x){fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);}else if (FOGMODE_EXP2 == vFogInfos.x){fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);}return clamp(fogCoeff, 0.0, 1.0);}float fog = CalcFogFactor();color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor; Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 21, 2013 Author Share Posted December 21, 2013 Thank you. I am not very comfortable with the shaders, but I understand better the problem of fog. How I use this shader? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 21, 2013 Share Posted December 21, 2013 You have to add this piece of code to the groundshader Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 21, 2013 Author Share Posted December 21, 2013 I am going to have the same problem with shadows. i must therefore add the shadows and fog in the shader. But i not understand large thing.Someone can help me with this Shader? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 22, 2013 Author Share Posted December 22, 2013 I finally managed to add the fog and the shadows. I've reuse the shader by default of standardMaterial and merge the groundMaterial of worldMonger. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.