3D Drawing Terrain and Effects to diffrent surfaces

Kentae

Member
Hi guys... I must admit defeat on this one.
(Not sure if the title explains the problem well but I couldn't come up with a better one)

So what I'm trying to do:
Draw my terrain, with multitexture and diffuse light, to a surface.
Draw the specular effect on the terrain to a second surface.
Get them to display as normal in my game.

I use my own multitexture shader with diffuse lighting to draw my terrain normally and this works perfectly for as long as I'm not drawing it to a custom surface.
The specular shader I use also works perfectly and usually I'd just have them combined into one.
But I want to add a mask of sorts to the specular effects and to do this I need to pass in one mask texture for each of the textures used in the multitexture shader.
The problem is that, if I've gotten this right, you can only pass in 8 textures at a time to a shader (for windows) and the multitexture already uses 5 of these slots... 4 for the different textures and 1 for the blend map.
This leaves 3 wich is not enough as I need 4 (1 for each texture used by the multitexture shader).

So I thought it would be best to render in two go's.
First the textured terrain then the specular effect.

But for some reason the terrain does not draw at all when I use surfaces.
My guess is that I'm just using surfaces wrong as I'm not all that familiar with them yet.

Here's my code so far:
Code:
// RENDER -- TERRAIN ###############################

// set a surface to draw the terrain to (create it if it doesn't exist)
if !surface_exists( surf_terrain ) then
    {
    surf_terrain = surface_create( 2048, 2048 );
    surface_set_target( surf_terrain );
    draw_clear( c_white );
    }
else
    {
    surface_set_target( surf_terrain );
    draw_clear( c_white );
    }

// set multitex shader
shader_set( sh_terrain_multitex );
// pass in multitex uniforms
texture_set_stage( u_baseTex, texBase );
texture_set_stage( u_rTex, texR );
texture_set_stage( u_gTex, texG );
texture_set_stage( u_bTex, texB );
texture_set_stage( u_blendMap, texBM );

// draw terrain
with ( obj_world )
    { event_user( 0 ); }

// reset multitex shader
shader_reset();
// reset drawing surface
surface_reset_target();


// set a surface to draw the specular to (create it if it doesn't exist)
if !surface_exists( surf_terrain_spec ) then
    {
    surf_terrain_spec = surface_create( 2048, 2048 );
    surface_set_target( surf_terrain_spec );
    draw_clear( c_white );
    }
else
    {
    surface_set_target( surf_terrain_spec );
    draw_clear( c_white );
    }

// set specular shader
shader_set( sh_terrain_specular );
// pass in specular uniforms
shader_set_uniform_f( u_reflection, 0.3 );
shader_set_uniform_f( u_shineDamping, 15.0 );

// draw terrain
with ( obj_world )
    { event_user( 0 ); }

// reset shader
shader_reset();
// reset drawing surface
surface_reset_target();


// tried adding these later on but to no effect
draw_surface( surf_terrain, 0, 0 );
draw_surface( surf_terrain_spec, 0, 0 );
I'm using GMS 1.4 and Windows 7.

Any help or pointers would be greatly appreciated :)

EDIT: Oh and I forgot to mention... I just haven't added the mask textures yet... figured I'd get it working normally first :)
 
Top