Files
cocos4/editor/assets/effects/pipeline/skybox.effect
T
jk20012001 8780a311a2 Fix skybox stretch in ortho projection (#10045)
Fix default sphere model
2022-01-25 19:09:46 +08:00

68 lines
1.6 KiB
Plaintext

CCEffect %{
techniques:
- passes:
- vert: sky-vs:vert
frag: sky-fs:frag
priority: max - 10
rasterizerState:
cullMode: none
depthStencilState:
depthTest: true
depthWrite: false
}%
CCProgram sky-vs %{
precision highp float;
#include <cc-global>
#include <decode>
out mediump vec4 viewDir;
vec4 vert () {
CCDecode(viewDir);
mat4 matViewRotOnly = mat4(mat3(cc_matView));
vec4 pos = matViewRotOnly * viewDir;
// orthographic projection adaptation
if (cc_matProj[3].w > 0.0) {
mat4 matProj = cc_matProj;
// default ortho height 10 approximate to default FOV 45
// stretch x by 2 to remedy perspective effect
// w = sin(45/2), h = 2 * w, _11 = 2 / w, _22 = 2 / h
matProj[0].x = 5.2;
matProj[1].y = 2.6;
matProj[2].zw = vec2(-1.0);
matProj[3].zw = vec2(0.0);
// position is modified inside branches to work around a vk driver bug seen in
// low-end Qualcomm devices (Adreno 512, Oppo R11, cocos-creator/3d-tasks#9236)
pos = matProj * pos;
} else {
pos = cc_matProj * pos;
}
pos.z = 0.99999 * pos.w;
return pos;
}
}%
CCProgram sky-fs %{
precision mediump float;
#include <cc-global>
#include <cc-environment>
#include <unpack>
#include <gamma>
#include <output-standard>
in mediump vec4 viewDir;
vec4 frag () {
#if USE_RGBE_CUBEMAP
vec3 c = unpackRGBE(texture(cc_environment, viewDir.xyz));
#else
vec3 c = SRGBToLinear(texture(cc_environment, viewDir.xyz).rgb);
#endif
return CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));
}
}%