SONB
Member
|
"EVE Online" like sun effect?
Hi!
EVE Online has a great sun effect, which I want to replicate in my project but I think it can only be done with a shader. The problem is that Esenthel doesn't support custom shaders, so my question is: Is there another way to achieve this effect?
Here is a screenshot from the game:
The effect I mean is this light distortion (horizontal lines coming out of the sun). I'm gonna try to create a custom sun texture with these lines but I don't think it would look as good as in EVE.
Thanx a lot for any suggestion
SONB
|
|
03-02-2009 03:52 PM |
|
Esenthel
Administrator
|
Re: "EVE Online" like sun effect?
using the Sun is one method.
but you can try using a simple 2D Gfx::draw after all 3d graphics
void render()
{
}
void draw()
{
Renderer(render);
lens_flare.draw(..);
}
|
|
03-02-2009 04:29 PM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Well, the custom sun texture doesn't look nice.
Esenthel, for the method you mentioned I need to know the screen coordinates of the sun and whether it is behind an object.
And I need to know, how much the sun is occluded by an object to know how much I should blend in/out my 2D gfx.
Can you help me with these two questions?
Thanx!
|
|
03-03-2009 04:56 AM |
|
Esenthel
Administrator
|
Re: "EVE Online" like sun effect?
converting world space to screen coordinates is done via PosToScreen
current camera position is Cam.matrix.pos
Sun position is Suns[0].pos (it is a position on sphere with radius=1)
for simple testing if the sun is occluded you can cast a physical ray from the camera to the sun direction * Viewport range
|
|
03-03-2009 11:37 AM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Ok, so to draw my gfx I do the following:
Code:
gfx->draw(PosToScreen(Suns[0].pos),0.5,0.5);
Is this right?
It works, kind of.. I mean, when the sun is in the center, my gfx is in the center of the sun but when the sun is near to the edge of the screen, the gfx is displayed with an offset to the sun, not in its center. I think it has something to do with the distortion of the camera..?
And why do I need current camera position?
|
|
03-03-2009 12:05 PM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Ah, nevermind, I got it!
I have to apply the camera position to the sun position, now the gfx is always displayed in the center of the sun.
Thank you very much, Esenthel!
|
|
03-03-2009 12:19 PM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Esenthel, I've got a problem, maybe a bug(?)
My gfx is displayed twice. One is displayed correctly at the sun and another behind the camera :? So when I turn around, I see this second gfx.
My code:
Code:
gfx->draw(PosToScreen(Cam.matrix.pos + Suns[0].pos) - Vec2(0.25,-0.25),0.5,0.5);
I do Vec2(0.25,-0.25) to center my gfx.
|
|
03-03-2009 12:55 PM |
|
Esenthel
Administrator
|
Re: "EVE Online" like sun effect?
you are using this function
Vec2 PosToScreen (Vec &pos );
because if it's nature (type) it is forced to always return a Vec2, even if the 3D point is behind the camera
you should use the other version of this function:
Bool PosToScreen (Vec &pos,Vec2 &screen); // convert 3D position to 2D screen position , false on fail (point is behind the camera)
also instead of manual centering the image
you can use this function
Gfx::drawCenter
|
|
03-03-2009 01:32 PM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Thanx, it works!
Here is the code:
Code:
void DrawGame()
{
Renderer(Render);
Vec2 scr;
if(PosToScreen(Cam.matrix.pos + Suns[0].pos, scr)) {
gfx->drawCenter(scr,0.5,0.5);
}
}
|
|
03-03-2009 02:28 PM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Esenthel Wrote:for simple testing if the sun is occluded you can cast a physical ray from the camera to the sun direction * Viewport range
Ok, first I tried to cast one physical ray and made it visible like in youre Testing tutorial. It looked ok. Then I tried to cast 20 rays in circle shape:
Code:
start = Vec(Cam.matrix.pos);
REP(20) {
Vec2 c = Rnd(Circle(3),false);
end = Suns[0].pos * Viewport.range + c.xy0() + Cam.matrix.pos;
// Here I display the rays with dots at their ends
}
I expected to see a perfect circle of rays' dots around the sun but all I see is a distorted circle, like an ellipse, and it is more distorted at the edges of the screen.
Should I use here the same PosToScreen method like I did with my lens flare gfx above to cast rays in a perfect circle?
|
|
03-05-2009 09:15 AM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
Well, somehow I figured it out..
Code:
Vec2 c, cScr;
REP(20) {
c = Rnd(Circle(60),false);
cScr = PosToScreen(Cam.matrix.pos + Suns[0].pos * Viewport.range);
end = ScreenToPos(cScr + c) + Suns[0].pos * Viewport.range;
// Here I display the rays with dots at their ends
}
The rays' points build a perfect circle now.
Now I need once to generate constant end position, not random like in the code above, and the work is done.
Esenthel, is this a good approach, first to get screen coordinates and then convert them back to world? Or is there a shorter way?
|
|
03-05-2009 11:20 AM |
|
Esenthel
Administrator
|
Re: "EVE Online" like sun effect?
Matrix3 matrix;
matrix.setDir(Suns[0].pos);
// from now on matrix.z=sun direction
// matrix.x=sun right vector
// matrix.y=sun up vector
multiply your XY (from random Circle, or from Sin/Cos functions) offsets by matrix.x and matrix.y
|
|
03-05-2009 12:13 PM |
|
SONB
Member
|
Re: "EVE Online" like sun effect?
No, it's still distorted, but this time only at screen edges. My code is definitely wrong :? :
Code:
Vec2 c[40];
REP(40) {
c[i] *= Matrix().rotateZ(DegToRad(9));
c[i].setLength(6);
}
REP(40) {
Matrix3 matrix;
matrix.setDir(Suns[0].pos);
Vec a = matrix.x * c[i].x + matrix.y * c[i].y + matrix.z * Viewport.range;
Vec end = a + Cam.matrix.pos;
// Here I display the rays with dots at their ends
}
This is the multiplication which makes problems, right?
|
|
03-05-2009 05:12 PM |
|