////////////////////////////////////////////////////////
// Water shader demo.
// Copyright 2010 by oP group Germany.
// Commercial Edition or above required for shaders
////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#include <keys.c>
#include <level.c>
#include <entmove.c>
#include <mtlFx.c>
#include <mtlView.c>
#define PRAGMA_PATH "%EXE_DIR%\\templates\\levels";
////////////////////////////////////////////////////////
var water_height,water_ripple,water_scale,hdr_threshold;
FONT* fHelp = "Arial#16bi";
PANEL* pHelp =
{
digits(5,5,"[1]/[2] -> water level: %4.1f",fHelp,1,water_height);
digits(5,20,"[3]/[4] -> wave height: %3.0f",fHelp,1,water_ripple);
digits(5,35,"[5]/[6] -> wave scale: %3.0f",fHelp,1,water_scale);
digits(5,50,"[7]/[8] -> HDR threshold: %3.0f",fHelp,1,hdr_threshold);
digits(5,65,"Cursor,PgUp/Dn -> move camera",fHelp,0,0);
flags = SHOW;
}
action on_f1_event() { toggle(pHelp,SHOW); }
action water()
{
fx_mirrorWater();
while(1) {
if(key_hit("1")) terrain_raise(me,-0.5);
if(key_hit("2")) terrain_raise(me,0.5);
// skills are defined as var, but shaders use float values
// conversion is not automatic here, thus we need floatv/fixv
if(key_hit("3")) my.skill43 = floatv(fixv(my.skill43)-5);
if(key_hit("4")) my.skill43 = floatv(fixv(my.skill43)+5);
if(key_hit("5")) my.skill44 = floatv(fixv(my.skill44)-5);
if(key_hit("6")) my.skill44 = floatv(fixv(my.skill44)+5);
if(key_hit("7")) mtl_hdr.skill2 = floatv(fixv(mtl_hdr.skill2)+1);
if(key_hit("8")) mtl_hdr.skill2 = floatv(fixv(mtl_hdr.skill2)-1);
water_height = terrain_get_z(my,1);
water_ripple = fixv(my.skill43);
water_scale = fixv(my.skill44);
hdr_threshold = fixv(mtl_hdr.skill2);
wait(1);
}
}
action blob()
{
my.skill42 = floatv(30); // texture influence
fx_envBump();
ent_rotate(me,2,1.5,0.5);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////Postprocessing Helperfunctions//////////
//////////////////////////////////////////////////
////08.03.2008////////////////by Nils Daumann/////
/////////////slindev.wordpress.com////////////////
//////////////////////////////////////////////////
//temporary pointers
VIEW* PP_Temp_View;
//Add an effect to a views stage chain
VIEW* PP_Add(MATERIAL* Material,VIEW* View,BMAP* btarget0,BMAP* btarget1,BMAP* btarget2,BMAP* btarget3)
{
//find the last view of "View"s effectchain and store its pointer
PP_Temp_View = View;
while(PP_Temp_View.stage != NULL)
{
PP_Temp_View = PP_Temp_View.stage;
}
//create a new view as the stored views stage
PP_Temp_View.stage = view_create(0);
set(PP_Temp_View.stage,PROCESS_TARGET);
//assign "Material" to the just created view
PP_Temp_View = PP_Temp_View.stage;
PP_Temp_View.material = Material;
//if a bmap is given, render the view into it
if(btarget0 != NULL){ PP_Temp_View.bmap = btarget0; }
if(btarget1 != NULL){ PP_Temp_View.target1 = btarget1; }
if(btarget2 != NULL){ PP_Temp_View.target2 = btarget2; }
if(btarget3 != NULL){ PP_Temp_View.target3 = btarget3; }
//return the pointer to the new view
return(PP_Temp_View);
}
//remove an effect from a views stage chain
int PP_Remove(MATERIAL* Material,VIEW* View,VIEW* StageView)
{
//find the view with the material selected or "StageView" and the previous view && ((StageView == NULL)+(PP_Temp_View.stage != NULL)) != 0
PP_Temp_View = View;
while(PP_Temp_View.material != Material)
{
View = PP_Temp_View;
PP_Temp_View = PP_Temp_View.stage;
//return one if the stage doesn´t exist
if(PP_Temp_View == NULL){return(1);}
}
//pass the views stage to the previous view
View.stage = PP_Temp_View.stage;
//pass the render target
View.bmap = PP_Temp_View.bmap;
View.target1 = PP_Temp_View.target1;
View.target2 = PP_Temp_View.target2;
View.target3 = PP_Temp_View.target3;
//reset the views bmap to null
PP_Temp_View.bmap = NULL;
PP_Temp_View.target1 = NULL;
PP_Temp_View.target2 = NULL;
PP_Temp_View.target3 = NULL;
//remove the view
ptr_remove(PP_Temp_View);
PP_Temp_View=NULL;
//return null if everything worked
return(0);
}
//remove all postprocessing from the view
void PP_Remove_All(VIEW* View)
{
if(View.stage == NULL){return;}
PP_Temp_View = View.stage;
View.stage = NULL;
View.bmap = NULL;
while(PP_Temp_View.stage != NULL)
{
View = PP_Temp_View;
PP_Temp_View = View.stage;
//pass the views stage to the previous view
View.stage = NULL;
//reset the views bmap to null
View.bmap = NULL;
//remove the view
ptr_remove(View);
}
}
/////////////////////////////////////////////////////////////////////////
function main()
{
if (d3d_shaderversion<2020)
error("Shaders require Commercial Edition!");
d3d_antialias = 4;
//video_set(1920,1080,32,1);
video_set(1280,720,32,0);
fps_max = 60;
// load a level, and create sky, water, and a model :
level_load("small.hmp");
ent_createlayer("skycube+6.dds",SKY | CUBE | SHOW,1);
//ent_createlayer("555.tga",SKY | CUBE | SHOW,1);
//camera.fog_start = 10 ;
//camera.fog_end = 2000 ;
//d3d_fogcolor1.red = 255 ;
//d3d_fogcolor1.green = 180 ;
//d3d_fogcolor1.blue = 20 ;
//fog_color = 1 ;
ent_create("water.hmp",vector(0,0,-5),water);
ent_create("blob.mdl",vector(0,0,30),blob);
vec_set(sun_color,vector(200,240,240));
// set up some parameters and a HDR effect for the camera
vec_set(camera.x,vector(-130,0,80));
camera.tilt = -20;
def_move(); // activate flythrough
mtl_hdr.skill3 = floatv(50); // exposure compensation factor
PP_Add(mtl_hdr,camera,NULL,NULL,NULL,NULL);
PP_Add(mtl_erode,camera,NULL,NULL,NULL,NULL);
}