//
//This file is part of Caelum.
//See http://www.ogre3d.org/wiki/index.php/Caelum 
//
//Copyright (c) 2006-2007 Caelum team. See Contributors.txt for details.
//
//Caelum is free software: you can redistribute it and/or modify
//it under the terms of the GNU Lesser General Public License as published
//by the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//Caelum is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public License
//along with Caelum. If not, see <http://www.gnu.org/licenses/>.
//

// Base class for materials in the caelum demo.
// They have a main pass and additional fog passes.
// Perhaps might be better to do this at runtime somehow?
material CaelumDemoBase
{
	technique
	{
	    pass Main
	    {
	        fog_override true none
	    }

	    // Haze pass
	    pass CaelumHaze
	    {
		    vertex_program_ref CaelumHazeVP
		    {
		    }
		    fragment_program_ref CaelumHazeFP
		    {
		    }

		    lighting off
		    scene_blend alpha_blend
		    fog_override false

		    texture_unit
		    {
			    texture AtmosphereDepth.png 1D
			    tex_address_mode clamp clamp clamp
		    }
		    texture_unit
		    {
			    texture EarthClearSky2.png
			    tex_address_mode wrap clamp clamp
		    }
	    }
    	
	    // Ground fog pass.
	    pass CaelumGroundFog
	    {
		    vertex_program_ref CaelumGroundFogVP
		    {
		    }
    		
		    fragment_program_ref CaelumGroundFogFP
		    {
		    }
    		
		    lighting off
		    //depth_write off
		    //colour_write off
		    scene_blend alpha_blend
	    }
    }
}

vertex_program Caelum/SampleTerrainVP cg
{
	source CaelumSample.cg
	entry_point MainVP
	profiles vs_2_0 arbvp1
	compile_arguments -posinv

	default_params
	{
		param_named_auto worldviewproj_matrix worldviewproj_matrix
		param_named_auto inverse_transpose_worldview_matrix inverse_transpose_worldview_matrix
	}
}

fragment_program Caelum/SampleTerrainFP cg
{
	source CaelumSample.cg
	entry_point MainFP
	profiles ps_2_x arbfp1
	
	default_params
	{
	    param_named_auto derived_scene_colour derived_scene_colour
	    param_named_auto light_position_view_space_0 light_position_view_space 0
	    param_named_auto light_position_view_space_1 light_position_view_space 1
	    param_named_auto derived_light_diffuse_colour_0 derived_light_diffuse_colour 0
	    param_named_auto derived_light_diffuse_colour_1 derived_light_diffuse_colour 1
		param_named texture1_scale float2 20 20
		param_named texture2_scale float2 100 100
	}
}

// Common terrain for caelum samples.
// Diffuse only lighting for two lights.
material CaelumSampleTerrain: CaelumDemoBase
{
	technique
	{
	    // Main terrain pass.
		pass Main
		{
		    ambient 1 1 1
		    diffuse 1 1 1
		    
		    vertex_program_ref Caelum/SampleTerrainVP
		    {
		    }

		    fragment_program_ref Caelum/SampleTerrainFP
		    {
		    }
		    		    
			texture_unit
			{
				texture terrain_dirt-grass.jpg
			}

            texture_unit
            {
                texture terrain_detail.jpg
            }
		}
	}
}