我已將鏡面反射鏡元件添加到我的基本光着色器中,並且出現鏡面光焦度問題。如果我將其值設置爲0,而不是沒有鏡面高光的預期遮罩對象,則會出現奇怪的效果,其中只有直接點亮的表面可見,而忽略環境和漫反射組件。零點像素着色器中的鏡面光焦度移除環境和漫反射
下面的圖片說明了這個問題:
我仍然可以與設置specularIntensity
0擺脫了鏡面元素,但我認爲設置specularPower
爲0將有同樣的效果。下面是我的像素着色器的代碼,我想不出有什麼地方錯了:
float4 LightPixelShader(PixelInputType input) : SV_Target
{
float4 specular;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
float4 textureColor = shaderTexture.Sample(SampleType, input.tex);
// Set default output color to ambient light value for all pixels
float4 color = ambientColor;
// Invert the light direction for calculations.
float3 lightDir = -lightDirection;
// Calculate the amount of light on this pixel.
float lightIntensity = saturate(dot(input.normal, lightDir));
if (lightIntensity > 0.0f)
{
// Determine final diffuse color
color += (diffuseColor * lightIntensity);
// Saturate ambient and diffuse color
color = saturate(color);
// Calculate the reflection vector based on the light intensity, normal vector and light direction
float3 reflection = normalize(2 * dot(lightDir, input.normal) * input.normal - lightDir);
// Determine the amount of specular light based on the reflection vector, viewing direction and specular power
specular = specularIntensity * specularColor * pow(saturate(dot(reflection, normalize(input.viewDirection))), specularPower);
}
// Saturate the final color in case it's greater then 1
color = saturate(color);
// Multiply the texture pixel and the final diffuse color to get the final pixel color result.
color = color * textureColor;
// Add the specular component
color = saturate(color + specular);
return color;
}
將'specular'初始化爲'float4(0,0,0,0)',所以如果像素不亮則不改變顏色。這可能就是爲什麼即使環境組件不見了。 –
它似乎沒有太大的改變。 – jaho
「不多」是什麼意思?環境組件是否重新出現? –