4

I'm working through Frank Luna's "DirectX 9.0c: A Shader Approach" book and I'm stuck on exercise 2 in chapter 10. I'm supposed to calculate a float value s and pass it to the pixel shader so I can calculate "toon lighting". I understand the theory behind how the calculations work, but I can't seem to figure out how to pass a single float value from my vertex shader to the pixel shader like that. When I searched on MSDN I only found the semantics that let you pass 3d vectors, etc.

It looks like maybe I need to modify my input and output structures somehow, but the exercises so far haven't had any structures besides a single "outputVS" structure.

In short, how do I pass a single float value from my vertex shader to the pixel shader in HLSL?

Thank you in advance.

Aztal
  • 217
  • 1
  • 5
  • 12

1 Answers1

2

You put the float into one component of the vector. Then your pixel shader reads only that one component.

There's no law that says that every component of a vector must contain actual data ;)

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 1
    This is the answer. I went back and Luna briefly mentions it during the first chapter using shaders. Basically you add a float to the vertex shader output structure and pixel shader's input parameters giving it the semantic "TEXCOORD", but nothing stops you from using that value for whatever you want. – Aztal Apr 15 '12 at 01:09