DUBBELFISK
Member
Hello,
I'm creating a 3D FPS game in GMS2 with doom-like graphics (all enemies are planes facing you etc).
I've made a simple shader that I'm using to manipulate the world. It looks like this:
time is just a uniform float that increases each step.
This creates a cool effect that wobbles the entire world and I use this when I draw the entire geometry of my game like this:
what I'm drawing here (vb_walls) is a vertex buffer with all the world geometry in it.
My problem occurs when I'm drawing all the other objects in the game (like enemies).
I want the shader to apply to them as well, however their movement does not sync with the world geometry movement.
Right now I'm drawing them in the same place as the previous code, just going through all of them and drawing their vertex buffers with their own matrix:
I'm quite new to both 3D in GMS2 and the vertex shader. (have worked a bit with fragment shaders before)
Does anyone know how I would solve this?
Sorry If I'm not explaining my problem good enough.
I guess my main issue is trying to sync the shader effect to multiple vertex buffers (with different matrixes)
I'm creating a 3D FPS game in GMS2 with doom-like graphics (all enemies are planes facing you etc).
I've made a simple shader that I'm using to manipulate the world. It looks like this:
Code:
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
object_space_pos.z -= sin(0.01*(time+in_Position.x))*8.0;
object_space_pos.x -= sin(0.01*(time+in_Position.y))*8.0;
object_space_pos.y -= sin(0.01*(time+in_Position.x))*8.0;
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}
This creates a cool effect that wobbles the entire world and I use this when I draw the entire geometry of my game like this:
Code:
shader_set(shd_3D);
shader_set_uniform_f(u_t,time);
var mat = matrix_build(0, 0, 0, 0, 0, 0, 1, 1, 1);
matrix_set(matrix_world, mat);
//Draw the buffer
vertex_submit(vb_walls, pr_trianglelist, sprite_get_texture(wall_sprite, wall_ii));//surface_get_texture(surf));//
shader_reset();
My problem occurs when I'm drawing all the other objects in the game (like enemies).
I want the shader to apply to them as well, however their movement does not sync with the world geometry movement.
Right now I'm drawing them in the same place as the previous code, just going through all of them and drawing their vertex buffers with their own matrix:
Code:
//DRAW ENEMIES
if(instance_exists(obj_enemy_parent))
{
var _enemies = instance_number(obj_enemy_parent);
for(i=0;i<_enemies;i+=1)
{
var _tmp_enemy = instance_find(obj_enemy_parent,i);
matrix_set(matrix_world,_tmp_enemy.matrix);
vertex_submit(_tmp_enemy.vb_plane,pr_trianglelist,sprite_get_texture(_tmp_enemy.sprite,_tmp_enemy.ii));
//matrix_set(matrix_world, matrix_build_identity());
}
}
I'm quite new to both 3D in GMS2 and the vertex shader. (have worked a bit with fragment shaders before)
Does anyone know how I would solve this?
Sorry If I'm not explaining my problem good enough.
I guess my main issue is trying to sync the shader effect to multiple vertex buffers (with different matrixes)