Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (223)
games submitted by our members
Games in WIP (813)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shadow mapping offset  (Read 2030 times)
0 Members and 1 Guest are viewing this topic.
Offline daslee

Senior Newbie


Medals: 1
Exp: 4 years



« Posted 2014-10-18 11:22:52 »

Hello. I've noticed that shadows in my game have offsets when I looked closer to the edges. This is how they look like: http://i.imgur.com/LeG60xx.jpg http://i.imgur.com/TPTSnLx.jpg Any suggestions how to solve this problem? Here is the shader code if someone needs (removed all unnecessary codes that is not related to shadow mapping):

Vertex
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
#version 420

layout(location = 0) in vec3 VertexPosition;
layout(location = 1) in vec3 VertexNormal;

out vec3 Position;
out vec3 Normal;
out vec4 ShadowCoord;

uniform mat4 MVP;
uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ShadowMatrix;

void main()
{
   vec3 pos = vec3(ModelViewMatrix * vec4(VertexPosition, 1.0));
   vec3 norm = normalize(NormalMatrix * VertexNormal);

   Position = pos;
   Normal = norm;
   
   //Shadow mapping
   ShadowCoord = ShadowMatrix * vec4(VertexPosition, 1.0);
   
   gl_Position = MVP * vec4(VertexPosition, 1.0);
}


Fragment:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
#version 420

layout(binding = 0) uniform sampler2D Texture;
layout(binding = 1) uniform sampler2DShadow ShadowTexture;

in vec3 Position;
in vec3 Normal;
in vec4 ShadowCoord;

subroutine void RenderPassType();
subroutine uniform RenderPassType RenderPass;

uniform float xPixelOffset;
uniform float yPixelOffset;

layout(location = 0) out vec4 FragColor;

float lookup(vec2 offset)
{
   return textureProj(ShadowTexture, ShadowCoord +
                                 vec4(offset.x * xPixelOffset * ShadowCoord.w,
                                     offset.y * yPixelOffset * ShadowCoord.w,
                                     0.0, 0.0)
            );
}

//SUBROUTINES

subroutine(RenderPassType)
void shadowPass()
{
   vec4 textureColor = texture2D(Texture, TexCoords);

   vec3 ambient, diffuse, specular;
   phongModelDirectional(Position, Normal, ambient, diffuse, specular);
   LightColorDS = diffuse + specular;
   LightColorA = ambient;
   
   float shadow;
   if(ShadowCoord.w > 1.0){
      float x,y;
      for(y=-1.5; y<=1.5; y+=1.0)
         for(x=-1.5; x<=1.5; x+=1.0)
            shadow += lookup(vec2(x,y));
      shadow /= 16.0;
   }
   
   FragColor = textureColor * vec4(LightColorDS * shadow + LightColorA, 1.0);
}

subroutine(RenderPassType)
void depthPass()
{
}

void main()
{
   RenderPass();
}
Offline MrMapcom

Junior Devvie


Medals: 3
Exp: 3 years



« Reply #1 - Posted 2014-10-18 13:04:46 »

One solution can be, make your walls ticker...

Here in NeHe you have some other solutions and why that offset is happening.

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

BTW those screenshots looks really nice.
Offline daslee

Senior Newbie


Medals: 1
Exp: 4 years



« Reply #2 - Posted 2014-10-18 18:07:45 »

One solution can be, make your walls ticker...

Here in NeHe you have some other solutions and why that offset is happening.

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

BTW those screenshots looks really nice.

Yeah, I was reading this article long time ago and I forgot about this, but now I remembered this and I think that it will help me (can't test it now). And screenshots I think would look even nicer if I was enabled normal mapping.  Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nouht

Senior Newbie





« Reply #3 - Posted 2014-10-27 22:17:49 »

Hi there, is this game written in LWJGL? If so, could you give me a little help on shadow mapping? I'm finding it difficult to learn.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
cybrmynd (120 views)
2017-08-02 12:28:51

cybrmynd (144 views)
2017-08-02 12:19:43

cybrmynd (138 views)
2017-08-02 12:18:09

Sralse (154 views)
2017-07-25 17:13:48

Archive (624 views)
2017-04-27 17:45:51

buddyBro (733 views)
2017-04-05 03:38:00

CopyableCougar4 (1260 views)
2017-03-24 15:39:42

theagentd (1239 views)
2017-03-24 15:32:08

Rule (1216 views)
2017-03-19 12:43:22

Rule (1268 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!