Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Labouts

Member Since 10 Dec 2011
Offline Last Active May 01 2014 07:44 PM

Topics I've Started

Problems with Normal Mapping

17 April 2014 - 07:31 AM

Hello,

 

I'm trying to implement lighting with normal maps in my 2D prototype. I'm stuck on a strange issue where the lighting fades out below my lights. It looks like the dot product between the light direction and the normal must be negative below the light, but I can't get a grasp on why that's happening.

 

Here is an image of the problem:

d2wjxL1.png

 

No matter where I place the light(s), the area below each light stays dark.

This is the code for my frag shader. I've simplified it to try and narrow the problem down:

#version 130

in vec2 texCoords;
in vec4 color;

uniform float numPointLights;
uniform sampler2D texture;
uniform sampler2D textureN;
uniform vec4 ambient;
uniform vec4 pointLightInfo[100];
uniform vec2 resolution;

void main()                                  
{
       vec4 diffuseColor = texture2D(texture, texCoords) * color;
	
	vec3 normalMap = texture2D(textureN, texCoords).rgb;
	normalMap.g = -normalMap.g; // Our normal map program produces an inverted y axis.
	
	normalMap = normalMap * 2 - 1; // Normalize to [-1, 1]
	
	vec2 screenPos = gl_FragCoord.xy;
	screenPos.x /= resolution.x;
	screenPos.y /= resolution.y;	
	screenPos = screenPos * 2 - 1; // Convert to NDC
	
	vec3 finalColor = (ambient.rgb * ambient.a) * diffuseColor.rgb;		
	for(int index = 0; index < numPointLights; index++) {		
                vec4 lightScreenPos = pointLightInfo[2*index]; // Pre-transformed to NDC
		vec3 lightVector = vec3(lightScreenPos.xy - screenPos.xy, lightScreenPos.z);	
		lightVector.x *= resolution.x / resolution.y;
		
		float lightDist = length(lightVector);
		
		vec3 normal = normalize(normalMap);
		vec3 lightDir = lightVector / lightDist;
		
		vec4 lightColor = pointLightInfo[2*index+1];
                float normalIntensity = max(dot(normal, lightDir), 0.0);
		vec3 diffuse = (lightColor.rgb * lightColor.a) * normalIntensity;
		
		vec3 falloff = vec3(0.009,0.09,0.5);
		
		float attenuation = 1.0 / ( falloff.x + (falloff.y*lightDist) + (falloff.z*lightDist*lightDist) );
		
	        vec3 intensity = diffuse * attenuation;
	        finalColor += diffuseColor.rgb * intensity;
    }

    gl_FragColor = vec4(finalColor, diffuseColor.a);
}

In case it's relevant, here is the level's normal map:

ODY3wtF.jpg


I'm at a bit of a loss for how to proceed. I'm hoping I made a silly error that will be quickly obvious to someone. Thanks in advance for any help.


XNA - Trapping the Mouse in Windowed Mode

02 February 2012 - 01:50 PM

I'm using XNA to make a game in which mouse movement controls the rotation of the camera. When running in windowed mode, I wanted to ensure that the cursor doesn't leave the screen if the game's not paused. I tried using Mouse.SetPosition, but the mouse still leaves the screen when moved quickly. This semi-frequently results in clicking off the screen, losing focus at undesirable times.
What can I do to prevent this?

Controversial Policy Choices in Games

02 February 2012 - 05:01 AM

In games where you are the leader of an independent state (a civilization, city state, ect), do you think controversial policy issues should be avoided when possible?

I'm asking because I was thinking about population control methods in the game I'm making and thought about the possibility of choosing to ban or promote birth control as a way the player could control growth. There are a number of other potential policy choices like this which would affect gameplay such as capital punishment policies and treatment of POWs; further, I'm already giving individual citizens enough personality to reasonably cause them to like or dislike your policies ( resistance to change, conscientiousness, ect ).

The game's main focus is managing the expansion of a small young civilization, but not necessarily politics. That said, do you think those choices should be included in the game or would including such issues from the real world distract too much from the core content?

Critique My Sprites

16 December 2011 - 12:34 AM

For my current project, I decided to attempt to make all of the art and audio assets myself despite having no experience in producing either. I just finished the first version of the sprite sheet for the player (a mage). I like them, but I'm biased; I'd like to get outside options on this sheet.

Each column is a state. In order, they are: Idle, Walking, Jumping, Hurt, Dieing, Target Cast, Area Cast, and Self Cast. The casting will be accompanied by visual effects.
Posted Image

PARTNERS