mellinoe / veldrid-samples

Sample projects for Veldrid
https://mellinoe.github.io/veldrid-docs/
121 stars 49 forks source link

Cant work with multiple textures in shaders #27

Closed BarisUckardes closed 3 years ago

BarisUckardes commented 3 years ago

Having a difficult time when i try use multiple resources.

Now, i have three images

->Pacman image (First Image) ->Flower image (Second Image) ->Brick image (Third Image)

i want to overlay and mix them in my fragment shader, but when i bind multiple textures it always falls back to the first image i bind.

For example

+If i only output the color of the pacman image it outputs correctly +if i sample pacman image and then output flower image, it outpus correctly +if i sample both pacman and flower image output brick image,it outputs correctly

BUT !

+if i dont sample pacman and try to output flower or brick texture, output color always fallsback to pacman image

This is my fragment shader code

` private const string FragmentCode = @"

version 450

                                        layout(location = 0) in vec2 tex_coords;
                                        layout(location = 0) out vec4 fsout_Color;

                                        layout(set = 1,binding = 1) uniform texture2D pacManTexture;
                                        layout(set = 1,binding = 2) uniform sampler pacManSampler;

                                        layout(set = 2,binding = 1) uniform texture2D flowerTexture;
                                        layout(set = 2,binding = 2) uniform sampler flowerSampler;

                                        layout(set = 3,binding = 1) uniform texture2D brickTexture;
                                        layout(set = 3,binding = 2) uniform sampler brickSampler;

                                        void main()
                                        {
                                            //fsout_Color =texture(sampler2D(pacManTexture,pacManSampler),tex_coords);
                                            //fsout_Color = texture(sampler2D(flowerTexture,flowerSampler),tex_coords);
                                            fsout_Color =texture(sampler2D(brickTexture,brickSampler),tex_coords);

                                        }";

` This image outpus the first image which is the first resource set that i bind to fragment shader stage.

This is how i create my texture,textureView,resourceLayout and resourceSets

image

I must be missing something vital here or is this some kind of bug.

My guess is doing something wrong with resource sets or layout set&binding numbers in the fragment shader

BTW I tried both opengl and dx11 backend i did no difference