//----------------------------------------------------------------------------- // --- GNNViz: PIXEL shader for terrain used in GNNViz with the Torque Shader // --- Engine // --- // --- This is a custom shader derived from the original TSE Atlas Vertex // --- shader code. It has been modified to allow for multiple detail texture // --- scales to remove tiling effects, plus a fade factor to allow terrain // --- to fade from detail texture close up to a "satellite overview" texture // --- for distant terrain. // --- // --- This shader was developed as part of the GNNViz project who's website is // --- at http://www.fsl.orst.edu/lemma/gnnviz/index.php // --- // --- For more information, contact Tim Holt at tim.holt@oregonstate.edu //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // --- Ideas for Improvement // --- // --- Need multiple detail textures applied using a blending map style // --- // --- Apply normal and parallax shaders to overview texture. The idea here is // --- that we could make the distant forest landscape be bumpy looking, which // --- would look like you were seeing the tops of the forest canopy. If you // --- think about it, when viewing a forested landscape from far away you are // --- just seeing bumpy tops of trees, not the smooth flat ground. // --- // --- Apply normal map shader to detail textures to give it more texture. // --- The normal map could be placed in the unused alpha channel. // --- // --- Store shadow information in the alpha channel of the overview texture // --- and apply it to the detail texture. When GNNViz generates a fake // --- satellite-like overview image to be used on the terrain, it also gives // --- the trees shadows. By making the unused alpha layer hold a basic 0..1 // --- level of shadow intensity, we could turn around and apply it to the // --- detail texture to shade the ground under trees. This would probably be // --- a very visually powerful addition to realism, however it would require // --- that the foliage replicator place tree models at the same locations as // --- the fake satellite overview image. That means that the code which // --- makes the fake sat image has to share the same random number generator // --- and seed as the foliage replicator. //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Structures //----------------------------------------------------------------------------- struct ConnectData { float2 texCoord : TEXCOORD0; float2 fogCoord : TEXCOORD1; float2 detailCoord : TEXCOORD2; float2 detailCoord2 : TEXCOORD3; float2 distCoord : TEXCOORD4; }; struct Fragout { float4 col : COLOR0; }; //----------------------------------------------------------------------------- // Main //----------------------------------------------------------------------------- Fragout main( ConnectData IN, uniform sampler2D diffuseMap : register(S0), uniform sampler2D fogMap : register(S1), uniform sampler2D detailMap : register(S2), uniform sampler2D detailMap2 : register(S3) ) { //-------------------------------------------------------------------------- // --- GNNViz: Pixel shader main body // --- // --- The job of this shader code is to return the actual color value to be // --- drawn at the current pixel. This code works in conjunction with the // --- vertex shader code in GNNVizAtlasSurfaceV.hlsl to decide how to // --- render the pixel data. //-------------------------------------------------------------------------- Fragout OUT; //-------------------------------------------------------------------------- // --- Compute the color contribution of the overview texture which is // --- draped over the entire Atlas terrain surface. //-------------------------------------------------------------------------- float4 overlayColor = tex2D(diffuseMap, IN.texCoord); overlayColor.a = diffuseColor.r; overlayColor.r = diffuseColor.b; overlayColor.b = diffuseColor.a; overlayColor.a = 1.0; //-------------------------------------------------------------------------- // --- Compute the amount of fog (0..1) to apply to the pixel being // --- rendered. //-------------------------------------------------------------------------- float4 fogColor = tex2D(fogMap, IN.fogCoord); //-------------------------------------------------------------------------- // --- Compute the amount of fade (0..1) between close up and distant // --- texture. //-------------------------------------------------------------------------- float4 fadeColor = tex2D(fogMap, IN.distCoord); //-------------------------------------------------------------------------- // ---- Compute the color contribution of the detail texture. // --- // --- Note that we are combining the same detail texture at two different // --- scale values here. This removes tiling in the detail texture. //-------------------------------------------------------------------------- float4 detailColor = tex2D(detailMap, IN.detailCoord); detailColor += tex2D(detailMap, IN.detailCoord2); detailColor /= 2; //-------------------------------------------------------------------------- // --- Now based on distance from viewers eye to pixel's coordinate in // --- space, blend between the overlay texture color contribution and the // --- detail texture contribution. //-------------------------------------------------------------------------- overlayColor = lerp (detailColor, overlayColor, fadeColor.a); //-------------------------------------------------------------------------- // --- Now factor in the fog contribution, interpolating between the terrain // --- color and the fog color using the fogColor alpha value as the weight. //-------------------------------------------------------------------------- OUT.col = lerp( overlayColor, fogColor, fogColor.a ); // --- original shader output calc // OUT.col = lerp(overlayColor, fogColor, fogColor.a ); return OUT; }