1 registered members (TipmyPip),
18,633
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Terrain MultiTexture Shader FOR C++ not LITE-C
#223465
08/24/08 13:36
08/24/08 13:36
|
Joined: Aug 2008
Posts: 61
Neurosys
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2008
Posts: 61
|
Ok, I used the wiki's terrain in l3td tutorial and got my terrain working while I was using SED and my .c Now I am using the engine sdk and am running all fine but I noticed my fx_terraintex3 shader isnt working (im guessing cuz im no longer using my .c file with #include "mtlFX.c" in it) I tried including mtlfx.c in my C++ project but that didnt work since its written in c-script. so the question is... how do I load the same shader I was using? here is the new code... dh.wmb is the terrain hmp after running it thru wed. #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include "adll.h" // Include the engine data types, variables, and functions
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) // application instance handle, // always zero // application command line // window flags
{
// The engine_open() function returns a pointer to a struct of
// engine variables. We don't want to load a script or level here, so we just pass NULL.
ENGINE_VARS *ev = engine_open(NULL);
if (!ev) return 1; // acknex.dll not found
//Add Content Folders Paths
add_folder("terrains");
add_folder("images");
add_folder("models");
level_load("dh.wmb");
engine_frame();
//Initialize The Graphics Environment
SETV(fps_max,60);
video_set(1024,768,32,0);
while (engine_frame()) {
//Main Loop
}
engine_close();
return 0;
}
|
|
|
Re: Terrain MultiTexture Shader FOR C++ not LITE-C
[Re: Neurosys]
#223563
08/25/08 07:24
08/25/08 07:24
|
Joined: Aug 2008
Posts: 61
Neurosys
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2008
Posts: 61
|
K so I picked thru the mtlFX.c and grabbed what I believed the be the terrain part for fx_terraintex3 and I made a C++ function to bind it to my entity (the terrain hmp) so its just like an action. The file mtlFX.c has an action that must be assigned to the hmp in wed called fx_terraintex3 and it does this : //action: fx_terraintex3
//title: Multitexture Terrain
//
//skill2: ScaleSkin2 15
//help: Skin2 base texture scale, 1..50, default 15.
//skill3: ScaleSkin3 15
//help: Skin3 red texture scale, 1..50, default 15.
//skill4: ScaleSkin4 15
//help: Skin4 green texture scale, 1..50, default 15.
//desc:
/// Blends 3 textures together, according to
/// the red and green channel in the first skin.
/// The blue channel can be used for a shadow map.
/// Skin1 = Terrain RGB blend & shadow mask.
/// Skin2 = Base tiled terrain texture (grass).
/// Skin3 = Red channel masked tiled texture (sand).
/// Skin4 = Green channel masked tiled texture (rock).
/// Skin5 = Optional base texture for non-shader hardware.
/// Skin6 = Optional detail texture for non-shader hardware.
//
//Based on ideas by Thomas 'ventilator' Oppl
//and Eric 'Steempipe' Hendrickson-Lambert
//
action fx_terraintex3()
{
// use skin 5 for non-shader hardware
if (d3d_shaderversion < 1111) {
if (ent_skins(my) >= 5) { my.skin = 5; }
return;
}
// if entity skins are missing, replace them by standard skins
mtl = mtl_terraintex3;
mtl_copy(mat_terrain);
my.material = mtl;
if (ent_skins(my) < 4) { mtl.skin4 = bmap_create("rock.tga"); }
if (ent_skins(my) < 3) { mtl.skin3 = bmap_create("sand.tga"); }
if (ent_skins(my) < 2) { mtl.skin2 = bmap_create("grass.tga"); }
// copy the texture scales to vecSkill41
if (my.skill2) { my.skill41 = floatv(my.skill2); }
else { my.skill41 = floatv(15); }
if (my.skill3) { my.skill42 = floatv(my.skill3); }
else { my.skill42 = floatv(15); }
if (my.skill4) { my.skill43 = floatv(my.skill4); }
else { my.skill43 = floatv(15); }
my.emask &= ~DYNAMIC; // when all done, set terrain static
} Now remember thats C script so its pretty useless to me here so.. I convert it to c++ and make the function/action bound to my ent like this terrain1 = ent_create("dh.hmp",_vec(0,0,0),NULL);
terrain1->event=(EVENT)giveshader;
terrain1->emask |= ENABLE_FRAME; //EVENT EVERY FRAME so heres the thing... no matter what I do it doesnt give the right look... if I dont do effect_load on the material I get the standard hmp with all its maps (RGB,sand,rock,grass) just plopped onto it. If I do effect_load on the tex3.fx I get an odd greyscale version of what the shader would look like if it was ...well.. grey.. o and BTW in mtlFX.c the MATERIAL* mtl_terraintex3 = { effect=" <blah blah blah" } .... I put that into the ttex3.fx file being loaded. Thats the right way isnt it? lol. Im trying! Anywhoz... heres my whole project code.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include "adll.h" // Include the engine data types, variables, and functions
void giveshader();
ENGINE_VARS *ev;
ENTITY *terrain1;
MATERIAL *mtl_terraintex3;
void giveshader() {
ENTITY *my;
my = (ENTITY*)ev->me;
mtl_terraintex3->skin4 = bmap_create("rock.tga");
mtl_terraintex3->skin3 = bmap_create("sand.tga");
mtl_terraintex3->skin2 = bmap_create("grass.tga");
mtl_terraintex3->skin1 = bmap_create("RGB.bmp");
//
vec_set((VECTOR*)&mtl_terraintex3->ambient_blue,(VECTOR*)&my->material->ambient_blue);
vec_set((VECTOR*)&mtl_terraintex3->specular_blue,(VECTOR*)&my->material->specular_blue);
vec_set((VECTOR*)&mtl_terraintex3->diffuse_blue,(VECTOR*)&my->material->diffuse_blue);
vec_set((VECTOR*)&mtl_terraintex3->emissive_blue,(VECTOR*)&my->material->emissive_blue);
mtl_terraintex3->power = my->material->power;
mtl_terraintex3->albedo = my->material->albedo;
//
my->material = mtl_terraintex3;
// copy the texture scales to vecSkill41
if (my->skill[2]) { my->skill[41] = floatv(my->skill[2]); }
else { my->skill[41] = floatv(15); }
if (my->skill[3]) { my->skill[42] = floatv(my->skill[3]); }
else { my->skill[42] = floatv(15); }
if (my->skill[4]) { my->skill[43] = floatv(my->skill[4]); }
else { my->skill[43] = floatv(15); }
effect_load(mtl_terraintex3,"ttex3.fx");
my->emask |= ENABLE_FRAME; //Turn that shit off once its done.
my->event=NULL;
return;
}
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) // application instance handle, // always zero // application command line // window flags
{
// The engine_open() function returns a pointer to a struct of
// engine variables. We don't want to load a script or level here, so we just pass NULL.
ev = engine_open(NULL);
if (!ev) return 1; // acknex.dll not found
level_load("");
//Add Content Folders Paths
add_folder("terrains");
add_folder("images");
add_folder("models");
engine_frame();
//Initialize The Graphics Environment
SETV(fps_max,60);
video_set(_VAR(1280),_VAR(1024),_VAR(32),_VAR(0));
//Setup The Worldscape
mtl_terraintex3 = mtl_create();
terrain1 = ent_create("dh.hmp",_vec(0,0,0),NULL);
terrain1->event=(EVENT)giveshader;
terrain1->emask |= ENABLE_FRAME; //EVENT EVERY FRAME
engine_frame();
//Stage The Camera
v(camera).z = _VAR(400);
//Main Loop
while (engine_frame()) {
//Main Loop
v(camera).z += (v(key_e ) - v(key_c)) * v(time_step);
v(camera).x += (v(key_w ) - v(key_s)) * v(time_step);
v(camera).y += (v(key_a ) - v(key_d)) * v(time_step);
v(camera).pan += _VAR((v(mouse_force).x) * 9 * v(time_step));
v(camera).tilt += _VAR((v(mouse_force).y) * 6 * v(time_step));
} //Main Loop
engine_close();
return 0;
}
|
|
|
|