Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct ConstantData
  2. {
  3.     float4x4 World;
  4.     float4x4 WorldViewProj;
  5.     float4x4 lolwat;
  6.     float4 ViewerPos;
  7. };
  8.  
  9. struct LightData
  10. {
  11.     float4 Position;
  12.     float4 Color;
  13. };
  14.  
  15. /*struct
  16. {
  17.     float4 MaterialAmbient;
  18.     float4 MaterialDiffuse;
  19.     float4 MaterialSpecular;
  20.     float4 MaterialEmissive;
  21.     float MaterialSpecularPower;
  22. };*/
  23.  
  24. cbuffer ConstBuf : register(b0)
  25. {
  26.     ConstantData ConstData;
  27. }
  28.  
  29. cbuffer ConstBuf1 : register(b1)
  30. {
  31.     LightData Lights;
  32. }
  33.  
  34. struct VS_IN
  35. {
  36.     float4 pos : POSITION;
  37.     float4 normal : NORMAL;
  38.     float4 tex : TEXCOORD;
  39. };
  40.  
  41. struct PS_IN
  42. {
  43.     float4 pos : SV_POSITION;
  44.     float4 normal : NORMAL;
  45.     float2 tex : TEXCOORD0;
  46.     float4 worldPos : TEXCOORD1;
  47. };
  48.  
  49. Texture2D DiffuseMap : register(t0);
  50. SamplerState Sampler : register(s0);
  51.  
  52. PS_IN VSMain(VS_IN input)
  53. {
  54.     PS_IN output = (PS_IN)0;
  55.  
  56.     output.worldPos = mul(float4(input.pos.xyz, 1.0f), ConstData.World);
  57.     output.pos = mul(float4(input.pos.xyz, 1.0f), ConstData.WorldViewProj);
  58.     output.normal = mul(float4(input.normal.xyz, 0.0f), ConstData.World);
  59.  
  60.     output.normal = normalize(output.normal);
  61.  
  62.     output.tex = input.tex.xy;
  63.  
  64.     return output;
  65. }
  66.  
  67. float4 PSMain(PS_IN input) : SV_Target
  68. {
  69.     float3 kd = DiffuseMap.Sample(Sampler, input.tex.xy).xyz;
  70.     kd = float3(1.0f, 1.0f, 1.0f);
  71.     float3 normal = normalize(input.normal.xyz);
  72.     float3 viewDir = normalize(ConstData.ViewerPos.xyz - input.worldPos.xyz);
  73.     float3 lightDir = normalize(Lights.Position.xyz - input.worldPos.xyz);
  74.     float3 refVec = normalize(reflect(-lightDir, normal));
  75.  
  76.     float3 diffuse = max(0, dot(lightDir, normal)) * kd;
  77.     float3 ambient = kd * 0.05f;
  78.     float3 spec = pow(max(0, dot(-viewDir, refVec)), 50) * 1.0f;
  79.  
  80.     //return float4(normal, 1.0f);
  81.     return float4(Lights.Color.xyz * (diffuse * ambient * spec), 1.0f);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement