# Starry Shader for Sky Sphere

**URL:** https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578
**Category:** Showcase
**Tags:** materials, shaders, shader-material, fragment-shader
**Created:** [May 16, 2019, 7:48am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578 "2019-05-16T07:48:09Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![sneha-belkhale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sneha-belkhale/32/10606_2.png) [@sneha-belkhale](https://discourse.threejs.org/u/sneha-belkhale)
#### Post date: [May 16, 2019, 7:48am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/1 "2019-05-16T07:48:09Z")

</div>

Thought i’d share a starry sky shader that I am applying to a sky sphere in one of my recent projects. Fully procedural, and generated with layers of perlin noise in the shader ( no particles ).

Check out the isolated example here :  
[https://stackblitz.com/edit/starry-skydome](https://stackblitz.com/edit/starry-skydome)

![50%20PM](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/1/123656fcf6baa76923a045dd04e43c46dd528f68.jpeg) ![56%20PM](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/0/0a66750e69dfa1b8ff8f81d3c06ab311ebf623a6.jpeg)

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [May 16, 2019, 7:58am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/2 "2019-05-16T07:58:38Z")

</div>

Very cool visual effect! 👍  
And thanks for sharing 🍻

---

<div class="post-metadata">

### Author: ![sciecode](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sciecode/32/5623_2.png) [@sciecode](https://discourse.threejs.org/u/sciecode)
#### Post date: [May 16, 2019, 3:41pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/3 "2019-05-16T15:41:48Z")

</div>

Looks really good! Amazing job.

---

<div class="post-metadata">

### Author: ![Usnul](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/usnul/32/2355_2.png) [@Usnul](https://discourse.threejs.org/u/Usnul)
#### Post date: [May 16, 2019, 6:00pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/4 "2019-05-16T18:00:02Z")

</div>

Your screenshot looks really cool. I don’t get the same effect when i use the link though:  
 ![image](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/9/98058e7062d7ca2fbe0309d99ec32ccb949be21f.png)

---

<div class="post-metadata">

### Author: ![titansoftime](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/titansoftime/32/1044_2.png) [@titansoftime](https://discourse.threejs.org/u/titansoftime)
#### Post date: [May 16, 2019, 11:32pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/5 "2019-05-16T23:32:42Z")

</div>

I get the same thing.

---

<div class="post-metadata">

### Author: ![sneha-belkhale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sneha-belkhale/32/10606_2.png) [@sneha-belkhale](https://discourse.threejs.org/u/sneha-belkhale)
#### Post date: [May 17, 2019, 1:14am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/6 "2019-05-17T01:14:35Z")

</div>

@titansoftime & @Usnul whoa that’s interesting…the link definitely works for me on Chrome on my Macbook… what device/browser are you using?

---

<div class="post-metadata">

### Author: ![titansoftime](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/titansoftime/32/1044_2.png) [@titansoftime](https://discourse.threejs.org/u/titansoftime)
#### Post date: [May 17, 2019, 2:53am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/7 "2019-05-17T02:53:33Z")

</div>

Desktop Windows 10 Chrome 74 GeForce GTX 1060  
Mobile Android Samsung Galaxy s7 Chrome

Both get the same results.

Here is a console log, not sure if this is part of the issue or just some typical stackblitz issue.

![image](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/f/f17c13e9e9f7f9c37668a8a9bbd97025a7ff83f5.png)

![image](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/0/02dcc3a4db3d05e95f9e46c83d8d30f722e2728b.png)

---

<div class="post-metadata">

### Author: ![sneha-belkhale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sneha-belkhale/32/10606_2.png) [@sneha-belkhale](https://discourse.threejs.org/u/sneha-belkhale)
#### Post date: [May 17, 2019, 4:04am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/8 "2019-05-17T04:04:47Z")

</div>

@titansoftime

yeah I get those errors too, they are just stackblitz issues… would you mind trying out this link as well?

[https://codercat.tk/three-body](https://codercat.tk/three-body)

^^ it’s the project where I use this sky shader… just trying to narrow down the problem, see if it’s anyway related to stackblitz.

thanks 🙂

---

<div class="post-metadata">

### Author: ![sciecode](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sciecode/32/5623_2.png) [@sciecode](https://discourse.threejs.org/u/sciecode)
#### Post date: [May 17, 2019, 4:20am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/9 "2019-05-17T04:20:26Z")

</div>

Desktop Windows 10 Chrome 74 GeForce GTX 750 TI

It works for me on both links.

But damn! that sudden sound almost made me deaf on the project link. 🤣

---

<div class="post-metadata">

### Author: ![sneha-belkhale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sneha-belkhale/32/10606_2.png) [@sneha-belkhale](https://discourse.threejs.org/u/sneha-belkhale)
#### Post date: [May 17, 2019, 4:22am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/10 "2019-05-17T04:22:48Z")

</div>

@sciecode, thanks for checking the link 🙂 and sorry about that … the project is still very work in progress~~ actually adding a sound on/off button at the moment

---

<div class="post-metadata">

### Author: ![Usnul](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/usnul/32/2355_2.png) [@Usnul](https://discourse.threejs.org/u/Usnul)
#### Post date: [May 17, 2019, 5:21am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/11 "2019-05-17T05:21:31Z")

</div>

![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/c/c0c9ede2cf02ee38896440cded3dc373632932c7.jpeg)

Also broken, only see one body 😛

my specs:

Win10, GTX 1080, Chrome Version 74.0.3729.157 (Official Build) (64-bit)

---

<div class="post-metadata">

### Author: ![sneha-belkhale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sneha-belkhale/32/10606_2.png) [@sneha-belkhale](https://discourse.threejs.org/u/sneha-belkhale)
#### Post date: [May 18, 2019, 3:51am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/12 "2019-05-18T03:51:08Z")

</div>

wow so strange. must be a really low level issue. I wish I could debug it but need access to a machine with either a GTX 1080 or GTX 1060…

---

<div class="post-metadata">

### Author: ![Aerion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aerion/32/6633_2.png) [@Aerion](https://discourse.threejs.org/u/Aerion)
#### Post date: [August 21, 2019, 6:45pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/13 "2019-08-21T18:45:26Z")

</div>

Can somebody upload a copy of this? The link to the starry sky demo is dead. Thank you!

---

<div class="post-metadata">

### Author: ![Andre\_Almeida](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Andre\_Almeida](https://discourse.threejs.org/u/Andre_Almeida)
#### Post date: [February 20, 2020, 1:40am UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/14 "2020-02-20T01:40:46Z")

</div>

Did you get to the bottom of this? What was the issue with Windows 10 GeForce GTX?

---

<div class="post-metadata">

### Author: ![Andre\_Almeida](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Andre\_Almeida](https://discourse.threejs.org/u/Andre_Almeida)
#### Post date: [February 20, 2020, 6:02pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/15 "2020-02-20T18:02:40Z")

</div>

Found the issue! Threejs shows the GPU warning " pow(f, e) will not work for negative f". Just put abs(f) in the first argument of pow() functions and it will work 🙂

---

<div class="post-metadata">

### Author: ![Aerion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aerion/32/6633_2.png) [@Aerion](https://discourse.threejs.org/u/Aerion)
#### Post date: [April 17, 2020, 6:51pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/16 "2020-04-17T18:51:23Z")

</div>

Sorry for reviving this, but I would like to know where in the shader I have to fix to get this to work with three.js r115? Thank you!

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [April 17, 2020, 7:08pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/17 "2020-04-17T19:08:51Z")

</div>

@Aerion  
Where? O\_o [https://stackblitz.com/edit/starry-skydome?file=StarrySkyShader.js](https://stackblitz.com/edit/starry-skydome?file=StarrySkyShader.js)

And the lines with the fix are 108 - 110:

```auto
float cs = pow(abs(cnoise(scaledClusterSize*vPos+noiseOffset)),1.0/clusterStrength) + cnoise(scaledStarSize*vPos);

float c =clamp(pow(abs(cs), 1.0/starDensity),0.0,1.0);

```

---

<div class="post-metadata">

### Author: ![Aerion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aerion/32/6633_2.png) [@Aerion](https://discourse.threejs.org/u/Aerion)
#### Post date: [April 17, 2020, 7:11pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/18 "2020-04-17T19:11:08Z")

</div>

@prisoner849 : Thank you! Is there a way to make the stars randomly blink with a manually set time / speed modifier & add / remove more stars? Thank you so much! 🙂

Edit : Also, I noticed this :

 ![weird-stars](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/1/1dac22ae6badb86ada4c4212f46f7bf793221057.png)

Is there a way to fix that or remove it & remove the aurora?

Thank you so kindly! 🙂

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [April 17, 2020, 7:38pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/19 "2020-04-17T19:38:19Z")

</div>

@Aerion  
Add a uniform with time and then use that noise function to make twinkle stars 🙂

PS I don’t know how to remove that star cluster.

---

<div class="post-metadata">

### Author: ![Aerion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aerion/32/6633_2.png) [@Aerion](https://discourse.threejs.org/u/Aerion)
#### Post date: [April 17, 2020, 7:40pm UTC](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578/20 "2020-04-17T19:40:25Z")

</div>

@prisoner849 or anyone else : I’m not good with shaders. How would you do it?

[Next page](https://discourse.threejs.org/t/starry-shader-for-sky-sphere/7578.md?page=2)
