弯曲的磨砂玻璃着色器? [英] Curved Frosted Glass Shader?

查看:213
本文介绍了弯曲的磨砂玻璃着色器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使透明物体变得不是那么困难,但是我需要根据对象的曲线使透明度有所不同,以使其看起来不仅仅是平面物体.如下图所示.

Well making something transparent isn't that difficult, but i need that transparency to be different based on an object's curve to make it look like it isn't just a flat object. Something like the picture below.

中心比圆柱体的侧面更透明,它更黑,这是背景色.然后是边框,在其顶部似乎有某种镜面反射的照明使它更加闪亮,但在这种情况下,我不知道如何实现这种透明度.使用表面相对于眼睛位置的法线确定透明度值?任何帮助将不胜感激.

The center is more transparent than the sides of the cylinder, it is more black which is the background color. Then there is the bezel which seems to have some sort of specular lighting at the top to make it more shiny, but i'd have no idea how to go about that transparency in that case. Using the normals of the surface relative to the eye position to determine the transparency value? Any help would be appreciated.

推荐答案

(将注释移入答案并添加了更多详细信息)

(moved comments into answer and added some more details)

使用(次表面)散射代替透明性.

Use (Sub Surface) scattering instead of transparency.

例如,您可以通过假设光源在整个表面/整个体积上是恒定的来简化很多事情,因此您只需要查看光线积分,而不是每个光线的整个体积积分...我在大气层"中做到这一点着色器,它看起来仍然非常棒,与真实事物几乎无法区分,请参见一些较新的截图 ...已将其与照片进行了比较来自地球和火星的数据,结果几乎没有任何复杂的数学结果.

You can simplify things a lot for example by assuming the light source is constant along whole surface/volume ... so you need just the view ray integration not the whole volume integral per ray... I do it in my Atmospheric shader and it still looks pretty awesome almost indistinguisable from the real thing see some newer screenshots ... have compared it to the photos from Earth and Mars and the results where pretty close without any REALLY COMPLICATED MATH.

还有更多实现此目的的选项:

  1. 体素贴图(体绘制)

在体积渲染引擎中实现分散很容易,但是需要大量的内存和功能.

It is easy to implement scattering into volume render engine but needs a lot of memory and power.

使用2个深度缓冲区(正面和背面)

这需要进行2次传球,且Cull面已打开且CW/CCW设置正确.这也易于实现,但是不能在同一视图中沿摄像机视图的Z轴处理多个对象.想法是将两个深度缓冲区都传递给着色器,并沿其路径对像素光线进行积分,以累积/吸收来自光源的光.像这样:

this need 2 passes with Cull face on and CW/CCW settings. This is also easy to implement but this can not handle multiple objects in the same view along Z axis of camera view. The idea is to pass both depth buffers to shader and integrating the pixel rays along its path cumulating/absorbing light from light source. Something like this:

  1. 将几何体作为两个纹理渲染到两个深度缓冲区.
  2. 渲染四边形覆盖整个屏幕
  3. 为每个片段计算射线线(绿色)
  4. 计算展位深度缓冲区中的交点 获得'length,ang'
  5. 使用散射沿长度方向积分以计算像素颜色

  1. render geometry to both depth buffers as 2 textures.
  2. render quad covering whole screen
  3. for each fragment compute the ray line (green)
  4. compute the intersection points in booth depth buffers obtain 'length,ang'
  5. integrate along the length using scattering to compute pixel color

我使用类似这样的东西:

I use something like this:

   vec3 p,p0,p1; // p0 front and p1 back face ray/depth buffer intersection points
   int n=16; // integration steps
   dl=(p1-p0)/float(n); // integration step vector
   vec3 c=background color;
   float q=dot(normalize(p1-p0),light)=fabs(cos(ang)); // normal light shading

   for (p=p1,i=0;i<n;p1-=dp,i++)                // p = p1 -> p0 path through object
        {
        b=B0.rgb*dl;  // B0 is saturated color of object
        c.r*=1.0-b.r; // some light is absorbed
        c.g*=1.0-b.g;
        c.b*=1.0-b.b;
        c+=b*q;       // some light is scattered in
        } // here c is the final fragment color

在积分之后/进行积分期间,您应该对颜色进行标准化...,以使所得到的颜色在渲染材质的真实视图深度附近达到饱和.有关更多信息,请参见下面的大气散射"链接(此代码是从中提取的)

After/durring the integration you should normalize the color ... so that the resulting color is saturated around the real view depth of the rendered material. for more informatio see the Atmospheric scattering link below (this piece of code is extracted from it)

分析对象表示

如果知道表面方程,则可以计算着色器内的光路交点,而无需深度缓冲区或体素贴图.此我的简单GLSL大气着色器使用此方法,因为用这种方法确实很容易处理椭球.

If you know the surface equation then you can compute the light path intersections inside shader without the need for depth buffers or voxel map. This Simple GLSL Atmospheric shader of mine uses this approach as ellipsoids are really easily handled this way.

光线跟踪器

如果需要精度并且不能使用Voxel贴图,则可以尝试使用光线跟踪引擎.但是无论如何,所有散射渲染器/引擎(包括#1,#2,#3 )都是光线跟踪器...正如您所看到的,所有在这里讨论的技术都是相同是唯一的差异获得射线/物体边界相交点的方法.

If you need precision and can not use Voxel maps then you can try ray-tracing engines instead. But all scattering renderers/engines (#1,#2,#3 included) are ray tracers anyway... As you can see all techniques discussed here are the same the only difference is the method of obtaining the ray/object boundary intersection points.

这篇关于弯曲的磨砂玻璃着色器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