• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [3D] Ortho-projected real-time shadows

Q

Quackertree

Guest
GM Version: GM:S 1.4 (and up, probably)
Target Platform: Windows (although other platforms CAN be supported - Read more down below)
Download: https://github.com/Quackertree/depthShadow
Links: N/A

Summary:
A shader made by Xor for 3D which creates ortho-projected real-time shadows in your 3D games - Explained, documented and open-sourced for you to use in your projects.

This is an intermediate tutorial, although I try to explain most of the process.

The full code can be viewed on GitHub. I'll place a couple of snippets here for reference.

Tutorial:

Hi there!

I wanted to make this tutorial for a bit now, but I kept forgetting I was going to, so this comes out a little late (especially with the new release of GM:S 2). Either way; Some of you may already have seen my game. I've been using 3D shadow in there, but there was a problem with the original method of shadow projection, where the shadows fall off the farther you move away. This caused the game to look ugly, etc.

In order to solve these issues, Xor helped me out and wrote an awesome shadow shader which projects them orthogonally onto the models. This means, that the shadows will always stay consistent in width, and the position of the camera now no longer has an effect on the shadows. I eventually re-wrote the shader slightly in order to add some extra post-processing effects to it.

The result looked somewhat like this (note: There are more shaders active than just the shadow shader):



I've got a couple of questions now on whether I wanted to do a tutorial on how I got to these shaders. So, let's get going!

How it works:

Here's a poorly drawn image of a side-view representation of a 3D space. I'll use this to explain how the shader (basically) works:



In the real world, we have a sun. The sun will cast rays of light and the rays of light which hit an object, will reflect. This leaves the parts behind the object with the ray hit to be dark, as they receive no light.

When we create a shader, we want to re-create this effect from real-life. We do this as follows:
  1. We construct a so-called "depth map"
  2. We check if the depth map value, is smaller than the distance between the pixel and the camera. If this is true, that pixel will be shaded.
When we mention "depth map", we're talking about a texture which contains data about how far the pixels are from the camera. Compared to the image above, we would save the distance of the two rays into a texture. Because only the pixels closest to the camera will be drawn, only these distances will be saved.

When we compare the depth map to the pixels as we draw them, we can calculate the distance between the current pixel and the sun aswell. Now, we can test these against each other to see which one is smaller.

In the image above: The most upper ray consists of two parts; Black and red. The black part is the shortest distance until the ray hits something -> This would be saved in the depth map. The black + red part is the distance of the ray we're casting from the sun to the current pixel. This means, that the red part is the difference between the two distances.

Because there is a red part (because the distance from the current pixel to the sun is greater than the value in the depth map), the current pixel has to be shaded (since it is obstructed by other stuff in front of it).

It's a little hard of a concept to get around the first time - But once you get more into it, you'll start to understand what's going on.

Perspective vs. orthogonal

Whenever you create a regular d3d_projection in GM:S, you'll always get a perspective projection. This causes issues with the shadows, as the shadows widen the further away they get from the source. This is by definition what perspective does - Things will fall off the further away they get from the source.

This works fine for small points lights, however, when we're discussing such things as the sun, this doesn't apply. Because the sun is at such a large distance away from earth, we can state that the rays of light coming from the sun are almost parellel to each other, as demonstrated below:



We call this, a "directional light".

In order to achieve this effect, we need to look through our world with an orthogonal projection. This is the exact opposite of perspective - Things don't widen the further away they get from the source. Instead, they remain the same size. This allows you to, in theory, look infinitely far away.

What we want to achieve

We want to achieve the following steps in our shader:
  1. Create an orthogonal projection and render an orthogonal depth map
  2. Use a second shadow shader to read out the shadows from the shadow map and render the final result on screen
I'm going to add another step to the list here. We'll be writing the shadows to a surface, then we'll blur it and finally, we'll map that surface to wherever everything is drawn. I'll explain this later.

The shader

The first step, is to create the depth map. For this, we'll need an orthogonal projection. The following snippet of code is what we'll use here:

