Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.3 渐变纹理 中 ambient 分量的计算方式为何不是这样的? #224

Closed
HongfeiXu opened this issue May 17, 2018 · 2 comments
Closed

Comments

@HongfeiXu
Copy link

HongfeiXu commented May 17, 2018

之所以有这个疑惑是因为 7.1 单张纹理ambient 的计算方式与 7.3 渐变纹理 中的不同。

这是 7.1 单张纹理 中片元着色器的部分代码

// Use the texture to sample the diffuse color
fixed3 albedo = tex2D(_MainTex, i.uv).rgb * _Color.rgb;

fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;

fixed3 diffuse = _LightColor0.rgb * albedo * saturate(dot(worldNormal, worldLightDir));

这是 7.3 渐变纹理 种片元着色器的相关代码,我的问题也在最后两行代码上。

// Use the texture to sample the diffuse color
fixed halfLambert = dot(worldNormal, lightDir) * 0.5 + 0.5;
fixed3 diffuseColor = tex2D(_RampTex, fixed2(halfLambert, halfLambert)).rgb * _Color.rgb;
fixed3 diffuse = _LightColor0.rgb * diffuseColor;

fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz;
// 为何不是这种方式来计算 ambient
//fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * diffuseColor;		

上面是这两种不同方式计算 ambient 所带来的不同效果,个人觉得后面的效果要好些。还是说这个问题的答案并不绝对?两种方式都没有问题?如果是那样的话,那么 7.1 单张纹理 中 albedo 的计算方式是否也可以变为 fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz; ?可能有点钻牛角尖了,但确实比较困惑。望解答。

这是 Chapter7-SingleTexture.shader 中用不同方式计算 ambient 后的效果对比。

@HongfeiXu HongfeiXu changed the title 7.3 渐变纹理 ambient 计算方式为何不是这样的? 7.3 渐变纹理 中 ambient 分量的计算方式为何不是这样的? May 17, 2018
@candycat1992
Copy link
Owner

你好,这个问题你可以参考之前的issue

@HongfeiXu
Copy link
Author

@candycat1992 明白了,这两种ambient的计算方式都是经验模型而已,效果会有不同,但没有说一定谁就是更好的。谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants