ios - OpenGL : Circle bevel with fragment shader?

标签 ios opengl-es opengl-es-2.0 fragment-shader

我正在尝试制作一个圆形粒子,看起来它的顶部有一束光。

这是我试图让它看起来像的东西:

particle 1

这是它目前的样子:

enter image description here

因为我使用的是 GL_POINTS,所以我得到了 gl_PointCoord 变量,这应该会让事情变得更容易,除了我不知道如何正确使用它,这导致了这个困惑:

varying lowp vec4 DestinationColor;

void main(void) {
  lowp vec2 circCoord = 2.0 * gl_PointCoord - 1.0;
  if (dot(circCoord, circCoord) > 1.0) {
    discard;
  }
  gl_FragColor = mix(DestinationColor, vec4(1, 0.5, 0.2, 1), (1.0-gl_PointCoord.t)*(max(abs(gl_PointCoord.t-0.5),abs(gl_PointCoord.s-0.5)))); // the world's worst slowest math
}

我非常感谢任何帮助,因为我糟糕的数学技能让我陷入困境。

最佳答案

您可以进行正确的全光照计算。例如,朗伯扩散会像这样工作:

const vec3 lightDir = normalize(vec3(0, 1, -0.5));
const vec3 ambient = ...;
const vec3 lightDiffuse = ...;

vec3 normal = vec3(circCoord, sqrt(1 - dot(circCoord, circCoord)));
float c = max(dot(normal, lightDir), 0);
gl_FracColor = ambient + lightDiffuse*c;

关于ios - OpenGL : Circle bevel with fragment shader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40947092/

相关文章:

ios - 在 iOS 中将 libmosquitto 从 1.1.3 升级到 1.4.8

c++ - 预期的说明符限定符列表之前... C++/Objective-C iPhone 项目中的错误

Android,触摸屏时openGL在jni中滞后

ios - 在 iframe 中打开选择框时,iPhone 中不显示“完成”按钮

ios - .local 域和 iOS/OSX

matrix - 在 ARKit 中将屏幕点取消投影到水平面

ios - 创建 AVPlayer 视频的动画、部分模糊

opengl-es - OpenGL ES 2.x : Bind both `GL_TEXTURE_2D` and `GL_TEXTURE_CUBE_MAP` in the same texture image unit?

android - 实现 GLSurfaceView.Renderer 问题

ios - 为什么在选择日期之前 UIDatePicker 的颜色设置不会激活?