Sun in HLSL

Started by
3 comments, last by blue_knight 17 years, 11 months ago
well, i'm trying to render the sunshine directly on the skysphere, without using any textures, because i think that works much better. but i'm having problems with this. i gave the position of the sun to the shader, wich then calculates the dot product between the normal of the sphere and the position of the sun ( both vectors are being normalized before that ). but this would lighten half the sky. but i would really like to come to this result: so i tried to scale down the dot product, that it would only influence a small amount of the sky:

Hemi = saturate(dot(normalize(lightDir), normalize(mul(Normal, matRotation))));
tempDiffuse = saturate(lerp(-20.0f, 1.0f, Hemi)) * SkyDome_Aequator * 0.5f;

but unfortunately this lightens no circle but some kind of weird rectangle ( with bowed edges ): perhaps i try to approach it from the wrong direction, but how can i achieve the desired effect?
Advertisement
You want to raise the dot product to a power, like specular highlights. Essentially (N.L)^p, where N = sphere normal (pointing in), L is the light direction (pointing toward the direction of the light) and p is some power that generates the highlight the size you want.
The way the central area looks makes me think you're simply using a texture that's too small, and the bizarre creation you're seeing is the MagFilter doing it's linear interpolation on 3*6 pixels... Just an idea.
i am using no texture at all. i'm just playing around with the dot product and the pixel shader.

i tried different methods, but they all ended in the same way:

return pow(Hemi, 20) * SkyDome_Aequator;
gave: this

return smoothstep(0.0f, 0.03f, Hemi - 0.97) * SkyDome_Aequator;
gave: this

i really don't know whats going wrong here -.-
Are you doing the calculation in the pixel shader? It looks like you're doing it in the vertex shader and the problem is that there isn't enough vertex density. If so try moving the calculation to the pixel shader and you shouldn't see this type of artifacting at all.

This topic is closed to new replies.

Advertisement