Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Two textures in a shader ?

$
0
0

@willmotil wrote:

So i suck with shaders in monogame i really haven't messed with them too much.
Im trying to get two textures to run in a simple shader.
However the second texture sampler is filled with zeros it seems when i try to read its alpha.
I have no clue why?
Further im not really all to sure what the registers do here especially with multiple textures.
I was never that good to begin with at shader semmantics in xna or hlsl, in monogame im even more confused. Any help or explinations are appreciated feel free to get as short or long winded as you wish.

//_______________________________
// basic shader
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

Texture2D TextureA : register(t0);
sampler TextureSamplerA : register(s0)
{
    Texture = (TextureA);
};

Texture2D TextureB : register(t0);
sampler TextureSamplerB : register(s1)
{
    Texture = (TextureB);
};

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
    float2 TexureCoordinate : TEXCOORD0;
};
struct VertexShaderOutput
{
    float4 Position : SV_Position;
    float4 Color : COLOR0;
    float2 TexureCoordinate : TEXCOORD0;
};
struct PixelShaderOutput
{
    float4 Color : COLOR0;
};

VertexShaderOutput VertexShaderFunctionB(VertexShaderInput input)
{
    VertexShaderOutput output;
    output.Position = input.Position;
    output.Color = input.Color;
    output.TexureCoordinate = input.TexureCoordinate;
    return output;
}

// arrgg humm 
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
    PixelShaderOutput output;
    // test
    float4 ca = tex2D(TextureSamplerA, input.TexureCoordinate) * input.Color;
    // cb is filled with zeros ?
    float4 cb = tex2D(TextureSamplerB, input.TexureCoordinate) * input.Color;
    if (cb.a > 1) ca.rgba = 250;
    output.Color = ca;
    //
    return output;
}
technique BlankTechniqueB
{
    pass
    {
        VertexShader = compile VS_SHADERMODEL VertexShaderFunctionB();
        PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
    }
}

Posts: 6

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles