简体   繁体   English

Three.js - 发光的球体

[英]Three.js - sphere that glows

I have a problem. 我有个问题。 I want to make a sphere which works like a source of light (sun). 我想制作一个像光源(太阳)一样工作的球体。 I found out that meshPhongMaterial has an option like emissive: color and shininess: intensity but I did not manage to code the sun. 我发现meshPhongMaterial有一个选项,如emissive: colorshininess: intensity但我没有设法编码太阳。 Does anyone know how to do it? 有谁知道怎么做? Thank you for answers! 谢谢你的回答!

If you are looking to create a glow-style effect, I have a written a number of examples at http://stemkoski.github.io/Three.js/ that may be helpful, including: 如果你想创造一种发光效果,我在http://stemkoski.github.io/Three.js/上写了一些可能有用的例子,包括:

http://stemkoski.github.io/Three.js/Selective-Glow.html http://stemkoski.github.io/Three.js/Selective-Glow.html
with accompanying blog post 随附博客文章
http://stemkoski.blogspot.com/2013/03/using-shaders-and-selective-glow.html http://stemkoski.blogspot.com/2013/03/using-shaders-and-selective-glow.html

as well as the more atmospheric-style glow effects 以及更具大气风格的发光效果

http://stemkoski.github.io/Three.js/Atmosphere.html http://stemkoski.github.io/Three.js/Atmosphere.html
and
http://stemkoski.github.io/Three.js/Shader-Halo.html http://stemkoski.github.io/Three.js/Shader-Halo.html

Hope this helps! 希望这可以帮助!

Since you don't have a specific problem, I can't give you a specific answer. 由于您没有具体问题,我无法给您一个具体的答案。 You seem a little lost though, so here's the thing you may be missing: In order for something to look like a source of light it must do two things: 你似乎有点失落,所以这就是你可能缺少的东西:为了使某些东西看起来像光源,它必须做两件事:

  1. Illuminate: You achieve this by creating a new Light object inside it. 照亮:您可以通过在其中创建一个新的Light对象来实现此目的。 It is a good idea to put both your object and the light inside a new THREE.Object3D. 将对象和光源放在新的THREE.Object3D中是个好主意。
  2. Glow: You will need to create a shader to blure the pixels around that object. 发光:您需要创建一个着色器来对该对象周围的像素进行模糊处理。 I found a tutorial specific for three.js for you here: Three.js glow tutorial . 我在这里找到了一个特定于three.js的教程: Three.js发光教程

There are more advanced techniques which you could try, like adding godrays . 您可以尝试更多高级技术,例如添加godrays

I wish you luck. 祝你好运。

meshPhong material has parameters 'emissive' and 'shininess' that affect the calculations within material shader, but those won't give you the effect that you want, they are just used for calculating final color. meshPhong材质具有参数'emissive'和'shininess',它们会影响材质着色器中的计算,但这些参数不会提供您想要的效果,它们仅用于计算最终颜色。

You can put spotlight, for example, at the exact position as the sphere, so it would lighten up object around it. 例如,你可以把聚光灯放在与球体一样的确切位置,这样它就会照亮它周围的物体。 However, if you want to achieve the effect of glowing sphere, you would have to write post-processing shader: 但是,如果要实现发光球体的效果,则必须编写后处理着色器:

  • Render sphere to framebuffer 1. 渲染球体到帧缓冲区1。
  • Render same sphere colored yellow (or some other bright color) to framebuffer 2. 将相同的球体颜色为黄色(或其他一些亮色)渲染到帧缓冲区2。
  • Blur content in framebuffer 2 as post-processing effect. 将帧缓冲区2中的内容模糊为后处理效果。
  • Blend original image (framebuffer 1) and blurred framebuffer 2 together to produce the final image. 将原始图像(帧缓冲区1)和模糊帧缓冲区2混合在一起以生成最终图像。

Also, some examples don't use actual post-processing to achieve glowing, but they use trick. 此外,一些示例不使用实际的后处理来实现发光,但它们使用技巧。

You render sphere and then render some quad with "glow aura" texture in the back. 渲染球体,然后在背面渲染一些带有“发光光环”纹理的四边形。 Visit: http://threegraphs.com/charts/sample/world/ to see how you can maybe simulate glow and create eclipse-like circle around sphere. 访问: http//threegraphs.com/charts/sample/world/ ,了解如何模拟发光并在球体周围创建类似日食的圆圈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM