gosu / ashton

Special graphical effects and other extensions for the Ruby/Gosu game library (⚠️ unmaintained)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature (or documentation) request: Multiple sampler2D's in one shader

runnerpack opened this issue · comments

commented

I want to do per-pixel lighting of sprites using a normal map, but I don't know how to get both diffuse and normal maps into the fragment shader at once using Ashton.
Is this already possible by e.g. assigning a Gosu::Image or Ashton::Texture to the shader as a uniform?

Ashton supports mult-texturing, but only 2 textures at a time. The way you do this is to set the multitexture value to the second one we want to supply to the draw action:

my_shader = Shader.new fragment: my_fragment_shader, vertex: :multitexture2
my_texture_or_image_1.draw ...args..., shader: my_shader, multitexture: my_texture_or_image_2

Within your fragment shader, you would access two textures and uv values (I recommend you use the :multitexture2 vertex shader with your own , which is provided for you: https://github.com/Spooner/ashton/blob/master/lib/ashton/shaders/multitexture2.vert).

An example of simple multi-texturing is provided in the examples: https://github.com/Spooner/ashton/blob/master/examples/stencil_shader_example.rb

commented

See, that shows how new I am to this stuff; I didn't even know what to search for xD
Thanks, Spooner!