PDA

View Full Version : Shaders: tricks and tips



TRam__
June 8th, 2015, 03:28 PM
Warning! All changes discussed in this thread broke your trainz installation, and within the first patching it will be completly destroyed and will need full reintallation (in case you forgot to paste backup shaders before patching).

So before any changes make a backup of "Shaders" folder (archive it or make its copy with other name) and don't forgot to replace shaders from backup BEFORE any patching.

Also, if you got "Render initialisation failed" - you have done something wrong and it's time to replace last edited shader with the backup one. Basic knowlage of C, C++ or even OpenGL SL will be also usefull. If your changes are successfull you'll need to wait for ~10-15 min first time for shader compilation.

(rar archive with all changes for build 80349 - https://drive.google.com/file/d/0B9tBzwOpZgNnLU5Zc0FqOUwyelE/view?usp=sharing (https://drive.google.com/open?id=0B9tBzwOpZgNnNUdnRGMzVFBBbjA))


So, begin from the easiest. How to make dark shadows and bright illumination?

This require both editing environment settings of the route and editing shaders. For shaders:

Open TANE\resources\Shaders\Common\StdLighting.fsh in any simple text editor (notepad ++, notepade, etc.). At the end of this file find the line

lightData.diffColor.xyz += matDiffuse.xyz * lightAmbient;

and just after it paste

// for wider brightness range
lightData.diffColor.xyz *= 1.5;

Also it will be worth to add ability to make sky brighter without postprocessing also? So, open Shaders\MaterialDefn\SkyBox.fsh and replace line (also near the end)


color.rgb *= skyColor.rgb; //Modulate with the sky colour.
with this one

color.rgb *= skyColor.rgb * 1.5; //Modulate with the sky colour.
So, after saving and closing, load trainz (with looong compilation) and in route set "dark shadows"
http://i.piccy.info/i9/5c0d88782baed8749b0284a689db2f04/1433795071/84843/854143/Bezymiannyi_800.jpg (http://i.piccy.info/i9/8b02332d787e22c1e38af7b2387d2659/1433795071/435173/854143/Bezymiannyi.jpg)http://i.piccy.info/a3/2015-06-08-20-24/i9-8321555/800x422-r/i.gif (http://i.piccy.info/a3c/2015-06-08-20-24/i9-8321555/800x422-r)
or "bright cloudly"
http://i.piccy.info/i9/893af1bdc8932a8bb276bc8efcc2896e/1433795249/104466/854143/Bezymiannyi_800.jpg (http://i.piccy.info/i9/34e02d5714676853d362451ea7015c4b/1433795249/530880/854143/Bezymiannyi.jpg)http://i.piccy.info/a3/2015-06-08-20-27/i9-8321563/800x424-r/i.gif (http://i.piccy.info/a3c/2015-06-08-20-27/i9-8321563/800x424-r)


Next tip. Do you want to get rid from the Compass? I did :) . Open Shaders\MaterialDefn\Compass.fsh and simply add in function "mediump vec4 GetColor0(in VertexToFragment fin)" in its begining after "{ "a line

return vec4 (0.0,0.0,0.0,0.0);
Yes, compass will will be only hidden, not completly disabled, but untill N3V add its disabling, that's the easiest way.

Next... Do you want slightly increase perfomance in the mode "without shadows"? Just disable specular calculation for objects, where it setted to zero (or to "black" color in 3D max). Fo this open Shaders\Common\StdLighting.fsh and in the function "vec3 CalculateLight(const mat3 tangentBasis, const vec3 objectPosition, **** " after a line


// The diffuseColor is the material color modulated with the light color. vec3 color = (diffIntens * diffuse * matDiffuse.rgb);

add this

if(dot(specular,vec3(1, 1, 1)) < 0.01) // we don't need any specular if it is switched off by modeller
specIntens = 0;
else
{

and before

return color;
// ....
// Part of test.... add a line

}

