Hi all,
I've been messing around with HLSL and ran into some issues with sampling. Before I describe it all I already know how to get my test shader to do what I want it to do, but I'm extremely confused as to why it doesn't work when I try to do it a different way and would really like to know why as it will fill in some clearly missing gaps I have on how sampling works.
I have two textures that are each on their own texture page. One is just a blue rectangle, the other is just a red rectangle. And I want to take a sample from each, add the color values together, and get a purple rectangle. However, when I do this I get only the blue rectangle. And what's weird about this is that if I return only the float4 that was used to store the sample from the blue rectangle then I get exactly that; the blue rectangle. Same for the red one. So each float4 used to store the sample seems to be getting the correct color. But when adding the two float4's together it will not work. Shader code below.
I already know that if I declare a second texture object to use for taking the second sample, then the two float4's will sum together to make the desired purple rectangle, but I really need to know why it doesn't work as it's written now. Can anyone help?
I've been messing around with HLSL and ran into some issues with sampling. Before I describe it all I already know how to get my test shader to do what I want it to do, but I'm extremely confused as to why it doesn't work when I try to do it a different way and would really like to know why as it will fill in some clearly missing gaps I have on how sampling works.
I have two textures that are each on their own texture page. One is just a blue rectangle, the other is just a red rectangle. And I want to take a sample from each, add the color values together, and get a purple rectangle. However, when I do this I get only the blue rectangle. And what's weird about this is that if I return only the float4 that was used to store the sample from the blue rectangle then I get exactly that; the blue rectangle. Same for the red one. So each float4 used to store the sample seems to be getting the correct color. But when adding the two float4's together it will not work. Shader code below.
GML:
struct PixelShaderInput {
float4 vPosition : SV_POSITION;
float4 vColor : COLOR0;
float2 vTexcoord : TEXCOORD0;
};
//declare the texture object.
Texture2D testTex2;
//declare the samplerstates
SamplerState testSample2;
SamplerState testSample3;
float4 main(PixelShaderInput INPUT) : SV_TARGET {
//declare the float4's
float4 BaseCol2 = 0;
float4 BaseCol3 = 0;
float4 BaseCol4 = 0;
//do the samples of the two different textures
BaseCol2 = testTex2.Sample(testSample2, INPUT.vTexcoord);
BaseCol3 = testTex2.Sample(testSample3, INPUT.vTexcoord);
//add the two floats (which ends up not working)
BaseCol4 = BaseCol2 + BaseCol3;
//return INPUT.vColor * BaseCol2; <-- if uncommented, this line returns the blue rectangle as expected
//return INPUT.vColor * BaseCol3; <-- if uncommented, this line returns the red rectangle as expected
return INPUT.vColor * BaseCol4; // <-- doesn't return the purple blended rectangle as expected, but rather the blue one.
}