• 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
Yura

Applying light effects and reflection

6 posts in this topic

Hi all,

I'm trying to enable light on my 3D scene and make my primitives a little specular. A little means that they have their color and it's must be visible but they must to reflect light on the normal direction. smile.png

 

My problem is that rendered model is black. If I disable shader function it seems to be OK, but light does not work as well

Light light = new Light()
            {
                Type = LightType.Directional,
                Diffuse = SharpDX.Color.White,
                Direction = Vector3.Normalize(new Vector3(0, 0, 1)),
            };
            d3dDevice.SetLight(0, ref light);
            d3dDevice.EnableLight(0, true);

 

 

Texture CubeMap;

samplerCUBE enviroMap = 
sampler_state
{
    Texture = <CubeMap>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
};

//VertexShader function with reflection calculations
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
	VertexShaderOutput output = (VertexShaderOutput)0;
	
	output.Position = mul(input.Position, worldViewProj);

	
	//
	float3 Normal = float3(0,1,0);
	
	// Compute normal in camera space
    float4 NormalVec = normalize( mul( worldViewProj, Normal ) );

    // Obtain the reverse eye vector
    float4 EyeVec = normalize( mul( output.Position, worldViewProj ) );

    // Compute the reflection vector
    float4 Reflect = reflect( -EyeVec, NormalVec );
	Reflect = refract( EyeVec, NormalVec, 0.8f );  

    // Store the reflection vector in texcoord0
    output.reflectionCoord = Reflect.xyz;
	
    return output;
}

//PixelShader function
float4 PixelShaderFunction(VertexShaderOutput input, float face : VFACE) : COLOR
{	
        float reflectivity = 0.5f;
	float4 color = reflectivity * texCUBE( enviroMap, input.reflectionCoord );	
	return color;
}

 

 

0

Share this post


Link to post
Share on other sites

If you are using shaders, then you can't use the light API in D3D9 - that is for fixed function processing only.  Instead, you have to pass the information in directly as constants to the shader program.

2

Share this post


Link to post
Share on other sites

If you are using shaders, then you can't use the light API in D3D9 - that is for fixed function processing only.  Instead, you have to pass the information in directly as constants to the shader program.

 

You are right, I've fixed a light, but my problem is still unsolved. To describe it better, I'm attaching some screenshots:

 

I have a model, which is empty inside  [attachment=14249:Capture.PNG] [attachment=14250:Capture2.PNG]

 

And when I disable lines, I get unclear what : [attachment=14251:Capture3.PNG] [attachment=14252:Capture4.PNG]

 

 

I want to make a light reflection to fix this problem, but the hlsl reflection code, which I posted above, is not what I need.

0

Share this post


Link to post
Share on other sites

The problem is that I don't have Normal vector on each vertice, so I'm using one default (0,1,0) for all vertices, and this is not good! I don't know where to find or how to calculate normal on each vertice, so I tried to make  reflection map, but with no desired result...

0

Share this post


Link to post
Share on other sites

I don't know where to find or how to calculate normal on each vertice, so I tried to make  reflection map, but with no desired result...

 

There is a lot of information conerning this in a web. I.E. here http://www.riemers.net:

            for (int i = 0; i < indices.Length / 3; i++)
             {
                 Vector3 firstvec = vertices[indices[i*3+1]].Position-vertices[indices[i*3]].Position;
                 Vector3 secondvec = vertices[indices[i*3]].Position-vertices[indices[i*3+2]].Position;
                 Vector3 normal = Vector3.Cross(firstvec, secondvec);
                 normal.Normalize();
                 vertices[indices[i * 3]].Normal += normal;
                 vertices[indices[i * 3 + 1]].Normal += normal;
                 vertices[indices[i * 3 + 2]].Normal += normal;
             }
1

Share this post


Link to post
Share on other sites

Thanks user88! I calculated normals and all seems to be ok.

I've implemented Blinn-Phong algorithm, it is what I need! But I have a question: I have vectors EyePosition and LooAtVector and I want source light always be at the camera position. Otherwords, the side of the figure, on which I'm looking, must be lighted. Look at my source code and tell me what I'm doing wrong:

 

//Vertex shader
......
// Will be moved into PixelShader for deferred rendering	 
    float3 lightDirection = LookAtPosition;
    output.L = -lightDirection;	            // Light Direction 
    output.N = mul(input.Normal, World);    // Surface Normal [World Coordinates]
.......

float4 PixelShaderFunction(VertexShaderOutput input, float face : VFACE) : COLOR
{	
        //my color
	float4 color = colors[round(input.texCoord * 11)];
	
	// [Ambient Light] I = Ai * Ac	
	float Ambient_Intensity = 0.7f;
	float4 Ambient_Colour = color;
	float4 Ambient_Light = Ambient_Intensity * Ambient_Colour;
	
	
	// [Diffuse Light] I = Di * Dc * N.L	
	float Diffuse_Intensity = 0.7f;
	float4 Diffuse_Colour = color;
	float NdotL = dot(normalize(input.N), normalize(input.L));
	float4 Diffuse_Light = Diffuse_Intensity * color * saturate(NdotL);		

	//----------Blinn-Phong

	// Compute the half vector Eye + Light
    float3 half_vector = normalize(EyePosition + EyePosition); //in my case eye+eye, couse I want light to be the same position as light
 
    // Compute the angle between the half vector and normal
    float  HdotN = max( 0.0f, dot( half_vector, input.N ) );
 
    // Compute the specular colour
    float4 cSpecular = float4(1.0f,1.0f,1.0f,1.0f); //white
	float fSpecularExponent = 5; 
    float3 specular = cSpecular * pow( HdotN, fSpecularExponent );
 
    // Determine the final colour    
    return float4( Diffuse_Light + specular + Ambient_Light, 1.0f );
}
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