Code:
d3d_set_projection_ortho( argument0, argument1, argument2, argument3, 0 );
var finalMatrix = matrix_get( matrix_projection);
finalMatrix[10] = -2/(argument5-argument4);
finalMatrix[14] = -((argument5+argument4)/(argument5-argument4));

return finalMatrix;
The above bit of code will setup an orthogonal projection, then read it's matrix, adjust it a bit and finally, return it. This code is under "xl_project_ortho.gml".

What we'll do, is take this matrix, pass it into the depth shader and use it to override the current projection matrix, effectively "tricking" the shader into thinking it works in a orthogonal projection and render everything that way.

I won't go over a lot of the setup stuff, you can read all of that under "xl_create.gml", which is a bundled script, with all scripts required inside it.

---

Now we have the matrix, we can start using the shader. First, we render by using the sh_depth_ortho. This is the important bit:

Code:
float3 ftov(float f)
{
    return float3(floor(f/255.0)/255.0,frac(f/255.0),frac(f));
}
void main(in v2p IN, out p2s OUT)
{
    float4 col = tex2D(gm_BaseTexture, IN.Texcoord);
    OUT.Diffuse = col;
    OUT.Depthmap = float4(ftov(IN.Depth*65025.0),col.a);
    OUT.Normal =  float4(normalize(IN.Normal)*0.5+0.5,1.0);
}
Note, that there are 3 different outputs. We call these MRTs (Multiple Render Targets) and they are something amazing included in Windows-only. It allows this shader to generate both the Diffuse, Depthmap and Normal in one render - This means you won't have to render loads of times which speeds up the render process a lot!

Note, that the shader doesn't use all 3 of these outputs. It just uses one of them. The shader still contains them, however, in case you may want to use these in the future.

What the code above does, in short, is convert the distance between the camera (temporarily located at the sun) and the current vertex, into a colour. Then, it saves this colour onto a surface.

Finally, the sh_shadow_ortho shader will render both the diffuse, aswell as the shadows (based on the depth map) onto two surfaces (once again, by using MRTs).

---

When you move your light source far away from the world, you'll get artifacts. This happens, because the depth map isn't precise enough. Shamefully, we cannot use the alpha component in the surfaces to extend the reach of the depth map (we've tried; GM didn't like it... :/). Therefore, we have to do clever trickery to get around this.

I resolved my issues by doing a post-process radial blur on the shadow surface. The code for this blur is as follows:

Code:
void main()
{
   float result = 0.0;
   vec2 hlim = vec2(float(-uBlurSize) * 0.5 + 0.5);
   for(int i=0;i<uBlurSize;++i)
   {
      for(int j=0;j<uBlurSize;++j)
      {
         vec2 offset = (hlim + vec2(float(i), float(j))) * texSize;
         result += texture2D(shadowTex, v_vTexcoord + offset).r;
      }
   }
  
   vec4 texel = texture2D(gm_BaseTexture, v_vTexcoord);
   gl_FragColor = vec4(texel.rgb * (result / float(uBlurSize * uBlurSize)), texel.a);
}
My blur size was set to 3 - This seems to be a good balance between quality and speed.

How to use the shader

Now you (sort of) know how it works, here's how you use the scripts from Git:

Make sure to add the files to your project and mark all shaders as HLSL 9, EXCEPT for sh_shadow_pp.
Code:
#Create
xl_create(); //Sets up the files -> Run this once in some Create event (anywhere, really)

#Draw
xl_depth(<Fill in appropriate parameters here>);
//Draw all your shizz
xl_depth_end();

if(!surface_exists(diffuseSurf)){/*Create...*/}
if(!surface_exists(shadowSurf)){/*Create...*/}

surface_set_target_ext(0, diffuseSurf); //Sets up for MRTs
surface_set_target_ext(1, shadowSurf); //Sets up for MRTs

xl_shadow();
//Draw all your shizz (again)
xl_shadow_end();

#Draw GUI Begin
shader_set(sh_shadow_pp);
texture_set_stage(shader_get_sampler_index(sh_shadow_pp, "shadowTex"), surface_get_texture(shadowSurf));
draw_surface(0, 0, diffuseSurf); //Cannot be application_surface
shader_reset();
Above is a snippet of pseudo-ish code (with some copy-paste bits), which gives the general idea of how to work with this shader. It is a quite advanced one to get working, but once you do, it's pretty awesome!

Cross-platform issues
There's an issue when trying to use this cross-platform, as there are MRTs involved. However, you can adjust the shader to become GLSL only.

Personally, I really like the MRTs, because I also use them to setup my bloom. The SSAO shader from MishMash and orange451 that I'm also using also uses MRTs and they nicely combine together by doing so. You're free to convert, however.

I cannot say anything about performance on other platforms, although I can predict that it won't run amazingly fast on Android.

This code in GM:S 2.0
GM:S 2 has many new features, including cameras, which make this process a lot "easier". You'd not have to setup the entire "hack", which grabs the orthogonal projection matrix and passes it to a shader. Instead, you can now actually create an orthogonal projection by using cameras.

Most of the code still holds. I personally don't use GM:S 2.0, so I'm not going to convert the shaders anytime soon to work in that engine. Feel free to use try this out yourself if you so desire - It'll teach you a lot about shaders! ;)

Conclusion
This was quite the tutorial. If you still feel confused, don't use the shader, but read more about how it works. I've linked some other tutorials down below, which explain the process nicely in more detail. Once you have a proper understanding of how everything works, you'll be able to implement it into your games.

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/ (Great source, if you ignore the code snippets used here!)
http://ogldev.atspace.co.uk/www/tutorial23/tutorial23.html (Another great source for shadow mapping, if you ignore the code snippets!)

Hopefully you've found this tutorial useful! Let me know if you've got any questions down below, I'll try to answer them as best as I can. :)
 
Last edited by a moderator:

Lewa

Member
Nice! Was also experimenting with different shadowing techniques (shadow volumes and orthographic shadow mapping) but had issues with the orthographic matrix creation on the shadow mapping side. (Somehow my orthographic matrix creation code from one of my openGL engine attempts didn't work in GM...)
Will definitely give it a look. (Also kudos for releasing this as open source.) :)

One question though: I suppose this isn't using shadow cascades? (I didn't find anything in the code that would point to that.)
 
Q

Quackertree

Guest
@Lewa: Thanks!

No, it's not using shadow cascades. I never really considered such a function (perhaps Xor wants to add it in?); We've only attempted to use the alpha component to extend the precision of the depth map from 2^16 to 2^32 (which would be a significant enough increase in precision). GM:S seemed to contain a bug (according to Xor), which makes the use of the alpha component in a depth map impossible, however.

To solve my issue, I simply added the radial blur (which is also commonly used for SSAO), allowing the shadows to extend out a lot further with little to no artifacts. It's a little slower, but at least it's an adjustable setting, so people can tweak it however they like best.

I do believe I once made a discussion about shadow cascades on the old forums, and Mike told me it would be impossible in the current setup of GM:S. Not exactly sure if it was about shadow cascades, however.. Had to do with shadows, that's for sure. Either way, that post is from a long time ago and perhaps things have changed now. :)
 
D

DennisGMC

Guest
I have set the sh_depth_ortho and sh_shadow_ortho shaders to HLSL 9. And the sh_shadow_pp is set to GLSL ES.
I've set the create draw and draw gui event like in the example. The shadowmap is set to 512 and xl_depth is set like this:
Code:
xl_depth(0, 0, -128, -128, 128, -128, 0);
However is get this error and don't really understand what the problem is.
I have cleared the compile space.
Code:
___________________________________________
############################################################################################
FATAL ERROR in Vertex Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_60868\gm_ttt_44074\memory(48,29): error X3004: undeclared identifier 'pos'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 1)
called from - gml_Object_obj_draw_l1_Draw_0 (line 28)
 
Q

Quackertree

Guest
I almost forgot you co-operated in that project! :eek:
Adjusted the main post to also credit you! :)

I have set the sh_depth_ortho and sh_shadow_ortho shaders to HLSL 9. And the sh_shadow_pp is set to GLSL ES.
I've set the create draw and draw gui event like in the example. The shadowmap is set to 512 and xl_depth is set like this:
Code:
xl_depth(0, 0, -128, -128, 128, -128, 0);
However is get this error and don't really understand what the problem is.
I have cleared the compile space.
Code:
___________________________________________
############################################################################################
FATAL ERROR in Vertex Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_60868\gm_ttt_44074\memory(48,29): error X3004: undeclared identifier 'pos'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 1)
called from - gml_Object_obj_draw_l1_Draw_0 (line 28)
Whoops!

I erased some stuff from the shader, because I had a lot of diffuse components, etc. in there for my current game. This variable might have slipped through.
I'll correct the issue and update the Git version today.

I'll edit this post once I've done so.

EDIT: Issue should be resolved now. You can download the newest version from Git.
 
M

MrROBOT

Guest
Does this use GM's built in lighting system?
How can I do this with point lights?
 
O

orange451

Guest
Does this use GM's built in lighting system?
How can I do this with point lights?
For point lights, you would have to have 6 projection matrices, each 90 degrees in FOV and pointing a different direction on the world-space axis (+x -x +y -y +z -z). You would have to write the depth information to a "fake" cubemap texture since Game Maker doesn't support cubemaps, and then you would also have to have a function to convert your reconstructed world space position (shown in the example in the OP) into a specific region of the faked cubemap, as a consequence of not having real cubemapping. Then presto, you have point lights with shadows. You also draw your point light with an inverted sphere so that the inside face obstructs the camera. This is used as a base to reconstruct the world-space position, as you are no longer working in an orthagonal perspective like what's used in directional shadowmapping.

You can read more on it here:
https://learnopengl.com/#!Advanced-Lighting/Shadows/Point-Shadows
http://ogldev.atspace.co.uk/www/tutorial43/tutorial43.html
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

On the older Game Maker forums, someone released a great shadowed point-light example. Perhaps someone can link it here.
 
D

DennisGMC

Guest
Now i have a different error i tried lots of things and updated to the latest version of your code but i get this eror:


Code:
___________________________________________
############################################################################################
FATAL ERROR in Vertex Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,66): error X3004: undeclared identifier 'normalMat_new'
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013: 'mul': intrinsic function does not take 2 parameters
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013: Possible intrinsic functions are:
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(float, float)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(float, floatK)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(float, floatLxK)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(floatM, float)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(floatM, floatM)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(floatM, floatMxK)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(floatNxM, float)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(floatNxM, floatM)
C:\Users\User\AppData\Local\gm_ttt_44932\gm_ttt_39690\memory(50,35): error X3013:     mul(floatNxM, floatMxK)

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 2)
called from - gml_Object_obj_3d_core_Draw_0 (line 295)
I have set the shaders to HLSL 9, EXCEPT for sh_shadow_pp.
So i don't really understand what the problem is. Also i have the same SSAO extension.
Can i just use the depth_buffer of the ssao object without any problems?
 
Q

Quackertree

Guest
Now i have a different error i tried lots of things and updated to the latest version of your code but i get this eror:


Code:
<snip>
I have set the shaders to HLSL 9, EXCEPT for sh_shadow_pp.
So i don't really understand what the problem is. Also i have the same SSAO extension.
Can i just use the depth_buffer of the ssao object without any problems?
Whoops, I also left the normals in for no good reason. :/

Will update the git asap. If you still get errors, let me know. I've triple checked now and I think it should all be fine, but if it isn't, I'll set up an example *.gmz to test it in.

P.S.: No, you cannot use the depth buffer from SSAO; They have a couple of small encoding differences which make them incompatible.

EDIT: Pushed the update to git.
 

Xor

@XorDev
No, it's not using shadow cascades. I never really considered such a function (perhaps Xor wants to add it in?); We've only attempted to use the alpha component to extend the precision of the depth map from 2^16 to 2^32 (which would be a significant enough increase in precision). GM:S seemed to contain a bug (according to Xor), which makes the use of the alpha component in a depth map impossible, however.
Maybe one day I'll make cascaded shadows, but I don't have the time at the moment.
@MishMash made cascaded shadows shader once. There's even a video explaining it.

Anyway, thanks for explaining this! I didn't get to making a tutorial myself, though it's been requested a few times.
 
D

DennisGMC

Guest
Whoops, I also left the normals in for no good reason. :/

Will update the git asap. If you still get errors, let me know. I've triple checked now and I think it should all be fine, but if it isn't, I'll set up an example *.gmz to test it in.

P.S.: No, you cannot use the depth buffer from SSAO; They have a couple of small encoding differences which make them incompatible.

EDIT: Pushed the update to git.
Well i still can't let it function properly.
Code:
___________________________________________
############################################################################################
FATAL ERROR in Fragment Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_55724\gm_ttt_91854\memory(55,36): error X3004: undeclared identifier 'n'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 2)
called from - gml_Object_obj_3d_core_Draw_0 (line 290)
 
Q

Quackertree

Guest
Maybe one day I'll make cascaded shadows, but I don't have the time at the moment.
@MishMash made cascaded shadows shader once. There's even a video explaining it.

Anyway, thanks for explaining this! I didn't get to making a tutorial myself, though it's been requested a few times.
Thanks! I forgot to tell you that I made the tutorial.. :/ At least you found it yourself, so that's great! :)

Cool! I looked up the topic about shadows just now, but it was about stenciled shadow buffers, and not about cascaded shadows. So I've mistaken that topic for one about shadow cascades @Lewa.

Well i still can't let it function properly.
Code:
___________________________________________
############################################################################################
FATAL ERROR in Fragment Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_55724\gm_ttt_91854\memory(55,36): error X3004: undeclared identifier 'n'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 2)
called from - gml_Object_obj_3d_core_Draw_0 (line 290)
I'm pretty sure I fixed that issue earlier on... I'll have another look at it. :/

EDIT: Whoops, I forgot to push the update. I only made a commit. :p

I've pushed it now.
 
D

DennisGMC

Guest
I'm pretty sure I fixed that issue earlier on... I'll have another look at it. :/

EDIT: Whoops, I forgot to push the update. I only made a commit. :p

I've pushed it now.
Now i have one error, and some warnings:

Code:
___________________________________________
############################################################################################
FATAL ERROR in Fragment Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(27,11): warning X3207: Initializer used on a global 'const' variable. This requires setting an external constant. If a literal is desired, use 'static const' instead.
C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(28,14): warning X3207: Initializer used on a global 'const' variable. This requires setting an external constant. If a literal is desired, use 'static const' instead.
C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(60,28): warning X3205: 'cos': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(60,40): warning X3205: 'sin': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(62,21): warning X3205: 'cos': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(62,37): warning X3205: 'sin': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_11812\gm_ttt_73217\memory(76,47): error X3004: undeclared identifier 'tex'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 2)
called from - gml_Object_obj_3d_core_Draw_0 (line 290)
 
Q

Quackertree

Guest
Now i have one error, and some warnings:

Code:
<snip>
Just add 'static' after 'const' in the shader_ortho. I always forget that this is a HLSL thing, so I just wrote 'const' and really didn't check, because I assumed it was correct.

I'll push to git later today, but there's no need in pulling if you can just add the two words yourself. :)

Are the spoilers a game that YOU made? If so, HOW THE HECK DID YOU DO THAT!!! :eek:
Magic. *snort* *snort*

Thanks! I've been working a lot with shaders lately and it took me quite a bit of experience from the past to get it to look like it does now. Full list of used shaders would be:
- Diffuse (this seems standard)
- Some darkness interpolation thing based on the z-value of each vertex
- Orthogonal shadows
- Bloom
- SSAO (although not displayed in the screenshot)
- And lots and lots of colour tweaking until it looked 'good enough' :)