TRam__
June 8th, 2015, 03:44 PM
Continuing next. You know about the bug that "if the sun is under the ground, but its specular still shines"? How to fix? Open Shaders\Common\StdLighting.fsh and find


// Determine if we are in shadow.
lightData.invShadowContribution = GetShadowValue(fin, pssmColor);

doLightCalc = lightData.invShadowContribution > 0.0;
Replace this with

#ifdef LIGHT_TYPE_MAIN // we do not need diffuse or specular from the sun if the sun is under the horisont
bool doLightCalc = false;
if(lightDirGlobal.z > 0)
{
// Determine if we are in shadow.
lightData.invShadowContribution = GetShadowValue(fin, pssmColor);
doLightCalc = lightData.invShadowContribution > 0.0;
}
#else //!LIGHT_TYPE_MAIN
lightData.invShadowContribution = 1.0;
bool doLightCalc = true;

#endif //!LIGHT_TYPE_MAIN

And there will be no sun illumination if the sun is under the horizont.


Next tip... Do you really want that at night all gloss and reflectness objects be dark? I never liked their light, and in TANE i've found a way to do this :) . So, open Shaders\MaterialDefn\StdLightSphericalReflection.f sh and find in function "mediump vec4 GetColor0(in VertexToFragment fin)" a part

#ifdef FORCE_ALPHA_ONE
float reflectionStrength = texDiffColor.a;


#else // !FORCE_ALPHA_ONE
float reflectionStrength = reflectionAmount;

#endif // !FORCE_ALPHA_ONE
And replace with this one

#ifdef FORCE_ALPHA_ONE
float reflectionStrength = texDiffColor.a * reflectionAmount * dot(lightAmbient, vec3(0.33,0.33,0.33) );


#else // !FORCE_ALPHA_ONE
float reflectionStrength = reflectionAmount * dot(lightAmbient, vec3(0.33,0.33,0.33) );

#endif // !FORCE_ALPHA_ONE


Next... Doing the same with "cube map", in file StdLightCubeReflection.fsh find part

#ifdef FORCE_ALPHA_ONE
fragColor.rgb = mix(fragColor.rgb, reflectionColor.rgb, fragColor.a);
#else // !FORCE_ALPHA_ONE
fragColor.rgb = mix(fragColor.rgb, reflectionColor.rgb, reflectionColor.a);
#endif // !FORCE_ALPHA_ONE
and replace it with this one

#ifdef FORCE_ALPHA_ONE
fragColor.rgb = mix(fragColor.rgb, reflectionColor.rgb, fragColor.a * dot(lightAmbient, vec3(0.33,0.33,0.33) ));
#else // !FORCE_ALPHA_ONE
fragColor.rgb = mix(fragColor.rgb, reflectionColor.rgb, reflectionColor.a * dot(lightAmbient, vec3(0.33,0.33,0.33) ));
#endif // !FORCE_ALPHA_ONE

Next... Done this with reflections, may it be it is woth to make smoke to be dark at night also? But the smoke is illumineted with the sun also, so we'll use middle ariphmetic of ambinet an diffuse . Or, stop. We have increased the environmet in 1.5 times... So propose to increase the smoke illumination twice, just for a laugh :). Open Shaders\MaterialDefn\PFXMain.fsh and find "mediump vec4 GetColor0(in VertexToFragment fin)". Before a fragment

// Fog the fragment.
AddFogToFragment(fin, fragColor);

return fragColor;
}add a line

fragColor.xyz *= dot(lightDiffuse + lightAmbient, vec3(0.3,0.3,0.3)); // middle ariphmetic of sum
Now we have a black smoke in night. Just because it isn't illuminated.

Kevin16c
June 8th, 2015, 04:33 PM
A very nice guide on tweaking the post processing mate. Did too many edits at once and caused the render initialization failed error but weeding out the problems now :)

