zoukankan      html  css  js  c++  java
  • 次表面散射(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;
    }

  • 相关阅读:
    Quartz学习笔记
    apache shiro学习笔记
    zTree学习笔记
    WebService学习笔记
    【webservice】Two classes have the same XML type name(转)
    使用OCUpload和POI一键上传Excel并解析导入数据库
    EasyUI学习笔记(四)—— datagrid的使用
    thinkphp的路径问题
    thinkphp验证码不现实多半是bom惹的祸
    TPM(ThinkPHPMobile)使用简明教程
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/3806647.html
Copyright © 2011-2022 走看看