<p>A very novice mistake, I was compiling with the old HLSL compiler. But why would that be the default? Very strange.</p>

<p>For anybody wondering, just right click the HLSL file in the solution explorer and go to properties -> HLSL Compiler -> General, and switch Shader Model to the one you want which was newest one for me (5.0)</p>

CC BY-SA 3.0
2016-02-20T20:40:35.193Z
2016-02-20T20:40:35.193Z
phatgreen
<p>I've recently made the switch to Visual 2015 and the .fx files have been depreciated. My project contained .fx files for the shaders so I've been switching over.</p>

<p>Only during the switch have I changed to using deferred rendering for lighting.</p>

<p>The only shader I've made so far is the Pixel Shader that is used on the 2nd Pass, the shader that does the Per Pixel x Per Light calculations, sums them, and outputs final color.</p>

<p>However, whenever I compile (I'm not actually using the shader in runtime, I'm just getting it all setup, the window is still just cleared to a color every frame, no actual rendering) I get a failure that says....</p>

<p>error X4502: Shader model ps_4_0_level_9_3 doesn't allow reading from position semantics.</p>

<p>Here is the only shader I have in the project that is causing this error.</p>

<p>I omitted the getGBufferAttributes and calculateLighting methods because I know they are not the issue. </p>

<pre><code>Texture2D NormalTexture                 : register(t0);
Texture2D DiffuseAlbedoTexture          : register(t1);
Texture2D SpecularAlbedoTexture         : register(t2);
Texture2D PositionTexture               : register(t3);

cbuffer LightParams
{
    float3 LightPos;
    float3 LightColor;
    float3 LightDirection;
    float2 SpotlightAngles;
    float4 LightRange;
};

cbuffer CameraParams
{
    float3 CameraPos;
};

float4 main(in float4 screenPos : SV_Position) : SV_Target0
{
    float3 normal;
    float3 position;
    float3 diffuseAlbedo;
    float3 specularAlbedo;
    float specularPower;

    getGBufferAttributes(screenPos.xy, normal, position, diffuseAlbedo, specularAlbedo, specularPower);

    float3 lighting = calculateLighting(normal, position, diffuseAlbedo, specularAlbedo, specularPower);

    return float4(lighting, 1.0f);
}
</code></pre>

<p>The code used for this shader is highly based off the code used as the deferred rendering example in the book, Practical Rendering with Direct3D 11 by Jason Zink, Matt Pettineo, and Jack Hoxley.</p>

<p>I don't understand why they would give source code that doesn't work. Does it have something to do with the new compiler in Visual 2015 and the Runtime?</p>

<p>Also, since I'm going from only using effects before to now raw HLSL shaders, is there anything I should be aware of that might trip somebody like me up?</p>

<shader><directx11><pixel-shader><hlsl><deferred-rendering>
HLSL Deferred Rendering
phatgreen
# HLSL Deferred Rendering

(Asked by: username_0 on 2016-02-20)

I've recently made the switch to Visual 2015 and the .fx files have been depreciated. My project contained .fx files for the shaders so I've been switching over.

Only during the switch have I changed to using deferred rendering for lighting.

The only shader I've made so far is the Pixel Shader that is used on the 2nd Pass, the shader that does the Per Pixel x Per Light calculations, sums them, and outputs final color.

However, whenever I compile (I'm not actually using the shader in runtime, I'm just getting it all setup, the window is still just cleared to a color every frame, no actual rendering) I get a failure that says....

error X4502: Shader model ps\_4\_0\_level\_9\_3 doesn't allow reading from position semantics.

Here is the only shader I have in the project that is causing this error.

I omitted the getGBufferAttributes and calculateLighting methods because I know they are not the issue.

```
Texture2D NormalTexture                 : register(t0);
Texture2D DiffuseAlbedoTexture          : register(t1);
Texture2D SpecularAlbedoTexture         : register(t2);
Texture2D PositionTexture               : register(t3);

cbuffer LightParams
{
    float3 LightPos;
    float3 LightColor;
    float3 LightDirection;
    float2 SpotlightAngles;
    float4 LightRange;
};

cbuffer CameraParams
{
    float3 CameraPos;
};

float4 main(in float4 screenPos : SV_Position) : SV_Target0
{
    float3 normal;
    float3 position;
    float3 diffuseAlbedo;
    float3 specularAlbedo;
    float specularPower;

    getGBufferAttributes(screenPos.xy, normal, position, diffuseAlbedo, specularAlbedo, specularPower);

    float3 lighting = calculateLighting(normal, position, diffuseAlbedo, specularAlbedo, specularPower);

    return float4(lighting, 1.0f);
}

```

The code used for this shader is highly based off the code used as the deferred rendering example in the book, Practical Rendering with Direct3D 11 by Jason Zink, Matt Pettineo, and Jack Hoxley.

I don't understand why they would give source code that doesn't work. Does it have something to do with the new compiler in Visual 2015 and the Runtime?

Also, since I'm going from only using effects before to now raw HLSL shaders, is there anything I should be aware of that might trip somebody like me up?

**Tags:** shader, directx11, pixel-shader, hlsl, deferred-rendering


---

## 1 answers

### Answer by username_0 on 2016-02-20. Score: 3 | Accepted answer

A very novice mistake, I was compiling with the old HLSL compiler. But why would that be the default? Very strange.

For anybody wondering, just right click the HLSL file in the solution explorer and go to properties -> HLSL Compiler -> General, and switch Shader Model to the one you want which was newest one for me (5.0)


---

