Lighting OUT; if (light.diffusePower > 0) { float3 lightDir = light.position - pos3D; //3D position in space of the surface float distance = length(lightDir); lightDir = lightDir / distance; // = normalize(lightDir); distance = distance * distance;
//Intensity of the diffuse light. Saturate to keep within the 0-1 range. float NdotL = dot(normal, lightDir); float diffuseIntensity = saturate(NdotL);
// Calculate the diffuse light factoring in light color, power and the attenuation OUT.Diffuse = diffuseIntensity * light.diffuseColor * light.diffusePower / distance;
//Calculate the half vector between the light vector and the view vector. float3 H = normalize(lightDir + viewDir);
//Intensity of the specular light float NdotH = dot(normal, H); float specularIntensity = pow(saturate(NdotH), specularHardness);
//Sum up the specular light factoring OUT.Specular = specularIntensity * light.specularColor * light.specularPower / distance; } return OUT;
Directx11에서 제작한 빌린퐁 셰이더입니다.
마무리
이처럼 고러드, 램버트, 빌린퐁 셰이더는 각각 다른 계산 방식과 특징을 가지고 있습니다. 사실 셰이더 종류에 대해 알아보는 글이라 더 자세히는 적지 않았습니다. 더 자세한 내용은 GPT 혹은 전문 칼럼을 참고하는 것도 좋은 방법이라고 생각합니다.