• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
harshman_chris

Environment Mapping Issues [Solved]

2 posts in this topic

I am working on environment mapping my objects from a skybox and I am getting an unexpected result, the final output is nothing, yet all the components that are used in created the final output are correct.

 

 

This is my reflective factor

[attachment=14292:ReflectiveFactor.png]

 

this is my base colour

[attachment=14290:baseColour.png]

 

Here is the environment mapped to the object

[attachment=14293:subemap.png]

 

This is the final output from a mix() function, but I also tried just using the standard lerp (I wrote myself), which is all mix is.

[attachment=14291:Final.png]

 

As you can see, all of the inputs are visible, but the output color is blank.

 

This is the combination line.

 

finalColor = vec4(mix(baseColour.rgb,cubeColor,reflectiveFactor),1.0);
 

 

I did the math by hand as well, and I do not get this result. Any help would be great.

 

 

Edit Attaching Shaders:

 

Vertex Shader

#version 330
 
layout(location = 0) in vec3 vertex;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 normal;
layout(location = 3) in vec3 tangent;
layout(location = 4) in vec3 bitangent;
 
out vec2 uv0;
out vec3 uv1;
out vec3 normal0;
out vec3 tangent0;
out vec3 bitangent0;

out vec3 worldPos0;
 
uniform mat4 mvp;
uniform mat4 world;

uniform vec3 cameraEyeWorldPosition;

void main()
{
	gl_Position =  mvp * vec4(vertex,1.0);
	uv0 = uv;
	normal0 = (world * vec4(normal,1.0)).xyz;
	tangent0 = (world * vec4(tangent,1.0)).xyz;
	worldPos0 = (world * vec4(vertex,1.0)).xyz;
	bitangent0 = (world * vec4(bitangent,1.0)).xyz;

	vec3 E = normalize(worldPos0 - cameraEyeWorldPosition);
	uv1 = reflect(E,normal0); 
}

Fragment Shader

#version 330
 
struct Attenuation
{
    float constant;
    float linear;
    float exponential;
};
 
struct BaseLight
{
	vec4 colour;
    float ambientIntensity;
    float diffuseIntensity;  
};
 
struct DirectionalLight 
{                                                                                   
    BaseLight base;
    vec3 direction;        
};
 
struct PointLight
{
	BaseLight base;  
    vec3 position;
	Attenuation attenuation;
};

struct SpotLight
{
	PointLight base;
	vec3 direction;
	float cutoff;
};

vec3 CalcBumpedNormal();
vec4 CalcLightInternal(BaseLight _light, vec3 _lightDirection, vec3 _normal);
vec4 CalcDirectionalLight(vec3 _normal);
vec4 CalcPointLight(PointLight _light, vec3 _normal);
vec4 CalcSpotLight(SpotLight _light, vec3 _normal);
 
const int MAX_POINT_LIGHTS = 10;
const int MAX_SPOT_LIGHTS = 5;

in vec2 uv0;
in vec3 uv1;
in vec3 normal0;
in vec3 tangent0;
in vec3 bitangent0;

in vec3 worldPos0;
 
out vec4 finalColor;
 
uniform DirectionalLight directionalLight;
uniform PointLight pointLights[MAX_POINT_LIGHTS];
uniform SpotLight spotLights[MAX_SPOT_LIGHTS];
 
uniform int numPointLights = 0;
uniform int numSpotLights = 0;
 
uniform vec3 cameraEyeWorldPosition = vec3(0.0,0.0,0.0);
 
uniform sampler2D diffuseTexture;
uniform sampler2D ambientTexture;
uniform sampler2D normalTexture;
uniform sampler2D specularTexture;
uniform sampler2D glossTexture;
uniform sampler2D reflectiveTexture;

uniform samplerCube cubeMapTexture;
 
void main()
{
	finalColor = vec4(1.0,1.0,1.0,1.0);

	vec4 MaterialDiffuseColor = texture2D(diffuseTexture, uv0);
 
	vec3 Normal = CalcBumpedNormal();

	vec4 TotalLight = vec4(0.0,0.0,0.0,1.0);
 
	TotalLight = CalcDirectionalLight(Normal);
 
	for (int i = 0; i < numPointLights; i++)
	{
		TotalLight = TotalLight + CalcPointLight(pointLights[i], Normal);
	}   

	for (int i = 0 ; i < numSpotLights ; i++)
	{
		TotalLight += CalcSpotLight(spotLights[i], Normal);
	}

	float reflectiveFactor = texture2D(reflectiveTexture, uv0).r;
	vec3 cubeColor = texture(cubeMapTexture, uv1.xyz).rgb;
 
	finalColor = MaterialDiffuseColor * TotalLight;
	finalColor = vec4(mix(finalColor.rgb,cubeColor,reflectiveFactor),1.0);
}

vec3 CalcBumpedNormal()
{
    vec3 Normal = normalize(normal0);
    vec3 Tangent = normalize(tangent0);
	vec3 Bitangent = normalize(bitangent0);
    Tangent = normalize(Tangent - dot(Tangent, Normal) * Normal);
    vec3 BumpMapNormal = texture(normalTexture, uv0).xyz;
    BumpMapNormal = 2.0 * BumpMapNormal - vec3(1.0, 1.0, 1.0);
    vec3 NewNormal;
    mat3 TBN = mat3(Tangent, Bitangent, Normal);
    NewNormal = TBN * BumpMapNormal;
    NewNormal = normalize(NewNormal);
    return NewNormal;
}
 
vec4 CalcLightInternal(BaseLight _light, vec3 _lightDirection, vec3 _normal)
{
	vec3 VertexToEye = vec3(0.0, 0.0, 0.0);
	VertexToEye = normalize(cameraEyeWorldPosition - worldPos0);

	vec4 AmbientColor = vec4(0.0, 0.0, 0.0, 0.0);

	AmbientColor = _light.colour * (texture2D(ambientTexture, uv0));
	
	float DiffuseFactor = 1.0;
	DiffuseFactor = dot(normalize(_normal), _lightDirection);

	DiffuseFactor = max(0.0,DiffuseFactor);
 
	vec4 DiffuseColor = vec4(0.0, 0.0, 0.0, 0.0);
	vec4 SpecularColor  = vec4(0.0, 0.0, 0.0, 0.0);
 
    DiffuseColor = _light.colour * _light.diffuseIntensity * DiffuseFactor;
		
	vec3 LightReflect = vec3(0.0, 0.0, 0.0);
	float SpecularFactor = 0.0;

	LightReflect = 2.0 * dot(_lightDirection, normal0) * normal0 - _lightDirection;

	SpecularFactor = dot(VertexToEye, LightReflect);;
		
	SpecularFactor = max(0.0,SpecularFactor);

	float specularPower = (texture2D(glossTexture, uv0).r);
	float specularIntensity = texture2D(specularTexture, uv0).r;

	SpecularFactor = pow(SpecularFactor, specularPower);
	SpecularColor = _light.colour * specularIntensity * SpecularFactor;
 
	return (AmbientColor /*+ RimColor*/ + DiffuseColor + SpecularColor);
}
 
vec4 CalcDirectionalLight(vec3 _normal)
{
    return CalcLightInternal(directionalLight.base, directionalLight.direction, _normal);
}
 
vec4 CalcPointLight(PointLight _light, vec3 _normal)
{
	vec3 LightDirection = vec3(0.0, 0.0, 0.0);
	float Distance = 0.0;

    LightDirection = worldPos0 - _light.position;
    Distance = length(LightDirection);
    LightDirection = normalize(LightDirection);
	
	vec4 Color = vec4(0.0, 0.0, 0.0, 0.0);
	float Attenuation = 1.0;

    Color = CalcLightInternal(_light.base, LightDirection, _normal);

	Attenuation =  _light.attenuation.constant +
							_light.attenuation.linear * Distance +
							_light.attenuation.exponential * Distance * Distance; 
 
	return Color/Attenuation;
}  

vec4 CalcSpotLight(SpotLight _light, vec3 _normal)
{
	vec3 LightToPixel = vec3(0.0,0.0,0.0);
	float SpotFactor = 0.0;
	
    LightToPixel = normalize(worldPos0 - _light.base.position);
    SpotFactor = dot(LightToPixel, _light.direction);

    if (SpotFactor > _light.cutoff) 
	{
        vec4 Color = CalcPointLight(_light.base, _normal);
        return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - _light.cutoff));
    }
    else 
	{
        return vec4(0.0, 0.0, 0.0, 0.0);
    }
}

 

This issue is now solved, I had two textures using the same texture unit.

Edited by harshman_chris
0

Share this post


Link to post
Share on other sites

Is "reflectiveFactor" a sensible value? Try hardcoding it to 0.2 or something. Also, It looks like the fragment wasn't just blank, it didn't exist--this maybe points to a problem in your shader's compilation. Maybe also try expanding out the mix function (i.e. "(1.0-0.2)*baseColour.rgb+0.2*cubeColor").

-G

0

Share this post


Link to post
Share on other sites

Is "reflectiveFactor" a sensible value? Try hardcoding it to 0.2 or something. Also, It looks like the fragment wasn't just blank, it didn't exist--this maybe points to a problem in your shader's compilation. Maybe also try expanding out the mix function (i.e. "(1.0-0.2)*baseColour.rgb+0.2*cubeColor").

-G

 

Already done, same result.

 

Edit:

 

So I set the outColour to vec4(1.0,1.0,1.0,1.0);

 

and then I run GEDebugger, and it doesnt break when I break on error, but if I ad one line, such as this.

 

Edit Again:

 

So the error I get is on the glDrawElements - GL_INVALID_OPERATION.

 

Which is one of two things:

 

GL_INVALID_OPERATION is generated if a geometry shader is active and mode is incompatible with the input primitive type of the geometry shader in the currently installed program object.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array or the element array and the buffer object's data store is currently mapped.

 

Neither of these seem to apply though to this type of issue.

 

 

finalColor.r = (baseColour.r * (1.0 - 0.2)) + (cubeColor.r * 0.2);
 

 

It will break on an error, so there must be an error I will have to get and output. It is not a compile or linking error though because those are output.

 

Edit Again:

 

So I have narrowed down the issue to adding the the result of the first and second parts of the lerp.

 

Here is the first lerp part

[attachment=14294:first.png]

 

The second lerp part

[attachment=14295:second.png]

 

So these when added causes an OpenGL error. What would cause two vec3's being added together to cause this error? Considering both are valid on there own, but added them breaks it?

Edited by harshman_chris
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0