• Advertisement
Sign in to follow this  

Sun projected on Skydome

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello ^^, I'm having a problem with something that should be rather simple : I have a skydome (a sphere), on which I wanna map a sun texture at the sun's position - which basically rotates around the center of the scene. And theres's a strange circle appearing (and rotating with the sun) : PROBLEM : I wanna get rid of that ugly brown circle ! To render this 'sky', I project the sun texture on the skydome using a camera (placed at the center of the scene). The camera always looks at the sun. 1. So I build a projective matrix (sun_texture_matrix)like this : Matrix sun_texture_matrix = camera.view_matrix * camera.proj_matrix * texture_space_matrix; with view_matrix = Matrix.LookAtLH(position, rotation_center, new Vector3(0,1,0)); proj_matrix = Matrix.PerspectiveFovLH((float)(Math.PI / 4.0f),1.0f, 1.0f, 100.0f); texture_space_matrix = |0.5f 0 0 0 | |0 -0.5f 0 0 | |0 0 0 0 | |0.5f 0.5f 1.0f 1.0f| 2. Then VS and PS : VS_OUTPUT VS(VS_INPUT input) { VS_OUTPUT output=(VS_OUTPUT)0; output.outPos = mul(input.inPos, WorldViewProj); output.outPos.z = output.outPos.w; output.texcoord = input.texcoord; output.sun_texcoord = mul(input.inPos,sun_texture_matrix); /* // this one part is to prevent a second sun to be rendered 'on the opposite side' if( output.sun_texcoord.w >= 0) output.sun_texcoord.zw = 0; */ return output; } float4 PS( in float2 texcoord : TEXCOORD0, in float4 sun_texcoord: TEXCOORD1 ) : COLOR0 { float4 sun_col = tex2Dproj(sun_sampler, sun_texcoord * 10.0f); // sun version return sun_col; } I can't find what's wrong - of course the texture is clean. Any of you guys has an idea ??

Share this post


Link to post
Share on other sites
Advertisement
Is the texture set to Clamp, and not mirror or tile?

Share this post


Link to post
Share on other sites
sure :

sampler sun_sampler = sampler_state
{
texture = <sun_tex>;
minfilter = LINEAR;
mipfilter = LINEAR;
magfilter = LINEAR;
addressU = CLAMP;
addressV = CLAMP;
};

Share this post


Link to post
Share on other sites
Okay, so what does it look like if you remove these lines of code:

/*
// this one part is to prevent a second sun to be rendered 'on the opposite side'
if( output.sun_texcoord.w >= 0)
output.sun_texcoord.zw = 0;
*/




obviously -- you'd get two suns, but is the brown circle doubled in width?

Also, could you post the code to the "sun_texture_matrix"?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi,

I think the tri-linear filter causes the ring.
I am not sure why this artifact appears.

Share this post


Link to post
Share on other sites
sirob :
I can't say for sure that it is doubled in width, cause the ring is not 'clean' when I remove the comment (in other words, when I remove the other sun)

All I can say, is that one of the 2 suns (the 'wrong sun')is bigger than the other one.
And the smaller the sun is, the bigger the crown is (yep, not the contrary).

To change the size of the sun I must change the (float)(Math.PI / 4.0f) parameter of the PerspectiveFovLH(...) method.

And here is an example of the sun_texture_matrix:



AP:
I can't understand why the tri-linear would cause this.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oh I just noticed I mistyped this
view_matrix = Matrix.LookAtLH(position, rotation_center, new Vector3(0,1,0));
when it should be :

view_matrix = Matrix.LookAtLH(rotation_center,position,new Vector3(0,1,0));

But I'm still stuck : the ugly crown is still there (though now the wrong sun and the right one have the same size)

Share this post


Link to post
Share on other sites
And here is the sun texture matrix : (the previous one was wrong because of a typo)


Share this post


Link to post
Share on other sites
/*
// this one part is to prevent a second sun to be rendered 'on the opposite side'
if( output.sun_texcoord.w >= 0)
output.sun_texcoord.zw = 0;
*/

That doesn't seem right. You should be clamping the q coordinate ('w') to [0,1] and leaving z alone. And actually, you shouldn't be assigning w to z in the first place, since doing so is nonsensical.

Share this post


Link to post
Share on other sites
Holy shit I made it...
I just tried a few other parameters, that is to say

addressU = BORDER;
addressV = BORDER;

instead of CLAMP

and now everything workds fine :)

Thanks everyone !
PS : I don't understand the slight difference...
This is taken from the SDK doc. :
- Border : Texture coordinates outside the range [0.0, 1.0] are set to the border color.
- Clamp : Texture coordinates outside the range [0.0, 1.0] are set to the texture color at 0.0 or 1.0, respectively.

The texture I have used (and others I have tested) have a clean border, nothing that would cause the crown.

So If anyone has an explanation, I'd be glad to hear it :)

Share this post


Link to post
Share on other sites
Not all cards support border in harware, make sure to test it and have some kind of falback for it.

Share this post


Link to post
Share on other sites
Ok thanks for the info.
Right now I'm working on a little demo for my own, so it doesn't really matters.

But if you have any idea of how I could avoid the BORDER thingy, let me know !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement