How to make a Sun (physical)

Started by
21 comments, last by scope 13 years, 11 months ago
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.
Advertisement
What's wrong with a white sphere? Or am i missing the point?
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.
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.
so just a sphere ?
I'd have to deactivate depth as I did with the skydome then, right ?
Quote:Original post by lipsryme
so 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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
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:

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]
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.

vertex shader:

   output.Vertex = input.Position;   output.Position = mul(float4(input.Position.xyz , 1.0f) , MatWVP);
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 ?

This topic is closed to new replies.

Advertisement