Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct OutputVertex
- {
- float4 xyzw : SV_POSITION;
- float4 rgba : OCOLOR;
- float2 uv : UV;
- float3 nrm : NORMAL;
- float4 world : WPOS;
- float3 loc : LOCAL;
- };
- struct Light
- {
- float3 dir;
- float x;
- float4 ambient;
- float4 diffuse;
- float3 pos;
- float range;
- float3 att;
- float y;
- float3 dir2;
- float cone;
- };
- cbuffer cbperframe : register(b)
- {
- Light light;
- };
- Texture2D env : register(t0);
- SamplerState envFilter : register(s0);
- float4 main(OutputVertex inputP) : SV_TARGET
- {
- // Directional
- inputP.nrm = normalize(inputP.nrm);
- float3 dir = normalize(light.dir);
- float4 inp = env.Sample(envFilter, inputP.uv);
- float3 final1 = inp * light.ambient;
- final1 += saturate(dot(-dir, inputP.nrm) * light.diffuse * inp);
- float4 dire = float4(final1, inp.a);
- // Point
- float3 lightToPixel = light.pos - inputP.world.xyz;
- float d = length(lightToPixel);
- float3 ambi = inp * light.ambient;
- float4 pnt = float4(0.0f, 0.0f, 0.0f, 0.0f);
- if (d < light.range)
- {
- float3 final2 = float3(0.0f, 0.0f, 0.0f);
- lightToPixel /= d;
- float howMuch = dot(lightToPixel, inputP.nrm);
- if (howMuch > 0.0f)
- {
- final2 += (howMuch * inp.xyz * float3(1.0f, 0.0f, 0.0f));
- float rangeAtt = 1.0f - saturate(d / light.range);
- final2 *= rangeAtt;
- }
- final2 = saturate(final2);
- pnt = float4(final2, inp.a);
- }
- // Output
- float4 combined = dire + pnt + float4(ambi, 0.0f);
- float4 real = saturate(combined);
- return real;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement