I am currently working on a simple game that I am building in Windows 8 using MonoGame (develop3d). I am using some shader code from a tutorial (made by Charles Humphrey) and having an issue populating a 'texture' parameter as it appears to be missing.

Edit I have also tried 'Texture2D' and using it with a register(t0), still no luck

I'm not well versed writing shaders, so this might be caused by a more obvious problem.

I have debugged through MonoGame's Content processor to see how this shader is being parsed, all the non 'texture' parameters are there and look to be loading correctly.

Edit This seems to go back to D3D compiler.

Shader code below:

#include "PPVertexShader.fxh"

float2 lightScreenPosition;

float4x4 matVP;

float2 halfPixel;

float SunSize;

texture flare;

sampler2D Scene: register(s0){
    AddressU = Clamp;
    AddressV = Clamp;

sampler Flare = sampler_state
    Texture = (flare);
    AddressU = CLAMP;
    AddressV = CLAMP;

float4 LightSourceMaskPS(float2 texCoord : TEXCOORD0 ) : COLOR0
    texCoord -= halfPixel;

    // Get the scene
    float4 col = 0;

    // Find the suns position in the world and map it to the screen space.
        float2 coord;

        float size = SunSize / 1;

        float2 center = lightScreenPosition;

        coord = .5 - (texCoord - center) / size * .5;
        col += (pow(tex2D(Flare,coord),2) * 1) * 2;                     

    return col * tex2D(Scene,texCoord); 

technique LightSourceMask
    pass p0
        VertexShader = compile vs_4_0 VertexShaderFunction();
        PixelShader = compile ps_4_0 LightSourceMaskPS();

I've removed default values as they are currently not support in MonoGame and also changed ps and vs to v4 instead of 2. Could this be causing the issue?

As I debug through 'DXConstantBufferData' constructor (from within the MonoGameContentProcessing project) I find that the 'flare' parameter does not exist. All others seem to be getting created fine.

Any help would be appreciated.

Update 1 I have discovered that SharpDX D3D compiler is what seems to be ignoring this parameter (perhaps by design?). The ConstantBufferDescription.VariableCount seems to be not counting the texture variable.

Update 2 SharpDX function 'GetConstantBuffer(int index)' returns the parameters (minus textures) which is making is impossible to set values to these variables within the shader. Any one know if this is normal for DX11 / Shader Model 4.0? Or am I missing something else?


1 Answer 1


Don't know much about internals of MonoGame, but texture are definitely not stored in a ConstantBuffer. The texture is not a constant buffer, it is a texture which has its own slot and is bounded completely separetly from the ConstantBuffer.

To get the slot of the texture, this is done through the ShaderReflection object and method reflect.GetResourceBindingDescription(i);.

  • \$\begingroup\$ Thanks for the advice! I thought the problem would probably be due to my lack of knowledge of shaders. Will have a look at 'GetResourceBindingDescription' soon. \$\endgroup\$ Nov 1, 2012 at 8:51
  • \$\begingroup\$ This solved my issues with missing parameters. Followed 'advertboy.wordpress.com/2012/05/06/…' to help with converting, but this gave me a better understanding. Cheers. Still gotta learn how to write hlsl shaders though :) Thanks again. \$\endgroup\$ Nov 4, 2012 at 3:03
  • 2
    \$\begingroup\$ For anyone following Layoric's link in the comment above, it has an extra quote in it so it doesn't quite get you there. The proper link is: advertboy.wordpress.com/2012/05/06/… \$\endgroup\$
    – chue x
    Jan 30, 2013 at 23:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .