• 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
Medo Mex

Directional Light

36 posts in this topic

@Anddos: I have been looking at the sample for a very long time, I still didn't get it to work as expected.

 

You might want to look at the shader code that I recently posted to make sure that there is no bugs.

-1

Share this post


Link to post
Share on other sites

When I change the line:

float3 viewDir =  cameraPos - worldPos;

To:

float3 viewDir =  worldPos - cameraPos;

I get better results, however, when I set a small number for the material power (shininess) I get very high specular light and when I set a large number for the material power (shininess) I get smaller specular light.

0

Share this post


Link to post
Share on other sites

Daft question, but why are you multiplying the normal by the world matrix in your vertex shader?

Out.Normal = mul(IN.Normal, (float3x3)World);

Aimee

Edited by AmzBee
0

Share this post


Link to post
Share on other sites

@AmzBee


Daft question, but why are you multiplying the normal by the world matrix in your vertex shader?

They are directional vectors and are dependent on object orientation.

 

@Medo


Well, I still don't see the specular light, however when I move the mesh and rotate it I begin to see the specular light (but in weird shape and just a tiny spot in random position on the mesh):

 

specular highlight wiki


Specular reflection is visible only where the surface normal is oriented precisely halfway between the direction of incoming light and the direction of the viewer; this is called the half-angle direction because it bisects (divides into halves) the angle between the incoming light and the viewer

 


I get better results, however, when I set a small number for the material power (shininess) I get very high specular light and when I set a large number for the material power (shininess) I get smaller specular light.

That is to be expected.

0

Share this post


Link to post
Share on other sites

@belfegor: 

 

That is to be expected.

 

 

How do I fix that? I'm expecting If:

 

Shininess = 0 then no specular light

Shininess = 5 then a little specular

Shininess = 80 then high specular

 

What I'm getting now? 1 = High specular light, 80 = Less specular light, 200 = Tiny specular light

Edited by Medo3337
0

Share this post


Link to post
Share on other sites

@Anddos: I'm just creating a single directional light:

pEffect->SetMatrix("View", &view);
pEffect->SetMatrix("Projection", &proj);

// Light
float lightDiffuse[4] = {0.9f, 0.9f, 0.9f, 1.0f};
float lightSpecular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
pEffect->SetValue("lightDiffuse", &lightDiffuse, sizeof(lightDiffuse));
pEffect->SetValue("lightSpecular", &lightSpecular, sizeof(lightSpecular));

// Material
float materialDiffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
float materialAmbient[4] = {0.15f, 0.15f, 0.15f, 1.0f};
float materialSpecular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
float materialPower = 1.0f; // *** Here I'm setting the value to 1.0f and getting high specular light, I'm expecting the specular light to be low since the value is low number ***

pEffect->SetValue("materialDiffuse", &materialDiffuse, sizeof(materialDiffuse));
pEffect->SetValue("materialAmbient", &materialAmbient, sizeof(materialAmbient));
pEffect->SetValue("materialSpecular", &materialSpecular, sizeof(materialSpecular));
pEffect->SetFloat("materialPower", materialPower);

float gAmbient[4] = { 0.2f, 0.2f, 0.2f, 0.0f };
pEffect->SetValue("globalAmbient", &gAmbient, sizeof(gAmbient));

// Directional light
D3DXVECTOR3 lightDirection(-1.0f, 0.0f, -1.0f);
pEffect->SetValue("lightDirection", &lightDirection, sizeof(lightDirection));

pEffect->SetValue("cameraPos", &camera->position(), sizeof(camera->position()));
pEffect->SetTexture("colorMapTexture", texture);
Edited by Medo3337
0

Share this post


Link to post
Share on other sites


How do I fix that?

What is broken?

You could make variety of material types with different "Shininess" in combination with specular maps (watch this video about specular maps).

0

Share this post


Link to post
Share on other sites

@belfegor: I think there is something confusing here, isn't "Shininess" same as specular level?

 

I want to control how much specular color will affect the mesh.

 

