How does one create an object that is semi-translucent to light. I would like to block point light source to create an effect similar to that one shown in the image. Note the smooth transition, because the light permeability of blocker was gradually decreasing. How can I achieve this in libgdx? There is no need for a blocker, if there is another way to do this I am open to it.
Blocker present:
Blocker not present:
Ended up using ambient light with black and white gradient texture applied to the material I wanted to mask.
Related
I am rendering some interactive scene in 3D and I am wondering: How do I add sunlight to it? I'll try to explain the best how I have it setup now.
What you see right now is that the directional light (the sun) is denoted by the yellow dot, which I want to replace with a realistic sunlight.
The current order of drawing is:
For all objects:
Do a light depth pass for the shadow.
Then for all objects:
Do a draw pass for the object itself, using the light depth texture.
Where would I add adding a realistic sunlight? I have a few ideas though about it:
After the current drawing order, save the output into a texture, and use a shader that takes the texture and adds sunlight on top of it.
After the current drawing order, use a shader that adds the sunlight simply to what has been drawn so far, such that it will be drawn after everything is on the screen.
Or maybe draw the sunlight before the rest of the scene gets drawn?
How would you deal with rendering a nice sunlight that represents a real life sun?
To realistically simulate sunlight, you probably need to implement some form of global illumination. A lot of the lighting we see on objects comes not directly from the light source, but from light bounced off of other objects. Global illumination simulates the bounced light.
[Global Illumination] take[s] into account not only the light which comes directly from a light source (direct illumination), but also subsequent cases in which light rays from the same source are reflected by other surfaces in the scene, whether reflective or not (indirect illumination).
Another techniques that may not be physically accurate, but gives "nice" looking results is Ambient Occlusion:
ambient occlusion is used to represent how exposed each point in a scene is to ambient lighting. So the enclosed inside of a tube is typically more occluded (and hence darker) than the exposed outer surfaces; and deeper inside the tube, the more occluded (and darker) it becomes.
I just implemented a light system in my engine. In the following screenshot you can see a light (the yellow square) in action:
Take into account that on top of the light illuminating the scenario, its also implemented a FOV which will occlude anything outside your field of view. Thats why the left part of the shadow seems so off.
As you can see the light's shadows are pretty "hard", as they won't even illuminate one bit of the area outside its direct reach.
In order to make the lights look better, I applied a filter to them, which pretty much limits the range to be illuminated, and also iluminate the area slightly within this limit:
In the big yellow circle you can see how the area is illuminated even if no direct light reaches it.
This solution however comes with some undesirable side effects. As you can see in the following screenshot, even if no light at all reaches an area, it will be illuminated if its too close to the light source:
I was wondering if there is any way to achieve what im trying to do by using shaders properly.
The main problem that I encounter comes from how I draw these shadows.
1) First I take the structures within the light's range.
At this point, I'm working with vertex, as they define the area of the shadow casting items:
2) Then, for each of these objects, I calculate the shadow they cast individually:
The shadow they cast is done by the CPU, by calpulating projections for each vertex of the body.
3) Then the GPU draws these shapes into a texture to compose the final shadow:
The problem I find is that making this difuse shadow effect, I need the final shadow. If I were to calculate the diffused shadows in step 2), a gap of light would appear between solids B and C.
But if I difuse the shadows in step 3, I no longer have the vertex information, as all the info I have are the 3 local textures added up together in one final texture.
So, is there anyway to achieve this? My first idea would be to pass a varying to the fragmentshader to calculate how much light comes into the dark area, but since I'll be processing this info on the final shadow, which has no vertex information, I'm completely lost about what approach I should use to make this.
I might be completely wrong on this approach, since I have very very limited experience with shaders.
Here is an example of what I have right now, and what I desire:
What I have: Plain illumination withing the light radius (which causes the light to clip through walls.
What I want: Shadow is more intense the farther away it is from where the light ends.
I think that no matter what you do, you're going to have to calculate the light falloff differently for the areas of the scene that don't have direct visibility to the original light source. I'm not sure how you're actually applying the shadow volume to the scene, but you might be able to do something like classify the edges as you're generating the shadow volume (i.e. did they come from a wall or from the line from the light to a corner?), and treat them accordingly.
In short I don't think there's any clever shader-specific trick you can pull off to fix this problem. It's a limitation of the algorithm you're using, so you need to improve the algorithm to take into account the different nature of the edges in your shadow volume.
--- Edit ---
Ok I think your best bet is going to be to create two shadow volumes (or rather shadow areas since we're working in 2D). One will be exactly as you have now, the other will be smaller -- you'll want to exclude the areas that are in "soft" shadow. Then you'll have three categories in your fragment shader: total shadow, soft shadow, and unshadowed.
To create the second shadow map, I think you'll want to do something like add a fixed angle to the edges that are created by the light shining around a corner.
--- Edit #2 ---
I think you can solve the problem of the gap between objects B and C by taking the silhouette of the shadow areas and the outer box of the scene. So for each of your shadow areas, you'd find the two outermost points that intersect the outer box, then throw out all the line segments in between and replace them with that portion of the box. I feel like I should be able to name that algorithm but it escapes me at the moment...
Original Scene:
Individual "hard" shadows:
Now union the shadows together:
Finally, trace around the shadows, keeping to the edges of the box. The corners you want to identify are the ones in yellow. As you are tracing around the perimeter of the shadows, you want to cut across the edge of the box until you reach the opposite corner. Not the easiest thing to code but if you've gotten this far I think you can figure it out :)
Alternatively, it might be easier to simply consider the lit areas. For example, you could do something like take the difference of the scene box and the unioned shadowed area This will usually give you multiple polygons; discard everything except the one that contains the light because the rest are the false gaps.
Blender noob trying to render an object but certain parts of it keep coming out black. I'm not sure why. My image is here which might help:
A few extra details:
The shelves I've been trying to render are just a collection of planes which I've aligned to form shelves
All of them have no material or texture on them
Despite this, the very furthest plane (back of the shelves) and the front one which says laundry render properly in white, but the others render in black
I've tried adding material/texture to all of them, but they still come out black
My light source is set to "Sun" and sits a little bit behind the camera and shines directly onto the shelves
Is this a lighting issue?? If so any suggestions for how to fix?
Your "normals" are flipped. In other words, each surface has a "front" and "back" side. The backs of yours are facing in (which makes sense, when you consider the method you created the volume...you're looking at the inside surfaces).
To fix your issue, select the dark faces and do Mesh->Normals->Flip
It looks like they are not getting any light on their faces because of the angle compared to the light source. Try adding a point light source to your scene just in front of your shelf objects to see if that changes the outcome.
Flipping the 'normals' worked for me, only after switching to render cycles from blender render. Hope that helps someone else.
I understand how a simple GLSL fog shader works, but how can it be applied? Applying it directly to a terrain mesh does not produce the desired "fog" result. How would one mimic the built-in fog effects of OpenGL with a shader? The only thing that I can think of is applying the shader to a series of encased spheres around the camera, but that seems like a lot of work for just some fog.
Update:
Some images to further explain.
This is the shader I have applied to my terrain mesh, and the result is not what I want:
http://puu.sh/31dft.jpg
This is the kind of effect I am looking to replicate:
http://mw2.google.com/mw-panoramio/photos/medium/4503932.jpg
Semi-realistic atmosphere rendering is an complex problem to which many (ongoing-) research is dedicated. In your reference photo there are essentially three major factors that can contribute to the particular composition: i. fog/haze ii. atmospheric scattering iii. altitude.
Simply put applying fog solely on objects such as terrain, is an inherently flawed concept, because fog occludes/obscures the transmittance of light. This includes the light from the sky. So in order to cover the scenario of fog being applied to the 'sky' another approach is required, involving post-processing. Essentially the position of every pixel needs to be reconstructed in 3d-space, and the fog algorithm needs to run over each of these.
Depending on particular the art-style this might be sufficient for your needs, however it's more complicated. This document, http://developer.amd.com/wordpress/media/2012/10/D3DTutorial_Crytek.pdf gives a nice starting point regarding atmospheric rendering (it includes volumetric fog).
You have to set the fog color and the background color to be the same. Otherwise the effects look bizarre. The point of fog is to make distant objects "fade into the background". The problem with your image is that your background is bright blue, as if you wanted it to be a sunny, clear day. But the objects in your scene are fading to white, as if there was a very very thick fog. I suggest you find some compromise--use a grayish blue for both.
is it possible to create a GLSL shader to get any object to be surrounded by a glowing effect?
Let's say i have a 3d cube and if it's selected the cube should be surrounded by a blue glowing effect. Any hints?
Well there are several ways of doing this. If each object is also represented in a winged edge format then it is trivial to calculate the silhouette and then extrude it to generate a glow. This however is, very much, a CPU method.
For a GPU method you could try rendering to an offscreen buffer with the stencil set to increment. If you then perform a blur on the image (though only writing to pixels where the stencil is non zero) you will get a blur around the edge of the image which can then be drawn into the main scene with alpha blending. This is more a blur than a glow but it would be relatively easy to re-jig the brightness so that it renders a glow.
There are plenty of other methods too ... here are a couple of links for you to look through:
http://http.developer.nvidia.com/GPUGems/gpugems_ch21.html
http://www.codeproject.com/KB/directx/stencilbufferglowspart1.aspx?display=Mobile
Have a hunt round on google because there is lots of information :)