Anixias
Member
Hi all. I'm trying to get real-time dynamic lighting in my prototype right now. The game is 3D in a perspective projection. It will have a view similar to that of an RTS or base-building game, so top-down ish at around 30 degrees down from straight forward (probably going to tweak that later).
Anyway, to get to the point, I found an old GM:S 1.4 project that has dynamic lighting using point lights. It can have an infinite number of them. I studied and studied it, and I understand how it all works. I've also been studying and watching videos relating to Shadow Mapping, so I understand the principle.
Here's where I'm at now. I have a directional light that renders the scene in an orthographic projection (where it renders from is currently fixed for testing, but later it will dynamically move so the whole view of the camera is captured by the light's projection). It renders the scene to a surface, ignoring any objects I flag as not being a shadowcaster. It uses a shader to store depth/distance to each fragment in the color values of the pixels, rather than texture information.
Now I'm stuck. I have a Depth Buffer/Z-Buffer/Shadow Map, whatever you want to call it. It stores the depth/distance to each fragment in the world via an orthographic view (because it's a directional light, so all light rays are parallel). I'm trying to work out how to adapt the old GM:S project's shader to fit a directional light, but I'm not exactly sure how.
I know, in principle, how it works. For each fragment, I multiply it's position by a few different matrices that describe the view from the light's perspective, and use that new position to sample the shadow map the light creates. From this, I compare the fragment's distance from the light to the distance recorded in the shadow map. If it's further away than the distance recorded in the shadow map, this fragment is in shadow.
But, I just don't know how to actually do all of that. I'm still fairly new to using GLSL ES. I think I'm supposed to do the projections in the fragment shader, because doing them in the vertex shader will actually project the pixel, so the game would literally be rendered from the light's perspective. But I'm still unsure of how to do this. Could anyone walk me through creating a shader for this purpose?
Extra information:
I have all of the uniforms in the shader working, including passing the sampler2D shadow map from the light. This game will never need more than one light, so only supporting directional lights (or just a single directional light) is perfectly acceptable.
I have a global ambient color variable as well that is simply a floating point value (0.0 - 1.0), 0.0 meaning that shadows should be solid black, and 1.0 meaning shadows should be invisible (white, when multiplying colors together this means it's basically invisible).
TL;DR Working on 3D lighting with only a single directional light (will never need any other lights of any kind). I need someone to help me create the second-pass shader for actually transforming pixel positions into a directional light's projection and view so I can sample the shadow map and render the amount of shadow it's in from ambient_color to white.
Anyway, to get to the point, I found an old GM:S 1.4 project that has dynamic lighting using point lights. It can have an infinite number of them. I studied and studied it, and I understand how it all works. I've also been studying and watching videos relating to Shadow Mapping, so I understand the principle.
Here's where I'm at now. I have a directional light that renders the scene in an orthographic projection (where it renders from is currently fixed for testing, but later it will dynamically move so the whole view of the camera is captured by the light's projection). It renders the scene to a surface, ignoring any objects I flag as not being a shadowcaster. It uses a shader to store depth/distance to each fragment in the color values of the pixels, rather than texture information.
Now I'm stuck. I have a Depth Buffer/Z-Buffer/Shadow Map, whatever you want to call it. It stores the depth/distance to each fragment in the world via an orthographic view (because it's a directional light, so all light rays are parallel). I'm trying to work out how to adapt the old GM:S project's shader to fit a directional light, but I'm not exactly sure how.
I know, in principle, how it works. For each fragment, I multiply it's position by a few different matrices that describe the view from the light's perspective, and use that new position to sample the shadow map the light creates. From this, I compare the fragment's distance from the light to the distance recorded in the shadow map. If it's further away than the distance recorded in the shadow map, this fragment is in shadow.
But, I just don't know how to actually do all of that. I'm still fairly new to using GLSL ES. I think I'm supposed to do the projections in the fragment shader, because doing them in the vertex shader will actually project the pixel, so the game would literally be rendered from the light's perspective. But I'm still unsure of how to do this. Could anyone walk me through creating a shader for this purpose?
Extra information:
I have all of the uniforms in the shader working, including passing the sampler2D shadow map from the light. This game will never need more than one light, so only supporting directional lights (or just a single directional light) is perfectly acceptable.
I have a global ambient color variable as well that is simply a floating point value (0.0 - 1.0), 0.0 meaning that shadows should be solid black, and 1.0 meaning shadows should be invisible (white, when multiplying colors together this means it's basically invisible).
TL;DR Working on 3D lighting with only a single directional light (will never need any other lights of any kind). I need someone to help me create the second-pass shader for actually transforming pixel positions into a directional light's projection and view so I can sample the shadow map and render the amount of shadow it's in from ambient_color to white.