Wednesday 14 March 2012

Oil Pollution Refinement

Previously I was just using a simple linear texture for the oil pollution effect, which was just an appropriation of the realistic color spectrum.  Since I have talked to a Graduate Student from the UVic Graphics Department (credit will be given for the help) about the actual pyhsics of the appearance of oil slicks.  The color spectrum at the borders of large scale oil spills, or small puddles on roads are from the distortion of light traveling through the material.  Basically the change in color is a function of the viewing angle, and the thickness of the oil on the water.



I have created a simple 2d color spectrum map, that for each vertex I determine the sampling point from the viewing angle relative to the camera, and an oil weight value which spreads to neighboring pixels.  This effect is a very basic approximation of the real physics, but gives a nice effect very efficiently.




My water is rendered as a solid color, which transitions to a dulled reflection as the viewing angle decreases.  The water system has the potential for more detail, I will be adding in the reflections of the land, smoke, and models on the water as well as a simple bump map that will give the effect of smaller sub waves.  The water can also recognize nodes that are underground, which will be culled and set to inactive, which can be anchors for smooth wave transitions to the land.  (pollution and waves will then not spread through land)

The smoke in this scene is an adaptation of the steam system.

Steam System Finalization

In XNA 4.0 there is a common problem with rendering point sprites with Alpha Blending.  For the Steam System I am using Alpha Blending vs Additive Blending because it is crucial to give the clouds the needed voluminous effect.  Additive Blending looks great for the darker exhaust, but for particles that are more detailed and fade out from center, Alpha Blending is the right choice.

As each pixel is written to the Z-Buffer, even those with full alpha, normal rendering results are box artifacts around point sprites for certain camera orientations. These artifacts occur when point sprites are drawn out of order, (relative to the camera position) but even if the list is sorted, the artifacts are extremely visible when two particles have the same distance.  The solution to this problem is to disable writing to Z-Buffer, but maintaining the read function, so the point sprites do not show through other objects in the scene.

This simple solution still has problems with my steam system.  After particles spawn, they fade out linearly until their transparency value is 0.  The sprites are rendered correctly when viewed from the front of the chain, but appear hollow from behind.  This requires that the list needs to be sorted relative to the camera.  From behind the point sprites with the most opacity are drawn last, so the over all effect appears to be a smoke funnel, which is a nice effect, but is not what I am looking for.

As the collection of Point Sprites is a linked list, I can simple choose draw from start or draw from end depending on the position of the camera relative to the spawn point and the wind direction.  This looks fine except at the point where the order changes, there is a very obvious shift in the smoke column because of the details in the steam clouds, and the faded borders necessary to give the steam volume.

My solution to this transition point is to multiply the color of each smoke cloud by the dot product of the vector between the camera and the spawn point, and the wind vector.  This gives a smooth blending as you rotate around the steam column, but the steam only renders fully when viewed exactly from behind or in front.  Make the transition quadratic preserves the full volume effect longer and then quickly changes to the fade transition.

The following video shows these problems:


The transition ends up becoming very white, but I am able to specify the color of the transition to match the color of the smoke.  I am also slightly reducing the size of the point sprites at the transition, otherwise it appears that they grow in the transition.  After balancing these different functions and constant scalars, I have been able to produce steam columns that have volume, texture, and transition smoothly for all orientations.

Using multiple emitters, each emitter must be sorted by its relative position to the camera.  The number of emitters should be very small, (unless the implementation is showing an over all view of the Tar Sands or the coal plants in China)  Unfortunately there is an obvious shift at the transition point, but most of the time this is not too noticeable, and for my purposes this artifact can be tolerated, as it can be avoided.



The second part of this video is integrating the factory with a land map created with my terrain editor.  As particles spawn and dissipate, they effect the land by saturating nearby vertices. 

Saturday 10 March 2012

Light System Finalization

I have continued to work on refining the light system, and have made improvements on the initial implementation.  As this is the end of this part of the development, I will re iterate over the details of the entire system.



