Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/home/shadbb/domains/czub.info/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/home/shadbb/domains/czub.info/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/home/shadbb/domains/czub.info/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Generate Sky & Sun in Ray Marching algorithm is very simple to process.
When the map procedure don’t intersect a scene obiect (In my shader Hit variable is false) gl_FragColor set to background color.
Is simple way to create it:
- First define te Sun structure:
struct Sun {
vec3 posistion;
vec3 color;
float haloSize;
float haloPower;
float discSize;
float discPower;
float discArea;
float horizontal;
};
Sun sunLight=Sun(vec3(-0.2, 0.2, -0.4),vec3(1.0,1.0,1.0), 100.0, 0.3, 100.0, 1.5, 0.9, 5.0); |
struct Sun {
vec3 posistion;
vec3 color;
float haloSize;
float haloPower;
float discSize;
float discPower;
float discArea;
float horizontal;
};
Sun sunLight=Sun(vec3(-0.2, 0.2, -0.4),vec3(1.0,1.0,1.0), 100.0, 0.3, 100.0, 1.5, 0.9, 5.0);
- Test the intersect a scene object:
Object sceneObject=rayMarching(ray, rayDir);
vec3 outColor=vec3(0.0, 0.0, 0.0);
if (sceneObject.hit){
...
outColor=outColor * lightColor * baseShadow + sceneObject.mat.ambient;
} else {
outColor=getSky(sceneObject, ray, rayDir);
}
gl_FragColor=vec4(outColor.r, outColor.g, outColor.b, 1.0); |
Object sceneObject=rayMarching(ray, rayDir);
vec3 outColor=vec3(0.0, 0.0, 0.0);
if (sceneObject.hit){
...
outColor=outColor * lightColor * baseShadow + sceneObject.mat.ambient;
} else {
outColor=getSky(sceneObject, ray, rayDir);
}
gl_FragColor=vec4(outColor.r, outColor.g, outColor.b, 1.0);
- If intersect is false result generate background color in the getSky function:
vec3 getSky(Object sceneObject, vec3 ray, vec3 rayDir){
vec3 skyColor=vec3(0.0);
float horizontHeight = pow(1.0-max(rayDir.y,0.0), sunLight.horizontal);
skyColor=mix(vec3(0.0, 0.0, 0.5), vec3(1.0, 0.0, 0.0), horizontHeight);
#if ENABLE_SUN==1
float sunAmount = max(dot(rayDir, normalize(sunLight.posistion)), 0.0);
// Sun Halo
skyColor = skyColor + sunLight.color * pow(sunAmount, sunLight.haloSize) * sunLight.haloPower;
// Sun Disc
skyColor = skyColor + sunLight.color * min(pow(sunAmount, sunLight.discSize) * sunLight.discPower, sunLight.discArea);
#endif
return clamp(skyColor, 0.0, 1.0);
} |
vec3 getSky(Object sceneObject, vec3 ray, vec3 rayDir){
vec3 skyColor=vec3(0.0);
float horizontHeight = pow(1.0-max(rayDir.y,0.0), sunLight.horizontal);
skyColor=mix(vec3(0.0, 0.0, 0.5), vec3(1.0, 0.0, 0.0), horizontHeight);
#if ENABLE_SUN==1
float sunAmount = max(dot(rayDir, normalize(sunLight.posistion)), 0.0);
// Sun Halo
skyColor = skyColor + sunLight.color * pow(sunAmount, sunLight.haloSize) * sunLight.haloPower;
// Sun Disc
skyColor = skyColor + sunLight.color * min(pow(sunAmount, sunLight.discSize) * sunLight.discPower, sunLight.discArea);
#endif
return clamp(skyColor, 0.0, 1.0);
}
- To create more funny effect – where intersect if true, create a halo effect in post processing (in future).
Example of this sun effect:




Możliwość komentowania jest wyłączona.