• 次表面散射(SubSurface Scattering) Shader 【转】


    原文 http://www.azure.com.cn/article.asp?id=231

    用深度值近似模拟物体的厚度,
    厚度越小处透光越多。 

    varying vec4 position;
    varying vec4 world_pos;
    varying vec2 texcoord0;
    varying vec3 normal;


    void main(void)
    {
       gl_Position = ftransform();
       world_pos = gl_Position;
       position = gl_Vertex;
       texcoord0 = gl_MultiTexCoord0.st;
       normal = gl_NormalMatrix * gl_Normal;
    }

    varying vec4 position;
    varying vec4 world_pos;
    varying vec2 texcoord0;
    varying vec3 normal;
    uniform vec4 camera_pos;
    uniform float near_clip;
    uniform float ampify;
    uniform vec3 singlelight;
    uniform sampler2D base;
    uniform vec3 lightcolor;
    uniform float ks;

    void main(void)
    {
       float distance =( distance(camera_pos, position) - near_clip )/200.0 * ampify;
       distance = log2(distance);
       //gl_FragColor = vec4(distance, distance, distance, 1);
      
       vec4 lightpos = vec4(singlelight.x,
                            singlelight.y,
                            singlelight.z,
                            1);
       vec4 lightvec =  lightpos - position;
       normalize(lightvec);
       normalize(normal);
       float diffuse = max(0.0, dot(normal, lightvec.xyz));
       vec4 diffusecolor = vec4(diffuse*lightcolor.r, diffuse*lightcolor.g, diffuse*lightcolor.b, 1.0);

       vec3 V = normalize(camera_pos - position).xyz;
       vec3 H = normalize(lightvec.xyz + V);
       float speclight = pow(max(dot(normal.xyz, H), 0.0), ks);
       vec4 specularcolor = vec4(speclight, speclight, speclight, 1.0);
       gl_FragColor = texture2D(base, texcoord0) * distance + diffusecolor + specularcolor;
       //gl_FragColor.r = distance;
      
       //gl_FragColor = diffusecolor;
    }

  • 相关阅读:
    POJ 1797 Heavy Transportation
    洛谷 P3379 【模板】最近公共祖先(LCA)
    洛谷 P1351 联合权值
    51nod 1272 最大距离
    codevs 1664 清凉冷水
    COGS 1176. [郑州101中学] 月考
    HDU
    HDU
    一坨计算几何的板子
    bzoj2618[Cqoi2006]凸多边形
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/3806647.html
Copyright © 2020-2023  润新知