VinnyBarb
June 8th, 2015, 04:53 PM
Very interesting of how one could be able to change these originally installed shader settings and THANK YOU very much to bring this to our attention. As this applies only to your installed TANE and how this will look to you on your screen if so changed as said above. What about a content creator trying to make a better looking asset with such above changes implemented and wanting to show these changes of a much better look on his/her created object? When such a newly created object is looked at in such a modified TANE and then exported out of it as a CDP, will the CDP keep such changed settings and will this still look as was changed in a standard vanilla TANE installation? I guess only testing this in game will answer that question.

Ideally, a user of TANE should be able to change such above settings easily with sliders and other such modifying gadgets in a "modifying settings" menu, not the current way of how clumsy and cumbersome this is presently implemented to a much lesser degree in TANE.

What does TRam think?

VinnyBarb

TRam__
June 8th, 2015, 05:01 PM
Going next, to the "normal map problems" like this http://www.zecrail.com/files/tane/TANE%202015-05-31%2022-55-46-00.jpg . Suppose that is insufficient accuracy of tangents in old exporter, that it had took from UV-coordinats. So called tangent-space, when we took the normal map with projective rendering of high-poligon mesh to our mesh, and obtained normal map corresponds with UV-coordinates. But in reality of Trainz it is unusefull, most of normals are generated with NVidia plugin, that supposes that top is on the top of texture. We even have no tutorial from N3V how to make an animation that deformates a mesh. So, why not to move closer to object-space, and set that "rotate normal to the top is green, rotate noraml to the right is red for side parts", and for top planes (with vertical normales) "green is forvard", for bottom planes "green is backward". And if we use mirrorred horisontal texture, we do need to flip red channel, mirrored vertically = flip green.

http://i.piccy.info/i9/f6ca1555682129bc896b189b9737d74c/1433799642/44286/854143/Bezymiannyi_800.jpg (http://i.piccy.info/i9/07e96861438a64ddbbd266b6aef02870/1433799642/150393/854143/Bezymiannyi.png)http://i.piccy.info/a3/2015-06-08-21-40/i9-8321757/754x566-r/i.gif (http://i.piccy.info/a3c/2015-06-08-21-40/i9-8321757/754x566-r)

So, suppose we have slightly modificated our model's normal maps, so, go to shaders. Now open TANE\resources\Shaders\VertexSetup\DirectX11 folder, and here we need to change in files
vcx_nov.vsh, vcx_p3c01.vsh, vcx_p3c01t02.vsh, vcx_p4t02.vsh the function

float3 GetVertexTangent(in VertexIn vin){
return float3(0.0, 1.0, 0.0);
}
To function

float3 GetVertexTangent(in VertexIn vin){
return float3(1.0, 0.0, 0.0);
}, and in files vcx_p3c01n3tg3t02.vsh, vcx_p3n3t02.vsh , vcx_p3n3tg3t02.vsh replace the

float3 GetVertexTangent(in VertexIn vin){
return float3(1.0, 0.0, 0.0);
}with

float3 GetVertexTangent(in VertexIn vin){
// suppose that the "vertical" direction is always z, directed to the top
// so we are looking for bi-normal to the plane of normal and (0.0,0.0,1.0) in object's space (not in the world space!)
// because tangent is also located on this plane


float3 tangent = float3(-vin.normal.y,vin.normal.x,0.0); // un-normilised tangent (it can loose normalisation while final transformation)
//cross(vec3(0.0,0.0,1.0), vin.normal);


if(vin.normal.z > 0.99) // normal is vertical, so tangent (red channal of normal map) will be in right, or (1.0,0.0,0.0)
tangent = float3(1.0,0.0,0.0);
else if(vin.normal.z < -0.99) // normal is vertical down, so tangent (red channal of normal map) will be in left, or (-1.0,0.0,0.0)
tangent = float3(-1.0,0.0,0.0);


return tangent;


//return float3(1.0, 0.0, 0.0);
} And, also, in Shaders\Common\StdLighting.fsh in function "void DoStandardLighting(in VertexToFragment fin, *** " replace this block

normal = (normal - 0.5) * 2.0; normal = normalize(normal);




highp vec3 vNormal = normalize(GetFragInputNormal(fin));
highp vec3 vTangent = normalize(GetFragInputTangent(fin));


// Create the biNormal;
highp vec3 vBiNormal = cross(vTangent, vNormal);


highp mat3 tangentBasis = mat3(vTangent, vBiNormal, vNormal);
highp vec3 lightDir = MatMul(objectLightDir, tangentBasis);


with
normal -= 0.5; normal *= 2.0;
normal = normalize(normal);




highp vec3 vNormal = normalize(GetFragInputNormal(fin));
highp vec3 vTangent = normalize(GetFragInputTangent(fin));


// Create the biNormal;
highp vec3 vBiNormal = cross(vNormal, vTangent); //opposite order to get negative value.


highp mat3 tangentBasis = mat3(vTangent, vBiNormal, vNormal);
highp vec3 lightDir = MatMul(objectLightDir, tangentBasis);




Yes, this change will cost some extra resources, but, may be it is the easiest way untill will be found a way of regenerating im-files to this method of targeting normal maps.


In addition, change in Shaders\MaterialDefn\StdLightSphericalReflection.f sh


normal = (normal - 0.5) * 2.0; normal = normalize(normal);

highp vec3 vNormal = normalize(GetNormalInWorldSpace(fin));
highp vec3 vTangent = normalize(GetTangentInWorldSpace(fin));

// Create the biNormal;
highp vec3 vBiNormal = cross(vTangent, vNormal);

highp mat3 tangentBasis = mat3(vTangent, vBiNormal, vNormal);
highp vec3 worldNormal = mul(tangentBasis, normal);
to this

normal -= 0.5;
normal *= 2.0;
normal = normalize(normal);

highp vec3 vNormal = normalize(GetNormalInWorldSpace(fin));
highp vec3 vTangent = normalize(GetTangentInWorldSpace(fin));


// Create the biNormal;
highp vec3 vBiNormal = cross(vNormal, vTangent); // changed the order
highp mat3 tangentBasis = mat3(vTangent, vBiNormal, vNormal);
mediump vec3 worldNormal = mul(normal, tangentBasis); // be careful here = normal is multiplied on transformed matrix of tangentBasis, unlike other vectors



What does TRam think?I think it will take loooooong time for Chris for implement all this "as it should be", not adding kludges as i am doing now.

Kevin16c
June 8th, 2015, 05:22 PM
I believe your spherical and cube map code blocks ended up slightly askew mate ;)

TRam__
June 8th, 2015, 05:38 PM
I your spherical and cube map code blocksMost of them are N3V's. So, "my" spherical reflection is the last i'd like to discuss. I'd like to make them work close to previous "normals" algorithm. To set that "top of enviremental spherical map is always on the top of the model". That just makes this map's work much more predictable, than "real" reflection calculation, i.e. when the "reflected vector" is calculated and is founded its point on the spherical map. Just use te vector of the camera, and the Z component of normal to set top plane on the top of spherical map, bottom on the bottom and vertical plane to the middle of spherical map.

So, replace in Shaders\MaterialDefn\StdLightSphericalReflection.f sh this
highp vec3 incidentVector = GetCameraToVertexDirectionInWorldSpace(fin);
highp vec3 reflectDir = reflect(incidentVector, worldNormal);
reflectDir.z += 1.0;
float m = 0.5 * inversesqrt( dot(reflectDir, reflectDir) );
vec2 sphereCoords = reflectDir.xy * m + 0.5;

sphereCoords.y = - sphereCoords.y;to this

// obtaining projection on horizontal plane
// the environment map supposed to be vertical


mediump vec2 worldBiNormal = mediump vec2(worldNormal.y, -worldNormal.x);
mediump vec3 incidentVector = normalize(GetCameraToVertexDirectionInWorldSpace(f in));


// reflection map shows the color of world's direction
vec2 sphereCoords = vec2(dot(incidentVector.xy, worldBiNormal), - worldNormal.z);
sphereCoords += 1.0;
sphereCoords *= 0.5;


And the last one thing i even don't like to discuss, the adjuncments to headlight illumination to make them like this:

http://i.piccy.info/i9/bb649168b37d2e73edbe6c0686f9d046/1433633727/29394/854143/Bezymiannyi_800.jpg (http://i.piccy.info/i9/3ec6a81d49815c3264d4a4e12cc23eb8/1433633727/150771/854143/Bezymiannyi.jpg)http://i.piccy.info/a3/2015-06-08-22-40/i9-8312877/800x423-r/i.gif (http://i.piccy.info/a3c/2015-06-08-22-40/i9-8312877/800x423-r)

I've obtained that with this code in StdLighting.fsh:

#ifndef LIGHT_TYPE_MAIN
#ifdef DEPTH_ONLY
vec3 lightRayDir = fragPos - objectViewCameraPos;
#else // !DEPTH_ONLY
vec3 lightRayDir = fragPos - lightPosObject;
#endif // !DEPTH_ONLY


// Do not attenuate for other sources in such a way
float atten = 1.0;


#ifdef LIGHT_TYPE_SPOT


float lightDistSQ = dot(lightRayDir,lightRayDir);


// Attenuate.
// One over distance squared.
// (Clamp to 1.0 so atten never goes over 1.0 and we also avoid divide by zero).
// for distance ~ 20 metres
atten = 20.0/max(lightDistSQ, 20.0);


if(atten < 0.00005)
{
discard;
}


// Normalize the light dir.
lightRayDir = normalize(lightRayDir);
vec3 lightDirObject_n = normalize(lightDirObject + vec3(0.0,0.0,0.07)); // redirecting 5 degrees to the ground


float spotBase = dot(-lightRayDir, lightDirObject_n);


// we need very sharp angel, something like 14 degrees as here (cos(14/2) = 0.993)


if(spotBase < 0.993)
{
if(spotBase < 0.7)
discard;
else // this is "near" light
{
float spotIntens = (spotBase - 0.7) * 3.0;
atten *= pow(spotIntens, 5) * 30;
}

}
else
{
float spotIntens = (spotBase - 0.993)*142;
spotIntens = spotIntens * spotIntens; // need the 2nd power
spotIntens *= 1000;


//spotIntens = pow(spotIntens, lightSpotParameters.y); // power setted here is too big
// Only light if in the spot cone.
// spotIntens *= float(step(lightSpotParameters.x, spotBase)); // don't know what is lightSpotParameters.x


float spotIntens2 = (spotBase - 0.7) * 3.0;
spotIntens2 = pow(spotIntens2, 5) * 30;
atten *= max(spotIntens, spotIntens2 );


//atten *= lightIntensity; // lightIntensity is also too big


}
if(atten < 0.00005)
{
discard;
}
#endif // LIGHT_TYPE_SPOT






// Note that the ambient component is also attenuated on non-parallel lights so this has to be calculated
// regardless of shadow state.


// Increase by the intensity.
//atten *= lightIntensity;


// find the max intecity


// atten = max(atten, lightIntensity);


#endif // !LIGHT_TYPE_MAIN


#if defined(DEBUG_UNLIT) || defined(DEPTH_ONLY)
lightData.diffColor.xyz = vec3(0.6, 0.6, 0.6);
#else // !DEBUG_UNLIT && !DEPTH_ONLY

Kevin16c
June 8th, 2015, 05:54 PM
Please pardon very my poor phrasing, what I meant was the formatting of your physical code in your code blocks got slightly messed up.

Example:


#ifdef FORCE_ALPHA_ONE float reflectionStrength = texDiffColor.a * reflectionAmount * dot(lightAmbient, vec3(0.33,0.33,0.33) ); //Should be two separate lines


#else // !FORCE_ALPHA_ONE
float reflectionStrength = reflectionAmount * dot(lightAmbient, vec3(0.33,0.33,0.33) );

#endif // !FORCE_ALPHA_ONE


I was simply pointing out some of your code in the code blocks inadvertently merged two lines into one.

TRam__
June 8th, 2015, 06:03 PM
I was simply pointing out some of your code in the code blocks inadvertently merged two lines into one.And get an error with texDiffColor.a , that doesn't exist for materials with !FORCE_ALPHA_ONE. By the way all #ifdef do not consume any resources, they just collect come shaders inside one code. In case of StdLightSphericalReflection they are: m.reflect, m.gloss and m.tbumpgloss

pcas1986
June 8th, 2015, 06:05 PM
What an interesting thread! Thanks.

Wearsprada
June 8th, 2015, 10:34 PM
Nice done! Thanks.
btw, tbumpenv fixed too, now without self-luminescence in night time.

rumour3
June 9th, 2015, 01:01 AM
Very interesting- will play with this later. It would be interesting to hear from Chris on these ideas, particularly on the m.tbumpenv fix (if it works) versus a 'proper' N3V solution.

R3

WindWalkr
June 9th, 2015, 01:59 AM
You won't hear from me on this for a while. I have a fair bit of other stuff to look through first. TRam__ is obviously a smart guy, but we'll have to review each change carefully to see whether it can be useful as a general case improvement, or whether it only really works in particular scenarios. I'm sure there is plenty of room for improvement in the current material shaders; they only really exist as a stepping stone to get us TS12 compatibility and there are a lot of things still to do in the future in terms of both adding new features and also removing some of the cruft. You guys should feel free to discuss this further in the meantime, but as TRam__ says- keep in mind that this level of modification to your build WILL break patching and may also mess up your content in a lot of other ways (ie. if you tweak your shaders for a particular effect, and then make a bunch of content, it's potentially going to look very odd on everybody else's machines, or if you upgrade in the future and your changes are gone.)

chris

rumour3
June 9th, 2015, 03:19 PM
Thanks Chris

Will treat with appropriate caution.

TRam__'s normal map fix for m.tbumpenv does appear to work for me. Compare the roof of my class 31 model in the background in this shot (note the white artefacts on the cab roof):

https://c2.staticflickr.com/6/5323/18044333836_4ee547d54b_c.jpg (https://flic.kr/p/tuvVN5)
Screenshot 2015-05-25 06.12.28 (https://flic.kr/p/tuvVN5) by rumour3 (https://www.flickr.com/photos/rumour3/), on Flickr

With these, using TRam__'s modified shader:
https://c1.staticflickr.com/1/500/18464097619_831e7576e3_c.jpg (https://flic.kr/p/u8BjWF)
TANE normal map test (https://flic.kr/p/u8BjWF) by rumour3 (https://www.flickr.com/photos/rumour3/), on Flickr

I'll look out for any unwanted side effects and report back in due course.

Chris- the helpdesk has a cdp of the WIP class 31, attached to my ticket about this issue, if you're interested in seeing the difference for yourself.

R3

WindWalkr
June 9th, 2015, 06:23 PM
Thanks. Keep the feedback coming- it'll make my job easier when the time comes ;-)

chris

Dinorius_Redundicus
June 9th, 2015, 06:23 PM
Perhaps this is a good place to record a problem I have experienced with m.tbumpenv.

On objects that have some sides facing towards the ground (example: a cylinder laying horizontally) the m.tbumpenv reflection makes the under-sides a pale blue instead of a dark color expected from the ground. I think this is because the reflection comes from the sky cube map but the Trainz sky below the horizon is always a light blue. The effect is disguised somewhat in TANE with shadows on, but could it be improved at a more fundamental level by adjusting the shaders? Or would it be better if the sub-horizon sky in the cube map was simply made dark, not light?

I have no technical expertise in this area, so pardon me if this makes no sense or doesn't belong here.

ZecMurphy
June 9th, 2015, 07:49 PM
Perhaps this is a good place to record a problem I have experienced with m.tbumpenv.

On objects that have some sides facing towards the ground (example: a cylinder laying horizontally) the m.tbumpenv reflection makes the under-sides a pale blue instead of a dark color expected from the ground. I think this is because the reflection comes from the sky cube map but the Trainz sky below the horizon is always a light blue. The effect is disguised somewhat in TANE with shadows on, but could it be improved at a more fundamental level by adjusting the shaders? Or would it be better if the sub-horizon sky in the cube map was simply made dark, not light?

I have no technical expertise in this area, so pardon me if this makes no sense or doesn't belong here.

Hi Deane
Could you possibly show a screenshot of this in T:ANE?

Maybe post it in this thread, which covers some issues I've found with tbumpenv in T:ANE: http://forums.auran.com/trainz/showthread.php?119992-Tbumpenv-mapping-issues

Note, T:ANE has a 'generic'/'fixed' cubemap, which includes both ground and sky in it. It should be reflecting ground on parts facing downward, but doesn't seem overly reliable. TS12 on the other hand simply reflected the sky below the horizon (Which was basically the lowest third of the sky colour, set in the environmental settings).

Regards

Dinorius_Redundicus
June 9th, 2015, 08:49 PM
OK, this is a false alarm then, sorry. I saw these problems in TS2010 and (mistakenly) assumed the sky cube and underlying problem to be still the same in T:ANE, but maybe masked by the shadows. If the sky cube has been improved as you say, then there is no problem.

TRam__
June 14th, 2015, 07:19 AM
Another tip: how to make a "depth" for sky.

1) open Shaders\MaterialDefn\SkyBox.vsh and remove in "void EditVertex(in VertexIn vin, inout VertexOutput vertex)" the line

vertex.tex0 += txOffset;
2) open Shaders\MaterialDefn\SkyBox.fsh and replace the function "mediump vec4 GetColor0(in VertexToFragment fin)" to this


mediump vec4 GetColor0(in VertexToFragment fin){
highp vec3 skyRayDir = normalize(GetFragRawVertexPosition(fin) - objectViewCameraPos);
mediump vec2 sky_dir = normalize(GetFragInputTex0uv(fin));
sky_dir *= 0.8*(1 - skyRayDir.z); // introducing "sky depth"
sky_dir = GetFragInputTex0uv(fin) + 0.5*txOffset + sky_dir ; // the speed of clouds is too big


mediump vec4 skyColor = GetFragInputColor0(fin);
mediump vec3 modulatedFogColor = GetFragInputColor1(fin);

mediump vec4 skyBasicColor = SampleTexture(skyBasicTex, sky_dir);
mediump vec4 skyStormColor = SampleTexture(skyStormTex, sky_dir);
mediump vec4 skyNightColor = SampleTexture(skyNightTex, sky_dir);


vec4 color = mix(skyBasicColor, skyStormColor, cloudFactor); //First, blend between normal/cloudy sky.


color = mix(color, skyNightColor, nightFactor); //Finally, blend with night sky texture.

color.rgb *= skyColor.rgb * 1.5; //Modulate with the sky colour.

color.rgb += modulatedFogColor; //And add in the modulated fog colour (fog gradient transition).


return mix(color, //Finally lerp the whole sky colour
vec4(fogColor, 0.0), //towards the actual fog colour
saturate(cloudFactor)); //when weather is rainy or snowy to emulate denser fog.
}


The sky will be significantly higher, and the speed of clouds will be reduced.

Wearsprada
June 14th, 2015, 11:07 AM
Excellent, i'll try it a bit later.
Thanks.

Mick_Berg
March 28th, 2016, 11:21 AM
What an interesting thread! Thanks.

I was going to ask you if you had seen this, thought you would like it.:)
Mick

greenpine
April 2nd, 2016, 02:54 AM
Hello,


This is a very very interesting contribution. I also have the same times with the settings for the shine in the night and the "light smoke" experimented with positive results. However, even under an older build.
A big compliment to TRam__!

Before
1043
After
1044


Greetings Heiko