CodeWalker/CodeWalker.Shaders/LightVS.hlsl

69 lines
1.7 KiB
HLSL
Raw Normal View History

2019-12-03 21:52:22 +08:00
#include "Common.hlsli"
struct VS_Output
{
float4 Pos : SV_POSITION;
float4 Screen : TEXCOORD0;
};
cbuffer VSLightVars : register(b0)
{
float4x4 ViewProj;
float4 CameraPos;
uint LightType; //0=directional, 1=Point, 2=Spot, 4=Capsule
uint IsLOD; //useful or not?
uint Pad0;
uint Pad1;
}
2019-12-05 00:40:52 +08:00
cbuffer VSLightInstVars : register(b1)
{
float3 InstPosition;//camera relative
float InstIntensity;
float3 InstColour;
float InstFalloff;
float3 InstDirection;
float InstFalloffExponent;
float3 InstTangentX;
float InstConeInnerAngle;
float3 InstTangentY;
float InstConeOuterAngle;
float3 InstCapsuleExtent;
uint InstType;
float3 InstCullingPlaneNormal;
float InstCullingPlaneOffset;
}
2019-12-03 21:52:22 +08:00
VS_Output main(float4 ipos : POSITION, uint iid : SV_InstanceID)
{
float3 opos = 0;
2019-12-05 00:40:52 +08:00
float extent = InstFalloff;
if (InstType == 1)//point (sphere)
{
opos = ipos.xyz * extent;
}
else if (InstType == 2)//spot (cone)
2019-12-03 21:52:22 +08:00
{
2019-12-05 12:04:00 +08:00
float arads = InstConeOuterAngle;
float3 tpos = (ipos.xyz * sin(arads)) + float3(0, 0, ipos.w * cos(arads));
float3 cpos = ((ipos.w > 0) ? normalize(tpos) : tpos) * extent;
opos = (cpos.x * InstTangentX) + (cpos.y * InstTangentY) + (cpos.z * InstDirection);
2019-12-03 21:52:22 +08:00
}
2019-12-05 00:40:52 +08:00
else if (InstType == 4)//capsule
2019-12-03 21:52:22 +08:00
{
2019-12-05 00:40:52 +08:00
float3 cpos = ipos.xyz * extent;
2019-12-12 19:21:18 +08:00
cpos.y += abs(InstCapsuleExtent.y) * (ipos.w - 0.5);
2019-12-05 00:40:52 +08:00
opos = (cpos.x * InstTangentX.xyz) + (cpos.y * InstDirection.xyz) + (cpos.z * InstTangentY.xyz);
2019-12-03 21:52:22 +08:00
}
2019-12-05 00:40:52 +08:00
float4 spos = mul(float4(opos + InstPosition, 1), ViewProj);
2019-12-03 21:52:22 +08:00
VS_Output output;
output.Pos = spos;
output.Screen = spos;
return output;
}