[SOLVED] To move from Pixel Shader to Vertex Shader


Since few month I use pixel shader on my rendertarget2D and that worked perfectly. Thx to kosmonautgames :wink:

But now I want to draw textured quad with primitives and perspectiveFieldOfView.

To draw my quad I use this method :

I tried to keep my way todo with rendertarget2D. But nothing :frowning:

So I think I need to use vertex shader and pixel shader but it doesn’t work too.
Vertex :

 struct VertexIn
    float4 Position : SV_POSITION0;
    float4 VertexColor  : COLOR0;
    float2 TexCoord : TEXCOORD0;

struct VertexOut
    float4 Position : SV_POSITION0;
    float4 VertexColor  : COLOR0;
    float2 TexCoord : TEXCOORD0;

VertexOut VS(VertexIn vin)
    VertexOut vout;
   // Here I try a lot of thing to test

    float4 worldPosition = mul(vin.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    vout.Position = mul(viewPosition, Projection);
    float4x4 WorldViewProjection = View*Projection;
    vout.Position = vin.Position;// (float4(vin.Position.x, vin.Position.y, 500.0, 1.0));// , WorldViewProjection);
                                                                         //vout.Position = vin.Position;// , WorldViewProjection);
    vout.TexCoord = vin.TexCoord;

    return vout;

Pixel :

float4 SimplePointLightPS(float4 Position : SV_Position, float4 Color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 //VertexOut pin) :SV_TARGET//
    float halfMagnitude = length(float3(texCoord.xy,500) - float3(0.5, 0.5,0));// pin.TexCoord.xy

    float alpha = (PointLightZ - 1) - saturate(PointLightPosition.z - halfMagnitude * PointLightPosition.z);

    return float4(GetComputedColor(alpha));


Is it possible to draw a textured quad and apply shader effect with Blendstate.Additive?

Thx in advance

Sure it is.
By the way, you don’t need to have in VertexOut the same members as in VertexIn.
You only need TexCoord, color for ex in VertexOut. Whereas no need of colors in the VertexIn if not used.

And float4 SimplePointLightPS() should be:

float4 SimplePointLightPS(VertexOut input):COLOR0

Can you clarify what you want to do?

Draw a fullscreen quad?

Check out https://github.com/UncleThomy/BloomFilter-for-Monogame-and-XNA

There is a quadrenderer, which generates a quad and supplemental basic vertex shaders/pixel shaders. The whole setup of the sample is really simple I think, so it’s easy to understand i hope.

Otherwise you can check out https://github.com/UncleThomy/DeferredEngine
or https://github.com/UncleThomy/Modelviewer

which uses fullscreenquads the same way, but has a few other shaders and is more complicated to understand.

I want to draw my layer of tiles (now tile == quad, before it was a rectangle) and apply light effect ( now quad too) with my shader.

I see my quad light but no effect. Possibly its my position no?


i have no idea what you are saying, sorry

Sorry for my bad english level.

For being specific, with your quad renderer method it works, the light is applied in the all the screen’s size BUT I would like to drawn the light just in the quad.

If I change his position and his size I see nothing.


Ok I see my quad now, I don’t know why but its ok.

float4 worldPosition = mul(float4(vin.Position,1), World); // Works fine

float4 worldPosition = mul(vin.Position, World); // I don't see my quad ???

Now I want to pass a blend state via the shader but

technique10 SimplePointLight
    pass Pass0
        SetBlendState(Blend, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetPixelShader(CompileShader(ps_4_0, SimplePointLightPS()));
        /*VertexShader = compile vs_4_0 VS();        
        PixelShader = compile ps_4_0 SimplePointLightPS();*/

with Blend :

BlendState Blend {
    BlendEnable[0] = TRUE;
    DestBlend = INV_SRC_ALPHA;
    SrcBlend = SRC_ALPHA;

If I initialize a currentTecnique with SimplePointLight, error null exception :frowning:

That’s wrong?

How initialize currentTechnique if I use technique10?

I make this :

_lightingEffectTechnique = deferred.Techniques["SimplePointLight"];// null exception



I use an old Blend method. Thx anyway.

Thx guys