In 3Ds Max I control that by setting "Specular level" in the material window, how do I use this level in my light shader?

 

[attachment=16959:spec-max.png]

0

Share this post


Link to post
Share on other sites

Here is the hlsl output for 3ds max default standard material:

material-editor-01-defau.jpg

struct PixelInput {
    float4 norm        : TEXCOORD0;
    float4 worldpos    : TEXCOORD1;
    float4 eyevector    : TEXCOORD2;
    float4 tangent        : TEXCOORD3;
    float4 binormal    : TEXCOORD4;
    float4 objpos        : TEXCOORD5;
    float4 tex0        : TEXCOORD6;
    float4 tex1        : TEXCOORD7;
};


struct PixelOutput {
    float4 c         : COLOR;
};


uniform float4 Diffuse = float4(0,588235,0,588235,0,588235,1,000000);
uniform float4 Specular = float4(0,900000,0,900000,0,900000,1,000000);
uniform float4 Emissive = float4(0,000000,0,000000,0,000000,1.0f);
uniform float SpecularLevel = 1,000000;
uniform float GlossLevel = 9,999999;
uniform float3 LightCol0;
uniform float3 LightDir0;
uniform float LightFallOff0;
uniform float LightHotSpot0;
uniform float Opacity = 1,000000;

PixelOutput fragmentEntry(PixelInput pi)
{
    PixelOutput PO;
    float3 N;
    N = normalize(pi.norm.xyz);
    float3 Eye;
    Eye.xyz = normalize(pi.eyevector.xyz);
    float4 nColor = float4(0.0,0.0,0.0,1.0);
    float4 mDiffuse = Diffuse;
    float4 mSpecular = Specular;
    float4 SelfIllum = Emissive;
    nColor = nColor + SelfIllum * mDiffuse;
    float3  H;
    float3 Light;
    float f;
    float fAtt;
    float fDist;
/*  default light */
    fAtt = 1.0;
    nColor = nColor + float4(LightCol0,1.0) * mDiffuse * clamp(dot(N,LightDir0),0,1) * fAtt;
    H = normalize(Eye+Light);
    f = clamp(dot(N,H),0,1);
    f = pow(f, GlossLevel);
    f = f * SpecularLevel;
    nColor = nColor + float4(LightCol0,1.0) * mSpecular * f * fAtt;
/* end of default light */
    nColor.a = Opacity;
    PO.c = nColor;
    return PO;
}


Looks like they use Glossiness as "materialPower/Shinniness" and "Specular level" is just scalar for specular power (i would set it to 100 (1.0) to match your shader).

Edited by belfegor
1

Share this post


Link to post
Share on other sites

@belfegor: Damn, I have been thinking that the specular shininess is the specular level! angry.png

 

I notice that it's set to 10 in 3Ds Max while in the shader it's "uniform float SpecularLevel = 1,000000;", why is that?

 

I will get the specular level from the .x file so I can pass the value to the shader, is the following correct?

float power = pow(nDotH, materialPower);
power *= specularLevel;

Remember that If I set specular level to 80 in 3Ds Max I want it to appear the same in my own program.

Edited by Medo3337
0

Share this post


Link to post
Share on other sites

I notice that it's set to 10 in 3Ds Max while in the shader it's "uniform float SpecularLevel = 1,000000;", why is that?

I would say because artists are accustomed on that way, looks like that is represented as percent in max and then converted before sent to shader.
There is other similar things too, for example most people are accustomed to degrees (because it is easier to visualise it) but some functions expect number in radians, in some scripting languages array indexing starts at 1 not 0 as in c++... etc
 

Remember that If I set specular level to 80 in 3Ds Max I want it to appear the same in my own program.

 
Use the same shader lightning formula and you will get same output.

 

 


I notice that it's set to 10 in 3Ds Max while in the shader it's "uniform float SpecularLevel = 1,000000;", why is that?

I noticed one thing so i will mention it to you. If you save material as FX from max, do not overwrite existing file as it will not update it, so rename it or delete old.

Edited by belfegor
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