123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #extension GL_EXT_frag_depth : enable
- //
- // adapted from the EDL shader code from Christian Boucheny in cloud compare:
- // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
- //
- precision mediump float;
- precision mediump int;
- //uniform float screenWidth;
- //uniform float screenHeight;
- uniform vec2 resolution;
- uniform vec2 neighbours[NEIGHBOUR_COUNT];
- uniform float edlStrength;
- uniform float radius;
- uniform float opacity;
- //uniform float uNear;
- //uniform float uFar;
- uniform mat4 uProj;
- uniform sampler2D uEDLColor;
- uniform sampler2D uEDLDepth;
- varying vec2 vUv;
- uniform int useEDL;
- float response(float depth){
- vec2 uvRadius = radius / resolution; //vec2(screenWidth, screenHeight);
-
- float sum = 0.0;
-
- for(int i = 0; i < NEIGHBOUR_COUNT; i++){
- vec2 uvNeighbor = vUv + uvRadius * neighbours[i];
- //获取周围八个格子的值
- float neighbourDepth = texture2D(uEDLColor, uvNeighbor).a;
- neighbourDepth = (neighbourDepth == 1.0) ? 0.0 : neighbourDepth;
- if(neighbourDepth != 0.0){
- //if(depth == 0.0){
- // sum += 100.0;
- //}else{
- sum += max(0.0, depth - neighbourDepth); //获取差值
- //}
- }
- }
-
- return sum / float(NEIGHBOUR_COUNT);
- }
- void main(){
- vec4 cEDL = texture2D(uEDLColor, vUv);
-
- float depth = cEDL.a;
- depth = (depth == 1.0) ? 0.0 : depth;
-
- if(depth == 0.0){ //去掉这句就能在无点云像素的地方渲染outline,但会遮住其他mesh
- discard;
- }
-
-
- if(useEDL == 1){
- float res = response(depth);
- float shade = exp(-res * 300.0 * edlStrength); //自然常数e为底的指数函数
- const float min = 0.2; //add 使边缘色变浅 范围从0-1 变为min-1
- shade = shade * (1.0-min) + min;
- gl_FragColor = vec4(cEDL.rgb * shade, opacity);
- }else{//加 不改颜色的情况
- gl_FragColor = vec4(cEDL.rgb, opacity);
- }
- //注意,edlStrength越强,在相同depth的叠放的点云间的轮廓线颜色越深
- //作用:勾勒边缘,强化深度差异,模拟阴影,加强结构立体感
-
- { // write regular hyperbolic depth values to depth buffer 修改深度
- float dl = pow(2.0, depth);
- vec4 dp = uProj * vec4(0.0, 0.0, -dl, 1.0);
- float pz = dp.z / dp.w;
- float fragDepth = (pz + 1.0) / 2.0;
- gl_FragDepthEXT = fragDepth;
- }
-
- }
|