To start off, we need an image that has some gap or spaces where lights normally pass through, such as a window, clouds, or hallway. In my image to the left, I will create a ray that will pass through the hole in the cliffs.

First off, we need to duplicate the original layer, of the ways to do this is right click the layer in the layers pallete and select "Duplicate Layer"


Now go to Filter->Blur->Radial Blur
Set amount to: 100, Method: Zoom, and Quality: Best

Then move your cursor over to the "Blur Center", then click and drag its center point to the upper left corner.

Note: Where you drag this will depend on your image and depend on where you want the source of light to come from.

Now set the layer's blending mode to "Lighten" or "Screen" and change the opacity to around "60%"

Then use the eraser tool with the soft brush (size 150px soft brush) and erase out part of the layer where obviously light is not passing through.

That's it!