cubeMapReflectionVS.hlsl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. int StyleUVW ; // 0 = specular reflection, 1 = diffuse reflection, 2 = use model vertex coordinates for uvw.
  2. float4x4 WorldViewProj;
  3. float4x4 World;
  4. float3 CameraPos;
  5. // Vertex Shader
  6. void VS(
  7. in float4 VPos : POSITION,
  8. in float3 VNorm : NORMAL,
  9. in float3 VTex : TEXCOORD0,
  10. out float4 outPos : POSITION,
  11. out float4 outTex : TEXCOORD0 )
  12. {
  13. // vertex position from model-space to view-space
  14. outPos = mul( VPos, WorldViewProj );
  15. if ( StyleUVW == 0 )
  16. {
  17. // create ray from camera position to the vertex, in world space
  18. float4 worldPos = mul(float4(VPos.x, VPos.y, VPos.z, 1.0), World);
  19. float3 view = CameraPos - worldPos.xyz;
  20. float4 normWorld = normalize(mul(float4(VNorm.x, VNorm.y, VNorm.z, 0.0), World)); // TODO: when objects are scaled non-uniform we need to multiply by WorldInverseTranspose instead
  21. // compute the reflection vector, and assign it to texcoord 0
  22. outTex.xyz = reflect( -normalize(view), normWorld.xyz );
  23. }
  24. else if ( StyleUVW == 1 )
  25. {
  26. // just use the normal for the reflection vector
  27. outTex.xyz = normalize(VNorm);
  28. }
  29. else if ( StyleUVW == 2 )
  30. {
  31. // use vertex-coordinates for texture coordinates
  32. outTex.xyz = VPos.xyz;
  33. }
  34. }