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

Specular questions (with pics)

4 posts in this topic

Hi,

I'm redoing my specular highlight implementation in my shaders, and with this I have a few short questions. Also after refreshing my knowledge reading some articles. This is my calculation in pseudo:

 

** viewdir = normalize(camerapos - vtx wpos)

** half vector = normalize(viewdir + -lightdir

** specular term = pow(saturate(dot(half, normal)), power) * lightcolor/intensity 

 

My specular material properties I retrieve like this (from 3ds max):

- specular level RGB, i.e. 1.0 / 1.0 / 1.0 is full bright white

- specular power is glossiness from max (50 in max = 50, 100 in max = 100 power)

 

My questions:

- would you agree that I could use either lightcolor/intensity or specular material level (/color)? Where the 1st makes the specular highlights in the color of the light, and the 2nd makes them the color of the specular properties of the material?

- in the past I had 2 different approaches to getting the lightdir for the half vector equation:

 

1. lightdir = -lightdir (most logical)

2. lightdir = normalize(-lightdir  - vtx wpos)

 

Both work, bot from all theory I know the 1st one seems most realistic/best. What would you say?

 

- is it correct that a specular highlight on for example a glass material, gets bigger the further the camera is away?

Here's an example from further and nearer to a glass material:

 

specular_far.jpg

 

specular_near.jpg

Edited by cozzie
0

Share this post


Link to post
Share on other sites

The specular material property is a mask describing how much red, green and blue light the surface reflects - its a ratio of the light intensity, so you should be using both.

0

Share this post


Link to post
Share on other sites
Thanks, that means I would need to multiply with both the specular material level/color and the light color/intensity (both vectors).

I'm actually not sure how it works in real life, I believe for metals the specular highlight is more or less the color of the materials specular reflection, and for none metals it's more or less the color of the light.

What I can't figure out is why I need to multiply my specular power enormously to get a nice highlight. For example the power of my glass material is 75 (from max exported), but only when I multiply/ change it to become around 8000, the highlight looks ok. Is there a logical/ mathematical reason for this? (couldn't find it in the articles I looked up)
0

Share this post


Link to post
Share on other sites

That depends if you're trying to be "physically based" with your shading.

In real life every material has a characteristic Fresnel Reflectance which is measured at normal incidence angle. That would be your SpecularColor or SpecularIntensity.

You can think of it as the minimum intensity of its reflectivity because it will always reach a maximum reflectivity of 1 (=solid white) depending on the viewing angle. Most materials have indeed very low fresnel reflectance (~0.02) whereas metals already start at ~0.7-0.8 (which is why they seem so shiny smile.png ).

The reason your specular highlight changes with increasing distance might be because of mipmapping and filtering of the normal map.

 

@op calculating the light direction depends on what kind of light it is. For a directional light you just use the light direction (negated because we shade from the view of the pixel/surface) but for example point light you'd need to calculate the light direction as a function of the light's position and the object's position (kind of like you did in the second example).

And like digitalfragment said you have to multiply by both the light's color and the materials specular color.

I'm not familiar with the settings for blinn-phong in 3ds max but if it's a value from 0 - 100 then they probably map it differently.

One mapping that I like is this one which ranges from 2-2048:

SpecularPower = exp2(10 * gloss + 1)

gloss = value from 0 to 1 (for example what you'd read in your shader from a gloss map)

 

If you're interested in physically-based-shading I'd recommend reading this: http://blog.selfshadow.com/publications/s2013-shading-course/ (Background: Physics and Math of Shading slides)

Edited by lipsryme
0

Share this post


Link to post
Share on other sites

Hi.

Thanks for the information, I've been playing around and stupidly the material I was testing with had a very low shininess in max, so raising that closer to 100 solved it without actualy 'rescaling' the specular power (I now just adapt the value from max).

 

The formula you gave though can be very useful when I start working with gloss maps (probably a while from now, but never the less :))

 

My shader(s) now take both the lightcolor as the diffuse material component into account, here's a snippet of the shader:

// directional light, specular term

		if(any(MatSpec))
		{
			float3 h = normalize(-DirLightDir[i] + input.ViewDir);	
				
			float specular = max(dot(h, normalMap), 0.0f);
			specularAcc = pow(specular, MatSpecPower) * DirLightColInt[i] + specularAcc;
		}

// the final addition/ calculation returning the end color

	float3 cd = (MatDiff * diffuseAcc + hemiAmb); 
	float3 ci = (MatSpec * specularAcc + MatEmi);
	float3 final = textureColor.rgb * cd + ci; 
	return float4(final, textureColor.a);

Some more tests also showed I should be fine for now, below 2 screenshots.

Regarding physical based shading, I didn't get into it yet, too much to do on my engine in too little time (day job takes so much time :))

 

2014-05_specular_ok1.jpg

 

2014-05_specular_ok2.jpg

1

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