Jump to content
  • Advertisement
Sign in to follow this  
redspike474

Directional lightmapped specular

This topic is 1046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Found this implementation of specular lightmaps https://github.com/Geenz/GzRNM/blob/719a8a7340fc2cd16b9a9072cd76feddaec0e7c9/GzRNMOS/Assets/GzRNM/Shaders/GzRNMPro/GzRNMInc.cginc

 

But this produces three specular lobes  (one for each basis) and is rather wrong looking, the developer addresses it on this forum page http://forum.unity3d.com/threads/geenzs-rnm-shaders-now-released.71648/page-2 but he never released the update as far as i can see.

 

Will continue to experiment!

Share this post


Link to post
Share on other sites

Thanks @MJP for the incredibly informative reply! that's a tonne of useful information.

 

 

 

This was the approach taken by Bungie for Halo 3, and was discussed in their SIGGRAPH presentation as well as their course notes.

More recently, we presented some info at SIGGRAPH about our lightmap baking for The Order.

 

Ideally i would love to do something like either of these implementations but it isn't currently feasible for this particular project, its also slightly beyond my current capability.

 

 

 

You could also try computing a "dominant direction" from your lightmap info and treating that as a directional light, but these approaches can sometimes suffer from interpolation issues where the dominant direction doesn't match up from texel to another. 

 

I took your advice and implemented a hacky phong specular with a dominant direction, It produces much better results than my previous implementation! here is my code, please feel free to pick it apart and point out any mistakes or suggest any improvements, Im still very much a novice. Though LOOKS right ingame........

#if( PHONG && !PS4)
{	
	float3 vEyeDir = normalize( g_EyePos - worldPos );	
	half SpecExponentMap = tex2D(SpecExponentSampler, coords.xy).r;

	float lumer1 = ( Luminance( lightmapColor1.rgb )  );	
	float lumer2 = ( Luminance( lightmapColor2.rgb )  );	
	float lumer3 = ( Luminance( lightmapColor3.rgb )  );		
			
	float3 	vLightDomDir = normalize (lumer1 * bumpBasis[0] + lumer2 * bumpBasis[1] + lumer3 * bumpBasis[2]);
	
	float3 vHalfAngle = normalize( vEyeDir.xyz + vLightDomDir.xyz );
	float flNDotH = saturate( dot( worldSpaceNormal.xyz, vHalfAngle.xyz ) );
		
	SpecPhong = pow( flNDotH, SpecExponentMap ); // Raise to specular exponent
	SpecPhong *= pow( saturate( dot( worldSpaceNormal, vLightDomDir ) ), 0.5 ); // Mask with N.L raised to a power
	
	
	float3 d_irradiance = 0;
	d_irradiance.x = dot(bumpBasis[0], vLightDomDir);
	d_irradiance.y = dot(bumpBasis[1], vLightDomDir);
	d_irradiance.z = dot(bumpBasis[2], vLightDomDir);
	d_irradiance*= d_irradiance;
	d_irradiance = d_irradiance.x *  lightmapColor1.rgb +  d_irradiance.y * lightmapColor2.rgb + d_irradiance.z * lightmapColor3.rgb;
	SpecPhong *=   d_irradiance; // color the specular from the d_irradiance

	float3  vSpecularTint =1; // leaving this in for now, models have the ability to tint specular

	float fSpecMask = 1.0f;
	fSpecMask =  baseColor.a; // hardcode for now
	//fSpecMask = lerp( normalTexel.a, baseColor.a, g_fBaseMapAlphaPhongMask );
	//fSpecMask = lerp( fSpecMask, baseLum, g_fBaseLumPhongMask );

	SpecPhong *= fSpecMask * vSpecularTint;
		

	float3 g_FresnelRanges = float3 ( 0.3, 9.0, 28 ); // test vaules to match models material // need to hook up to material
	float fFresnelRanges;
	fFresnelRanges = Fresnelcustom( worldSpaceNormal, vEyeDir, g_FresnelRanges );
	SpecPhong *= fFresnelRanges;
	
	//to do look at this again.
	#if ( ( CASCADED_SHADOW_MAPPING ) && ( CASCADE_SIZE > 0 ) )
	{	
	// Apply csm shadows
	//SpecPhong.rgb *= shadowscalarpassthrough;
	}
	#endif
		
	//note note - not sure why we would want rim lighting on brushwork so left it out. but could bring back for cheap;
}

Thanks! smile.png

Edited by redspike474

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!