Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


alkisbkn

Member Since 21 Feb 2008
Offline Last Active Oct 22 2014 10:26 AM

#5180441 PBR (blurry reflections)

Posted by alkisbkn on 15 September 2014 - 06:47 AM

Right, so I restructured my shader to something which seems to be correct.

Basically I have 2 material modes, metallic and non metallic (as UE4 does), and if I want anything in between, I interpolate. The shader code as it stands now looks like this:


half3 reflection = texCUBEbias (_ReflectionTex, float4(i.reflectDir, (1-roughness)*6));
				
half specPower = exp2(10 * roughness + Log2Of1OnLn2_Plus1);
				
half3 light = DecodeLightmap(lightmap);
half3 fresnel = schlick(NdotV, metalness);

half3 specular =  (LN2DIV8 * specPower + 0.25) * SphericalGaussianApprox(HdotN, specPower) * fresnel;
				
half3 ec = saturate(1 - (specular + reflection));
				
half3 plastic = albedo.rgb * light * ec + specular;
half3 metallic = (specular*albedo + reflection * albedo.rgb) * Luminance(light);

return half4(lerp(plastic, metallic, metalness), 1);

I am also using Lagarde's spherical gaussian approximation for the specular component which saves me quite a bit with negligible quality loss. Thumbs up for that!

 

So basically if it's metal, I ignore the albedo and simply have specular + reflection, multiplied by the lightmap.

If it's plastic, I use the albedo times lightmap, with added specular.

 

The specular colour depends on the metalness. For metals, it's coloured (using the albedo), for non-metals it's constant white.

The result looks like this (all the spheres have an albedo of "gold", but metalness and roughness varies diagonally, specular on the plastic balls is there, but it's hidden by the geometry at times)

 

2j2ddp2.png

 

The reflection cubemap is not prefiltered properly, so that's my next step!

 

Total fragment shader cost is about 27 instructions, with room for more optimisation.




#5180059 PBR (blurry reflections)

Posted by alkisbkn on 13 September 2014 - 07:02 AM

half-precision (or even fixed) floats are generally faster than 32bit floats, especially on mobile hardware. I'm just trying to squeeze out every performance that the powervr chips have to offer :)




#5159205 Best comment ever

Posted by alkisbkn on 09 June 2014 - 02:29 AM

/*

      .o.       ooooooooo.   ooooo      ooo   .oooooo.   ooooo        oooooooooo.   o8o  .oooooo..o      oooooooooooo       .o.       ooooo     ooo ooooo        ooooooooooooo 
     .888.      `888   `Y88. `888b.     `8'  d8P'  `Y8b  `888'        `888'   `Y8b  `YP d8P'    `Y8      `888'     `8      .888.      `888'     `8' `888'        8'   888   `8 
    .8"888.      888   .d88'  8 `88b.    8  888      888  888          888      888  '  Y88bo.            888             .8"888.      888       8   888              888      
   .8' `888.     888ooo88P'   8   `88b.  8  888      888  888          888      888      `"Y8888o.        888oooo8       .8' `888.     888       8   888              888      
  .88ooo8888.    888`88b.     8     `88b.8  888      888  888          888      888          `"Y88b       888    "      .88ooo8888.    888       8   888              888      
 .8'     `888.   888  `88b.   8       `888  `88b    d88'  888       o  888     d88'     oo     .d8P       888          .8'     `888.   `88.    .8'   888       o      888      
o88o     o8888o o888o  o888o o8o        `8   `Y8bood8P'  o888ooooood8 o888bood8P'       8""88888P'       o888o        o88o     o8888o    `YbodP'    o888ooooood8     o888o     
                                                                                                                                                                               





*/



#5156296 Best comment ever

Posted by alkisbkn on 27 May 2014 - 10:50 AM

Okay, although this is not a code snippet, it can trigger your imagination about what we've been going through with this guy's code smile.png

This is the comment that I came across (obviously after another programmer fixed his mental code design and bugs)

 

// TODO BILLYPotentially improve programming skills




#5138892 [C#] How to skew a mesh via matrix?

Posted by alkisbkn on 14 March 2014 - 03:39 AM

I figured it out myself, thanks.

Don't you just love when this happens :) People not posting the answers they find to their questions themselves, just stating that they found it.

Not that I need the answer, it could help someone else though, and this keeps happening on forums.




PARTNERS