Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct ConstantData
- {
- float4x4 World;
- float4x4 WorldViewProj;
- float4x4 lolwat;
- float4 ViewerPos;
- };
- struct LightData
- {
- float4 Position;
- float4 Color;
- };
- /*struct
- {
- float4 MaterialAmbient;
- float4 MaterialDiffuse;
- float4 MaterialSpecular;
- float4 MaterialEmissive;
- float MaterialSpecularPower;
- };*/
- cbuffer ConstBuf : register(b0)
- {
- ConstantData ConstData;
- }
- cbuffer ConstBuf1 : register(b1)
- {
- LightData Lights;
- }
- struct VS_IN
- {
- float4 pos : POSITION;
- float4 normal : NORMAL;
- float4 tex : TEXCOORD;
- };
- struct PS_IN
- {
- float4 pos : SV_POSITION;
- float4 normal : NORMAL;
- float2 tex : TEXCOORD0;
- float4 worldPos : TEXCOORD1;
- };
- Texture2D DiffuseMap : register(t0);
- SamplerState Sampler : register(s0);
- PS_IN VSMain(VS_IN input)
- {
- PS_IN output = (PS_IN)0;
- output.worldPos = mul(float4(input.pos.xyz, 1.0f), ConstData.World);
- output.pos = mul(float4(input.pos.xyz, 1.0f), ConstData.WorldViewProj);
- output.normal = mul(float4(input.normal.xyz, 0.0f), ConstData.World);
- output.normal = normalize(output.normal);
- output.tex = input.tex.xy;
- return output;
- }
- float4 PSMain(PS_IN input) : SV_Target
- {
- float3 kd = DiffuseMap.Sample(Sampler, input.tex.xy).xyz;
- kd = float3(1.0f, 1.0f, 1.0f);
- float3 normal = normalize(input.normal.xyz);
- float3 viewDir = normalize(ConstData.ViewerPos.xyz - input.worldPos.xyz);
- float3 lightDir = normalize(Lights.Position.xyz - input.worldPos.xyz);
- float3 refVec = normalize(reflect(-lightDir, normal));
- float3 diffuse = max(0, dot(lightDir, normal)) * kd;
- float3 ambient = kd * 0.05f;
- float3 spec = pow(max(0, dot(-viewDir, refVec)), 50) * 1.0f;
- //return float4(normal, 1.0f);
- return float4(Lights.Color.xyz * (diffuse * ambient * spec), 1.0f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement