Horde3D

Next-Generation Graphics Engine
It is currently 18.04.2024, 13:08

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 05.01.2012, 18:21 
Offline

Joined: 16.05.2009, 12:43
Posts: 207
Hey all.

I'm trying to implement an atmospheric scattering model and I'm having issues with the shader hopefully someone can help me figure out.

I'm basically using a fullscreen quad pass to render the atmosphere. The actual atmosphere will eventually use Eric Bruneton's approach from his Atmospheric Scattering work. But right now I'm simply trying to get the sunlight part working.

heres the basics of erics bit I'm doing first:

VS:

void main()
{
viewDir = (cameraToWorld *(vec4((screenToCamera * glVertex).xyz,0.0)).xyz;
gl_Position = vec4(gl_Vertex.xy,0.999999,1.0);
}

FS:

void main()
{
vec3 v = normalize(viewDir);
vec3 suncolor = vec3(step(cos(3.1415926/180.0),dot(v,worldSunDir))) * SUN_INTENSITY;
}

(I shortened the shader code to make it readable) but in the code above, screenToCamera is the inverse projection matrix. cameraToWorld is the inverse view matrix.


So the drawFSQuad render method basically sets an orthographic projection, with the model view matrix set to the camera as expected. But I need to get a direction vector from the sun (which I'm calculating by subtracting viewerPos from lightPos and normalizing).

so my code baiscally does in the VS:

worldSunDir = normalize(lightPos.xyz - viewerPos);

But of course I need to calculate the viewDir, so my question is how to get the viewDir from a fsQuad pass?

I'm probably looking at it wrongly. But as shaders don't really give any way of debugging them in terms of single stepping, I'm hoping someone with a grasp of Horde's setup will see the issue here.

Ta.


Top
 Profile  
Reply with quote  
PostPosted: 06.01.2012, 12:08 
Offline

Joined: 15.02.2009, 02:13
Posts: 161
Location: Sydney Australia
Hi zoombapup,

Maybe the fs quad doesn't have the viewDir so you might need to make your own. So in the fs quad's material:
Code:
<Uniform name="viewDir" a="0.0" b="-1.0" c="0.0" d="0.0" />

Then whenever you want to set the light direction, maybe for some kind of day/night cycle you can specify some vector manually or query the light itself (just checked, there's no viewDir param? It might need the rotation values and converted to a vector, so some maths involved for that). Also this is untested pseudocode:
Code:
Vec4f myViewDir;

myViewDir.x = 0;
myViewDir.y = -1;
myViewDir.z = 0;
myViewDir.w = 0;

h3dSetMaterialUniform(fsQuadMaterialRes, "viewDir", viewDir.x, viewDir.y, viewDir.z, viewDir.w);

Good luck! This might not be the right way about it. *shrugs*

_________________
-Alex
Website


Top
 Profile  
Reply with quote  
PostPosted: 06.01.2012, 12:26 
Offline

Joined: 16.05.2009, 12:43
Posts: 207
The light has a lightDir that I've been using. But the issue isn't with the position of the sun (or lightsource direction vector in my case) but the view direction with respect to the pixel on the screen.

Thanks for the help, I think I'm going to try and tackle this issue by making a new perspective projection Quad renderer with the same setup as Eric's code, that way I should be able to just drop in his code with a few simple fixups for naming. At least thats the theory, although I do wonder what exactly is wrong with my current approach. As with everything shader wise, its a complete pain in the arse to debug where its going wrong :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group