D
Darius Pranskus
Guest
Hi experts
I am experimenting with the possibility of using normal map textures to enhance the look and feel of my sprites. So I created tree objects - a circle, a square and a star. l of them rotate in Step event.
Also I use a custom shader to use the normal maps, which I prepare it in create event of each object, use it in the DrawBegin event and then reset in DrawEnd event. For example if we take a square object:
Create event
DrawBegin event
DrawEnd event
Step event
The problem I am facing is that even I pass different textures with texture_set_stage for individual objects, all of my objects use the last normal map texture.
My understanding is that texture_set_stage function just sets some stage in the GPU, and because it is the same for each object, that's why it uses it for all of them.
I am still pretty new to GM and shaders, could someone help me what approach should i take to ensure that my shader uses different textures for each object.
I tried to duplicate the shader and use a copy of it on each object, tried to use different names for texture variables but with no luck.
I am evaluating the GMS at the moment and I am about to purchase it if this issue is sorted.
I also uploaded a sample project to illustrate this. Please find it here https://bit.ly/35JEN3K
Thank youy very much
Darius
I am experimenting with the possibility of using normal map textures to enhance the look and feel of my sprites. So I created tree objects - a circle, a square and a star. l of them rotate in Step event.
Also I use a custom shader to use the normal maps, which I prepare it in create event of each object, use it in the DrawBegin event and then reset in DrawEnd event. For example if we take a square object:
Create event
Code:
//shader uniforms
light_dir_uniform = shader_get_uniform(shNormal, "light_dir");
normal_tex_uniform = shader_get_sampler_index(shNormal, "normal_tex");
//direction light is pointing to, i.e. opposite direction light is coming from.
//light direction is normalized inside vertex shader
light_x = -10;
light_y = 3;
light_z = 50;
//used to keep track of the current texture assigned to shader normal sampler "normal_tex"
//so that we can avoid resetting it unless the texture will change
normal_tex = sprite_get_texture(sprSquareN, 0);
Code:
shader_set(shNormal)
shader_set_uniform_f(light_dir_uniform, light_x, light_y, light_z);
texture_set_stage(normal_tex_uniform, normal_tex);
Code:
shader_reset()
Code:
image_angle += 1;
image_angle = image_angle % 360;
image_alpha = degtorad( image_angle ) / ( 2 * pi );
The problem I am facing is that even I pass different textures with texture_set_stage for individual objects, all of my objects use the last normal map texture.
My understanding is that texture_set_stage function just sets some stage in the GPU, and because it is the same for each object, that's why it uses it for all of them.
I am still pretty new to GM and shaders, could someone help me what approach should i take to ensure that my shader uses different textures for each object.
I tried to duplicate the shader and use a copy of it on each object, tried to use different names for texture variables but with no luck.
I am evaluating the GMS at the moment and I am about to purchase it if this issue is sorted.
I also uploaded a sample project to illustrate this. Please find it here https://bit.ly/35JEN3K
Thank youy very much
Darius