UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

77 lines (64 loc) 2.77 kB
export default `// source: https://github.com/mrdoob/three.js/blob/dev/examples/js/shaders/SSAOShader.js vec3 getViewPosition(const float depth) { float clipW = _projectionMatrix[2][3] * depth + _projectionMatrix[3][3]; vec4 clipPosition = vec4((vec3(vUv, depth) - 0.5) * 2.0, 1.0); clipPosition *= clipW; return (_inverseProjectionMatrix * clipPosition).xyz; } // source: https://github.com/mrdoob/three.js/blob/342946c8392639028da439b6dc0597e58209c696/examples/js/shaders/SAOShader.js#L123 float getViewZ(const in float depth) { #ifdef PERSPECTIVE_CAMERA return perspectiveDepthToViewZ(depth, cameraNear, cameraFar); #else return orthographicDepthToViewZ(depth, cameraNear, cameraFar); #endif } // credits for transforming screen position to world position: https://discourse.threejs.org/t/reconstruct-world-position-in-screen-space-from-depth-buffer/5532/2 vec3 screenSpaceToWorldSpace(const vec2 uv, const float depth) { vec4 ndc = vec4( (uv.x - 0.5) * 2.0, (uv.y - 0.5) * 2.0, (depth - 0.5) * 2.0, 1.0); vec4 clip = _inverseProjectionMatrix * ndc; vec4 view = cameraMatrixWorld * (clip / clip.w); return view.xyz; } // vec2 worldSpaceToScreenSpace(vec3 worldPos){ // vec4 ssPos = _projectionMatrix * inverse(cameraMatrixWorld) * vec4(worldPos, 1.0); // ssPos.xy /= ssPos.w; // ssPos.xy = ssPos.xy * 0.5 + 0.5; // return ssPos.xy; // } #define Scale (vec3(0.8, 0.8, 0.8)) #define K (19.19) vec3 hash(vec3 a) { a = fract(a * Scale); a += dot(a, a.yxz + K); return fract((a.xxy + a.yxx) * a.zyx); } // source: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/gpu/shaders/material/gpu_shader_material_fresnel.glsl float fresnel_dielectric_cos(float cosi, float eta) { /* compute fresnel reflectance without explicitly computing * the refracted direction */ float c = abs(cosi); float g = eta * eta - 1.0 + c * c; float result; if (g > 0.0) { g = sqrt(g); float A = (g - c) / (g + c); float B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0); result = 0.5 * A * A * (1.0 + B * B); } else { result = 1.0; /* TIR (no refracted component) */ } return result; } // source: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/gpu/shaders/material/gpu_shader_material_fresnel.glsl float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta) { /* compute fresnel reflectance without explicitly computing * the refracted direction */ float cosine = dot(Incoming, Normal); return min(1.0, 5.0 * fresnel_dielectric_cos(cosine, eta)); }`; //# sourceMappingURL=helperFunctions.js.map