I also load in Blender models from the *.obj format and convert them to vertex buffers using Lewa's script for Blender import.
 
D

DennisGMC

Guest
Just add 'static' after 'const' in the shader_ortho. I always forget that this is a HLSL thing, so I just wrote 'const' and really didn't check, because I assumed it was correct.

I'll push to git later today, but there's no need in pulling if you can just add the two words yourself. :)
Alright i added static after const in the shadow_ortho script. It fixed the first two errors, but i still have 4 related to cos and sin.
And most importantly an error "undeclared identifier 'tex'". Here is the error log:

Code:
___________________________________________
############################################################################################
FATAL ERROR in Fragment Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(60,28): warning X3205: 'cos': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(60,40): warning X3205: 'sin': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(62,21): warning X3205: 'cos': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(62,37): warning X3205: 'sin': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(76,47): error X3004: undeclared identifier 'tex'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 2)
called from - gml_Object_obj_3d_core_Draw_0 (line 292)
Thanks for all the help so far :) !
 
Q

Quackertree

Guest
Alright i added static after const in the shadow_ortho script. It fixed the first two errors, but i still have 4 related to cos and sin.
And most importantly an error "undeclared identifier 'tex'". Here is the error log:

Code:
___________________________________________
############################################################################################
FATAL ERROR in Fragment Shader compilation
ShaderName: sh_shadow_ortho

C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(60,28): warning X3205: 'cos': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(60,40): warning X3205: 'sin': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(62,21): warning X3205: 'cos': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(62,37): warning X3205: 'sin': conversion from larger type to smaller, possible loss of data
C:\Users\User\AppData\Local\gm_ttt_40403\gm_ttt_28953\memory(76,47): error X3004: undeclared identifier 'tex'

############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Script_xl_shadow (line 2)
called from - gml_Object_obj_3d_core_Draw_0 (line 292)
Thanks for all the help so far :) !
I'll build an example project to test properly, in that case. I've never experienced this kind of issue before, but it's probably something simple (again). I'll see if I can build one tonight and upload it. I'll let you know if it's done. From then on, you shouldn't have any issues with the shader anymore. :)
 
D

DennisGMC

Guest
I'll build an example project to test properly, in that case. I've never experienced this kind of issue before, but it's probably something simple (again). I'll see if I can build one tonight and upload it. I'll let you know if it's done. From then on, you shouldn't have any issues with the shader anymore. :)
Thanks for all the help! i will be waiting for a example.
 
Q

Quackertree

Guest
Thanks for all the help! i will be waiting for a example.
Great news! I just finished it up and pushed it to Git.

Should be the last download you'll have to do; I've ran the tests multiple times now and it works like a charm now. :)
 
D

DennisGMC

Guest
Great news! I just finished it up and pushed it to Git.

Should be the last download you'll have to do; I've ran the tests multiple times now and it works like a charm now. :)
Thanks it works fine now. But how did you merge the ssao object with these shadows?
I'm having trouble using the 2 at the same time.
 
Q

Quackertree

Guest
Thanks it works fine now. But how did you merge the ssao object with these shadows?
I'm having trouble using the 2 at the same time.
Great to hear that it's working! :)

I believe I rendered the SSAO to another seperate surface and stacked the two on top with another postprocessing shader. Not entirely sure, but I believe that's how I went about it. :)
 
J

Jason Blanchard

Guest
This looks fantastic, but does it work with models? The shadow of the model gets drawn at the correct location, but the actual model is always drawn at (0, 0, 0) no matter what coordinates I put in d3d_model_draw. Is there any way to get the model to draw at the correct location?

Edit: Dang, nevermind. I think I got it. Messing around with stuff it looks like changing
Code:
OUT.Position = mul(viewMat, IN.Position);
to
Code:
OUT.Position = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], IN.Position);
in the sh_shadow_ortho shader fixed it. I have no idea what I'm doing so I hope that doesn't create any other problems.
 
Last edited by a moderator:
Top