Light Sources:
Light sources are defined in texture map.  Areas with high alpha are light sources.  The more transparent a pixel is the more light it will "emit"   This allows me to specify very detailed and unique light sources.  Light colors can also be defined in the texture.  Light sources will be saturated in the bloom process, so I define the colors in the texture map to be very desaturated, so when there is no light, the sources will be rendered gray.


Basic Method:-Draw Each model, preserving alpha values of light sources to final render
-On New Layer:  Extract pixels with alpha values less than 1 from scene
(this layer is half the size, for efficiency)
-Perform Gaussian Blur on light map

Problems:
-As the light sources of the model are drawn with transparency, you can see through parts of the model.
-Each model with light must be drawn black before the light sources are drawn, so they will not appear to be transparent.



Distance Problem: (both methods)
-As the light sources get farther away, there are less pixels for the Gaussian Filter to sample from.  The light sources appear to dissipate very quickly, especially with a render layer that is half the screen size.
-Filters with larger kernels look much better close up, but dissipate more quickly
-Filters with small kernel sizes still give a good light effect close up, and remain longer, but still dissipate too quickly.
-No filter looks bad close up, but remains over long distances.

This video shows these different cases:


To solve this problem, I use a very small kernel size (which also more efficient) and I draw the light source on the model at full resolution, and then perform the bloom process on the extracted light map.  At close distances only the bloomed light source is visible, and at the farther distances when the bloom dissipates you can still see the light source on the model.


Another goal of the light system is to allow for animations.  Each model will have a variable that will acount for the saturation and value of its light sources.  These variables can be set to be completely on or off, or for a blinking effect of the lights.



Final Process
-Draw each Model normally.  (Draw light sources more grey, this is what will be seen when the lights are off)
-If model has light, draw light pass:
  • For every pixel in texture that has alpha = 1, draw full transparency black
  • If pixel has transparency, saturate and increase brightness by alpha weight, then set final alpha value to light value.  (If light source is off, the second pass will not appear, if light value is full, second pass will be rendered over the model)
  • The alpha values of light sources still have to be less than 1 to be extracted.
-Run Light Extract pass over rendered Scene, for any pixel with any alpha, saturate to preserve color.  All other pixel are black.
-Preform Light Bloom pass on light map
-Combine bloomed light map with rendered Scene

This video shows the results of the final process.


There is still room for improvement in aesthetics with the process variables, and some of these will be able to be set in each model for diverse effects.



Light Motion Blur
-A simple feature that gives a nice effect, but may not be desirable
-Before combining Blurred Light map with final scene, save render layer as texture
-Next pass draw light map along with previous bloomed light map with partial transparency, to ensure that the previous map will dissipate.
-This effect is not very noticeable at farther distances.

Initial Land Modification and Dirt Movement

One of my main inspirations for this project was to create a program where a user could control an Excavator and physically alter the land in the environment.  This process is one of the main foundations for this project.  Alteration includes height modification, texture deformation, and color desaturation.  (Shifting colors towards grey)

This feature still has some smoothing out to do.  For realistic implementation, IE a large land map with small machines, subdivisions will be required for accurate results.  Implementing efficient subdivision is a goal for this project, but it will be very tricky to keep an efficient system for seamless alteration. 




Another related system to the excavator simulation is falling dirt from the bucket of the machine.  So far I have a simple implementation using a texture band that has a beginning, looping middle, and end texture.  The falling dirt adds also back into the land map where it falls.  This system is quite simple to implement in conjunction with the excavation process.  For each update I am already checking what grid space the bucket is above, and the distance from the ground surface.  These are the only external parameters needed for the falling dirt.

This gives a nice effect, but is not quite realistic enough.  I am going to work on implementing this effect with more dynamic point sprites that are also partially animated.  Though this current system is still quite useful, as it could be easily adapted to be used for a conveyer belt system (part of any mining operation or processing facility)