<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.stephanschlegel.de/index.php?action=history&amp;feed=atom&amp;title=Three.js_-_Fireflies_Shader</id>
	<title>Three.js - Fireflies Shader - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stephanschlegel.de/index.php?action=history&amp;feed=atom&amp;title=Three.js_-_Fireflies_Shader"/>
	<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Fireflies_Shader&amp;action=history"/>
	<updated>2026-05-06T15:33:25Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Wikizone</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Fireflies_Shader&amp;diff=25869&amp;oldid=prev</id>
		<title>134.3.74.15 am 6. Februar 2022 um 10:07 Uhr</title>
		<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Fireflies_Shader&amp;diff=25869&amp;oldid=prev"/>
		<updated>2022-02-06T10:07:29Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;de&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Nächstältere Version&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version vom 6. Februar 2022, 10:07 Uhr&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Zeile 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Links ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; [[Three.js - Shaders]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Beispiel ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;script.js&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;script.js&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>134.3.74.15</name></author>
	</entry>
	<entry>
		<id>https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Fireflies_Shader&amp;diff=25866&amp;oldid=prev</id>
		<title>134.3.74.15: Die Seite wurde neu angelegt: „script.js &lt;syntaxhighlight lang=&quot;javascript&quot;&gt; import firefliesVertexShader from &#039;./shaders/fireflies/vertex.glsl&#039; import firefliesFragmentShader from &#039;./shader…“</title>
		<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Fireflies_Shader&amp;diff=25866&amp;oldid=prev"/>
		<updated>2022-02-06T10:00:02Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „script.js &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt; import firefliesVertexShader from &amp;#039;./shaders/fireflies/vertex.glsl&amp;#039; import firefliesFragmentShader from &amp;#039;./shader…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;script.js&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
import firefliesVertexShader from &amp;#039;./shaders/fireflies/vertex.glsl&amp;#039;&lt;br /&gt;
import firefliesFragmentShader from &amp;#039;./shaders/fireflies/fragment.glsl&amp;#039;&lt;br /&gt;
&lt;br /&gt;
//...&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Fireflies&lt;br /&gt;
 */&lt;br /&gt;
const firefliesGeometry = new THREE.BufferGeometry()&lt;br /&gt;
const firefliesCount = 30&lt;br /&gt;
const positionArray = new Float32Array(firefliesCount * 3)&lt;br /&gt;
const scaleArray = new Float32Array(firefliesCount)&lt;br /&gt;
for(let i = 0; i &amp;lt; firefliesCount; i++){&lt;br /&gt;
    positionArray[i * 3 + 0] = ( Math.random() -0.5) * 4.5 // from -0.5 to 4&lt;br /&gt;
    positionArray[i * 3 + 1] = ( Math.random() + 0.05) * 3 // from 0.05 to 2.95&lt;br /&gt;
    positionArray[i * 3 + 2] = ( Math.random() ) * 4.5 // from 0 to 4.5&lt;br /&gt;
    scaleArray[i] = Math.random()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
firefliesGeometry.setAttribute(&amp;#039;position&amp;#039;, new THREE.BufferAttribute(positionArray, 3))&lt;br /&gt;
firefliesGeometry.setAttribute(&amp;#039;aScale&amp;#039;, new THREE.BufferAttribute(scaleArray, 1))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//const firefliesMaterial = new THREE.PointsMaterial({ size: 0.1, sizeAttenuation: true })&lt;br /&gt;
const firefliesMaterial = new THREE.ShaderMaterial({&lt;br /&gt;
    transparent: true,&lt;br /&gt;
    blending: THREE.AdditiveBlending,&lt;br /&gt;
    depthWrite: false, // fixes some clipping issues&lt;br /&gt;
    uniforms:{&lt;br /&gt;
        uPixelRatio : {value: Math.min(window.devicePixelRatio, 2)},&lt;br /&gt;
        uSize: { value: 100 },&lt;br /&gt;
        uTime: { value: 0 }&lt;br /&gt;
    },&lt;br /&gt;
    vertexShader: firefliesVertexShader,&lt;br /&gt;
    fragmentShader: firefliesFragmentShader&lt;br /&gt;
})&lt;br /&gt;
const fireflies = new THREE.Points(firefliesGeometry, firefliesMaterial)&lt;br /&gt;
scene.add(fireflies)&lt;br /&gt;
gui.add(firefliesMaterial.uniforms.uSize, &amp;#039;value&amp;#039;).min(0).max(500).step(1).name(&amp;#039;firefliesSize&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
// ...&lt;br /&gt;
&lt;br /&gt;
window.addEventListener(&amp;#039;resize&amp;#039;, () =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    // ...&lt;br /&gt;
    // Update fireflies &lt;br /&gt;
    // Update ratio in case s.o. has different screens&lt;br /&gt;
    firefliesMaterial.uniforms.uPixelRatio.value = Math.min(window.devicePixelRatio, 2)&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vertex.glsl&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
uniform float uPixelRatio;&lt;br /&gt;
uniform float uSize;&lt;br /&gt;
uniform float uTime;&lt;br /&gt;
attribute float aScale;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    vec4 modelPosition = modelMatrix * vec4(position, 1.0);&lt;br /&gt;
    modelPosition.y += sin(uTime + modelPosition.x * 100.0) * aScale * 0.2; &lt;br /&gt;
    // move up and down and use x pos to create a offset&lt;br /&gt;
    // * aScale -&amp;gt; reduce Amplitude more for smaller fireflies&lt;br /&gt;
    // * 0.2 -&amp;gt; reduce amplitude in general&lt;br /&gt;
    vec4 viewPosition = viewMatrix * modelPosition;&lt;br /&gt;
    vec4 projectionPosition = projectionMatrix * viewPosition;&lt;br /&gt;
&lt;br /&gt;
    gl_Position = projectionPosition;&lt;br /&gt;
    &lt;br /&gt;
    // Take care of retinas etc but not more than 2 (performance)&lt;br /&gt;
    gl_PointSize = uSize * uPixelRatio * aScale; &lt;br /&gt;
    gl_PointSize *= (1.0 / - viewPosition.z); // size attenuation (far-&amp;gt;smaller)&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
fragment.glsl&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  //gl_FragColor = vec4(gl_PointCoord, 1.0, 1.0);&lt;br /&gt;
  float distanceToCenter = distance(gl_PointCoord, vec2(0.5));&lt;br /&gt;
  float strength = 0.05 / distanceToCenter - 0.1; // -0.1 that our formular reaches 0. Otherwise we&amp;#039;d see borders&lt;br /&gt;
  gl_FragColor = vec4(1.0, 1.0, 1.0, strength);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>134.3.74.15</name></author>
	</entry>
</feed>