Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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  
  Deferred rendering shadow mapping shader  (Read 337 times)
0 Members and 1 Guest are viewing this topic.
Online Kefwar

Senior Member


Medals: 5
Projects: 1



« Posted 2014-03-04 21:18:38 »

Hello,

I've followed some tutorials on deferred rendering and searched a lot, but I don't get what's going wrong here. In the tutorials it works this way, and when I try it, it doesn't.

I'm getting the following error:
1  
2  
3  
4  
5  
6  
7  
Unable to create fragment shader:
Fragment shader failed to compile with the following errors:
WARNING: 0:20: warning(#402) Implicit truncation of vector from size 4 to size 1.
ERROR: 0:21: error(#247) Function return is not matching type
WARNING: 0:39: warning(#402) Implicit truncation of vector from size 4 to size 3.
WARNING: 0:42: warning(#402) Implicit truncation of vector from size 4 to size 3.
ERROR: error(#273) 1 compilation errors.  No code generated


The fragment shader I'm using with this test:
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  
uniform sampler2D tDiffuse; 
uniform sampler2D tPosition;
uniform sampler2D tNormals;
uniform sampler2D tShadowMap;
uniform vec3 cameraPosition;
uniform mat4 worldToLightViewMatrix;
uniform mat4 lightViewToProjectionMatrix;
uniform mat4 worldToCameraViewMatrix;

float readShadowMap(vec3 eyeDir)
{
   mat4 cameraViewToWorldMatrix = inverse(worldToCameraViewMatrix);
   mat4 cameraViewToProjectedLightSpace = lightViewToProjectionMatrix * worldToLightViewMatrix * cameraViewToWorldMatrix;
   vec4 projectedEyeDir = cameraViewToProjectedLightSpace * vec4(eyeDir,1);
   projectedEyeDir = projectedEyeDir/projectedEyeDir.w;

   vec2 textureCoordinates = projectedEyeDir.xy * vec2(0.5,0.5) + vec2(0.5,0.5);

   const float bias = 0.0001;
   float depthValue = texture2D( tShadowMap, textureCoordinates ) - bias;
   return projectedEyeDir.z * 0.5 + 0.5 < depthValue;
}

void main( void )
{
   // Read the data from the textures
  vec4 image = texture2D( tDiffuse, gl_TexCoord[0].xy );
   vec4 position = texture2D( tPosition, gl_TexCoord[0].xy );
   vec4 normal = texture2D( tNormals, gl_TexCoord[0].xy );
   
   mat4 lightViewToWolrdMatrix = inverse(worldToLightViewMatrix);
   vec3 light = lightViewToWolrdMatrix[3].xyz;
   vec3 lightDir = light - position.xyz;
   
   normal = normalize(normal);
   lightDir = normalize(lightDir);
   
   vec3 eyeDir = position.xyz - cameraPosition;
   vec3 reflectedEyeVector = normalize(reflect(eyeDir, normal));
   
   float shadow = readShadowMap(eyeDir);
   float diffuseLight = max(dot(normal,lightDir),0) * shadow;
   float ambientLight = 0.1;

   gl_FragColor = (diffuseLight + ambientLight ) * image + pow(max(dot(lightDir,reflectedEyeVector),0.0), 100) * 1.5 * shadow;
}


The solution or a push in the right direction would be welcome.  Wink
Offline Gef
« Reply #1 - Posted 2014-03-04 21:45:02 »

1  
ERROR: 0:21: error(#247) Function return is not matching type

Have you tried to return a float instead of a boolean ?
1  
return projectedEyeDir.z * 0.5 + 0.5 < depthValue ? 1.0 : 0.0;

I haven't tested it but it seems to be something like that.
Other warnings are few cast problems that you should solve too.

Offline Drenius
« Reply #2 - Posted 2014-03-04 21:45:50 »

Must "normal" be a vec4? not a vec3? This would cause an error at 39 and 42 (as in the log)...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Kefwar

Senior Member


Medals: 5
Projects: 1



« Reply #3 - Posted 2014-03-04 21:51:40 »

1  
ERROR: 0:21: error(#247) Function return is not matching type

Have you tried to return a float instead of a boolean ?
1  
return projectedEyeDir.z * 0.5 + 0.5 < depthValue ? 1.0 : 0.0;

Must "normal" be a vec4? not a vec3? This would cause an error at 39 and 42 (as in the log)...
Thank you for your response, the errors are gone. Now I have to fix the most important thing: the shadows aren't appearing.  Wink
Offline Slyth2727
« Reply #4 - Posted 2014-03-04 22:57:04 »

Excuse me if I am assuming a bit too much, but it sounds like you don't have too much experience with shaders. I suggest that you take a step back and learn the basics a little better, maybe do some regular shadow mapping shaders or a few simple post processing effects to get a hang of the language.
Again I could be completely mistaken, if that's the case excuse me.

Other than that: Oh goody deferred rendering Cheesy

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Online Kefwar

Senior Member


Medals: 5
Projects: 1



« Reply #5 - Posted 2014-03-04 22:59:56 »

Excuse me if I am assuming a bit too much, but it sounds like you don't have too much experience with shaders.
You are right, I don't have much experience with shaders. I am working with OpenGL and shaders for about 3 weeks now. Cheesy
Offline Slyth2727
« Reply #6 - Posted 2014-03-04 23:18:37 »

Excuse me if I am assuming a bit too much, but it sounds like you don't have too much experience with shaders.
You are right, I don't have much experience with shaders. I am working with OpenGL and shaders for about 3 weeks now. Cheesy

In that case deferred rendering is most likely a bit over your head Smiley
Go ahead and check out davedes tutorials here: http://www.java-gaming.org/index.php?topic=28048.0
As well as shadertoy.com. Most of the shaders on there right now are pretty useless, however they are nice looking and give you an idea of just how powerful shaders can be. The site is nice for just testing out a quick shader if you want to. Just do some research you can find just about anything you want for shaders online. Good luck!

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (25 views)
2014-09-21 02:42:18

BurntPizza (16 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (26 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (44 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (100 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!