Horde3D http://horde3d.org/forums/ |
|
Getting correct position for pixel in fullscreen quad render http://horde3d.org/forums/viewtopic.php?f=1&t=1620 |
Page 1 of 1 |
Author: | zoombapup [ 05.01.2012, 18:21 ] |
Post subject: | Getting correct position for pixel in fullscreen quad render |
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. |
Author: | MistaED [ 06.01.2012, 12:08 ] |
Post subject: | Re: Getting correct position for pixel in fullscreen quad re |
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* |
Author: | zoombapup [ 06.01.2012, 12:26 ] |
Post subject: | Re: Getting correct position for pixel in fullscreen quad re |
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 |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |