50 lines
1.4 KiB
HLSL
50 lines
1.4 KiB
HLSL
#include "bindless_structs.hlsli"
|
|
|
|
struct FS_Input
|
|
{
|
|
float4 inPosition : POSITION;
|
|
float4 inNormal : NORMAL;
|
|
float4 inColor : COLOR0;
|
|
float2 inUV : TEXCOORD0;
|
|
};
|
|
|
|
struct FS_Output
|
|
{
|
|
float4 outColor : SV_Target0;
|
|
};
|
|
|
|
float4 GetAlbedo(uint materialBufferId, int materialId, float2 uv)
|
|
{
|
|
uint albedoTexId = materialsBuffer[materialBufferId][materialId].m_AlbedoTex;
|
|
if (albedoTexId == INVALID_HANDLE)
|
|
{
|
|
return (float4) materialsBuffer[materialBufferId][materialId].m_AlbedoFactor;
|
|
}
|
|
else
|
|
{
|
|
return textures[albedoTexId].Sample(immutableSamplers[albedoTexId], uv);
|
|
}
|
|
}
|
|
|
|
FS_Output main(FS_Input stage_input)
|
|
{
|
|
|
|
// Hereby assume that we always have a point light at
|
|
float3 lightPos = float3(6.0f, 6.0f, 6.0f);
|
|
// with
|
|
float3 lightColor = float3(0.7f, 0.7f, 0.7f); //float3(0.7f, 0.4f, 0.1f);
|
|
// and
|
|
float3 ambient = float3(0.02f, 0.02f, 0.02f);
|
|
|
|
float3 norm = normalize(stage_input.inNormal.xyz);
|
|
float3 lightDir = normalize(lightPos - stage_input.inPosition.xyz);
|
|
float diff = max(dot(norm, lightDir), 0.0f);
|
|
float3 diffuse = diff * lightColor;
|
|
|
|
float4 objColor = pcb.m_MaterialIdx < 0 ? stage_input.inColor : GetAlbedo(pcb.materialBufferHandle, pcb.m_MaterialIdx, stage_input.inUV);
|
|
|
|
FS_Output output;
|
|
output.outColor = float4(objColor.rgb * (diffuse + ambient), objColor.a);
|
|
return output;
|
|
}
|