# How to make a Sun (physical)

This topic is 3186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, right now I'm doing an outside scene with daytime change but I've got a problem with the sun. Well of course the Sun would be the directional lighting but I want to have a sun on the horizon that I can translate according to the daytime. I've been trying to figure out a way to do that but I can't think of anything that'll work. Does any here have an idea how I can do that ? It doesn't have to be the best looking way.

##### Share on other sites
What's wrong with a white sphere? Or am i missing the point?

##### Share on other sites
Umm.....white sphere ?
I just want to know how to make a sun on the horizon (skydome) that I can move according to the current daytime.

##### Share on other sites
Well the sky dome i just a hemisphere that moves with the camera, draw a sphere just inside it that also moves with the camera.

##### Share on other sites
so just a sphere ?
I'd have to deactivate depth as I did with the skydome then, right ?

##### Share on other sites
Quote:
 Original post by lipsrymeso just a sphere ?I'd have to deactivate depth as I did with the skydome then, right ?

Disable writes, but enable tests. Quick rule of thumb for this-- if you want it to be *hidden by* things, such as terrain, enable testing. If you want it to *hide* things, then enable writes.

##### Share on other sites
or you could compute the sun in the pixel shader for example like this

float3 norm = normalize(input.vertex);float3 Sun = normalize(SunPos);float  SunDot = dot(Sun, norm);vector sun = 0.5f * pow( max(0, SunDot), 300.0f );

code in action:

##### Share on other sites
Could you explain the last two lines?

Also what's with the normal calculation?
Do I draw a single vertex with Pos, Color and Normal ?
And where would the normal of that vertex point to ?

[Edited by - lipsryme on May 1, 2010 2:33:38 PM]

##### Share on other sites
well i'm not the best at explaining these thing but i'll give it a try:

You have a normal from the current pixel and one for the sun position. the smaller the angle between those, the bigger the dot product. the pow() is used to control the attenution.

Quote:
 Also what's with the normal calculation?Do I draw a single vertex with Pos, Color and Normal ?[

No, you just have to pass the untransformed vertex position to the pixel shader to compute the normal because it is assumed that all faces of the skydome point to the center of the skydome.

   output.Vertex = input.Position;   output.Position = mul(float4(input.Position.xyz , 1.0f) , MatWVP);

##### Share on other sites
Hmm I don't quite get it.

So...the input.vertex is the untransformed Vertex Position of the Skydome ?

And the variable "norm" would then be the position vector of the Skydome pixel we are looking at ?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 30
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015591
×