OpenGL ES - 如何在Blender Cycles Render中实现Glossy Shader?

时间:2014-11-17 01:21:59

标签: android opengl-es blender

Blender周期渲染中,有一个名为Glossy的着色器类型。现在我想在Android上使用OpenGL ES 2.0实现这个光泽着色器。我想知道在哪里可以找到这个着色器的GLSL实现?下面是显示光泽反射的图像(参见平面上的反射)。 enter image description here

1 个答案:

答案 0 :(得分:0)

该效果基本上只是一个高斯模糊滤镜。这些文件中的PowerVR SDK中有一个很好的OpenGL ES 2.0示例:

\实例\中间体\布卢姆\ OGLES2 \ BlurVertShader.vsh:

// Blur filter kernel shader
//
// 0  1  2  3  4
// x--x--X--x--x    <- original filter kernel
//   y---X---y      <- filter kernel abusing the hardware texture filtering
//       |
//      texel center
//
// 
// Using hardware texture filtering, the amount of samples can be
// reduced to three. To calculate the offset, use this formula:
// d = w1 / (w1 + w2),  whereas w1 and w2 denote the filter kernel weights

attribute highp   vec3  inVertex;
attribute mediump vec2  inTexCoord;

uniform mediump float  TexelOffsetX;
uniform mediump float  TexelOffsetY;

varying mediump vec2  TexCoord0;
varying mediump vec2  TexCoord1;
varying mediump vec2  TexCoord2;

void main()
{
    // Pass through vertex
    gl_Position = vec4(inVertex, 1.0);

    // Calculate texture offsets and pass through   
    mediump vec2 offset = vec2(TexelOffsetX, TexelOffsetY);

    TexCoord0 = inTexCoord - offset;
    TexCoord1 = inTexCoord;
    TexCoord2 = inTexCoord + offset;    

}

\实例\中间体\布卢姆\ OGLES2 \ BlurFragShader.vsh:

uniform lowp sampler2D  sTexture;

/* 
  Separated Gaussian 5x5 filter, first row:         1  5  6  5  1
*/

varying mediump vec2  TexCoord0;
varying mediump vec2  TexCoord1;
varying mediump vec2  TexCoord2;

void main()
{
    lowp vec3 color = texture2D(sTexture, TexCoord0).rgb * 0.333333;
    color = color + texture2D(sTexture, TexCoord1).rgb * 0.333333;
    color = color + texture2D(sTexture, TexCoord2).rgb * 0.333333;    

    gl_FragColor.rgb = color;
}