Unable to get proper vec4 value in uniform for frag shader #1088
Replies: 1 comment 1 reply
-
Hi Sam,
I'm wondering if you have fallen for the classic structure packing problem
(I certainly have). Shader structures are packed to 16 byte boundaries, so
your structure
layout(binding = 1) uniform Switch
{
int useTexture;
vec4 flatColor;
} switchData;
is probably getting 12 bytes extra padding between useTexture and
flatColor, which isn't accounted for when you load it on the CPU side. A
simple test would be to put an extra 3 x int dummy values in before
flatColor, or to switch useTexture and flatColor around so that flatColor
packs first (don't forget to do it in c++ code and in the shader).
Worth a try.
Cheers,
Roland
…On Tue, 20 Feb 2024 at 13:19, Sam Brkopac ***@***.***> wrote:
Here is an example program that shows my issue
<https://gist.github.com/sbrkopac/18ae8880ea7cc33e889f197a2be0490d>. I'm
trying to add a "switch" to a uniform that is 1 or 0 and has a vec4 value
associated with it. If it's 0 I want to use the vec4 as the color for the
mesh rather than the texture.
I've been starting to use RenderDoc and when I look at a frame, I see the
following:
image.png (view on web)
<https://github.com/vsg-dev/VulkanSceneGraph/assets/1939712/c3f05793-2b30-45e2-a3dd-7c84591fb638>
Note that I'm expecting vec4(1.0f, 1.0f, 0.0, 1.0f)
When I look at the FS in RenderDoc:
image.png (view on web)
<https://github.com/vsg-dev/VulkanSceneGraph/assets/1939712/9ec309b5-6cd4-4e29-ab53-b41594ae9218>
I believe I'm doing everything cleanly in the VSG side. Extra eyes would
be great.
Thanks!
—
Reply to this email directly, view it on GitHub
<#1088>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPOEQ2U4M7AOTKY3WQOL7LYUQBZTAVCNFSM6AAAAABDQK4OS6VHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGI2DEMJUHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sbrkopac
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here is an example program that shows my issue. I'm trying to add a "switch" to a uniform that is 1 or 0 and has a vec4 value associated with it. If it's 0 I want to use the vec4 as the color for the mesh rather than the texture.
I've been starting to use RenderDoc and when I look at a frame, I see the following:
Note that I'm expecting
vec4(1.0f, 1.0f, 0.0, 1.0f)
When I look at the FS in RenderDoc:
I believe I'm doing everything cleanly in the VSG side. Extra eyes would be great.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions