Shader assembly of fresnel approximation

Test code

//----------------------------------------------------------------------------------------------------
// Fresnel test shader by hanecci
//
// This software is released under the Unlicense. ( http://unlicense.org/ )
//
// This is free and unencumbered software released into the public domain.
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any means.
//
//----------------------------------------------------------------------------------------------------

in vec3         normal;
in vec3         half_vec;
uniform vec3    f0;

#define FRESNEL_MODE       ( 0 )

#define FRESNEL_NO_OPT     ( 0 )
#define FRESNEL_BLACK_OPS2 ( 1 )
#define FRESNEL_SEBASTEIN0 ( 2 )
#define FRESNEL_SEBASTEIN1 ( 3 )
#define FRESNEL_DISNEY	   ( 4 )

void main( void )
{
	vec4 color = vec4( 0.0, 0.0, 0.0, 0.0 );

	float dot_n_h = dot( normal, half_vec );

#if ( FRESNEL_MODE == FRESNEL_NO_OPT )

	color.rgb = f0 + ( vec3(1.0) - f0 ) * pow( dot_n_h, 5 );

#elif ( FRESNEL_MODE == FRESNEL_BLACK_OPS2 )

	color.rgb = f0 + ( vec3(1.0) - f0 ) * exp2( - 10.0 * dot_n_h );

#elif ( FRESNEL_MODE == FRESNEL_SEBASTEIN0 )

	color.rgb = f0 + ( vec3(1.0) - f0 ) * exp2( - 8.35 * dot_n_h );

#elif ( FRESNEL_MODE == FRESNEL_SEBASTEIN1 )

	color.rgb = f0 + ( vec3(1.0) - f0 ) * exp2( ( - 5.55473 * dot_n_h - 6.98316 ) * dot_n_h );	

#elif ( FRESNEL_MODE == FRESNEL_DISNEY )

	float value2 = dot_n_h * dot_n_h;
	float value5 = value2 * value2 * dot_n_h;
	color.rgb    = mix( f0, vec3(1), value5 );

#endif

	gl_FragColor = color;
}

No optimization

; --------  Disassembly --------------------
00 ALU: ADDR(32) CNT(16) 
      0  x: DOT4        ____,  R0.x,  R1.x      
         y: DOT4        ____,  R0.y,  R1.y      
         z: DOT4        ____,  R0.z,  R1.z      
         w: DOT4        ____,  (0x80000000, -0.0f).x,  0.0f      
         t: ADD         R0.y, -C0.x,  1.0f      
      1  x: ADD         R0.x, -C0.y,  1.0f      
         w: ADD         R0.w, -C0.z,  1.0f      
         t: LOG_sat     ____,  PV0.x      
      2  w: MUL         ____,  PS1,  (0x40A00000, 5.0f).x      
         t: MOV         R1.w,  0.0f      
      3  t: EXP_e       ____,  PV2.w      
      4  x: MULADD      R1.x,  PS3,  R0.y,  C0.x      
         y: MULADD      R1.y,  PS3,  R0.x,  C0.y      
         z: MULADD      R1.z,  PS3,  R0.w,  C0.z      
01 EXP_DONE: PIX0, R1
END_OF_PROGRAM

"Black Ops 2" @ SIGGRAPH 2013

; --------  Disassembly --------------------
00 ALU: ADDR(32) CNT(15) 
      0  x: DOT4        ____,  R0.x,  R1.x      
         y: DOT4        ____,  R0.y,  R1.y      
         z: DOT4        ____,  R0.z,  R1.z      
         w: DOT4        ____,  (0x80000000, -0.0f).x,  0.0f      
         t: ADD         R0.y, -C0.x,  1.0f      
      1  x: ADD         R0.x, -C0.y,  1.0f      
         y: ADD         R1.y, -C0.z,  1.0f      
         w: MUL         ____,  PV0.x,  (0xC1200000, -10.0f).x      
         t: MOV         R2.w,  0.0f      
      2  t: EXP_e       ____,  PV1.w      
      3  x: MULADD      R2.x,  PS2,  R0.y,  C0.x      
         y: MULADD      R2.y,  PS2,  R0.x,  C0.y      
         z: MULADD      R2.z,  PS2,  R1.y,  C0.z      VEC_021 
01 EXP_DONE: PIX0, R2
END_OF_PROGRAM

"Approximate Fresnel with Spherical Gaussian"

Version0

; --------  Disassembly --------------------
00 ALU: ADDR(32) CNT(15) 
      0  x: DOT4        ____,  R0.x,  R1.x      
         y: DOT4        ____,  R0.y,  R1.y      
         z: DOT4        ____,  R0.z,  R1.z      
         w: DOT4        ____,  (0x80000000, -0.0f).x,  0.0f      
         t: ADD         R0.y, -C0.x,  1.0f      
      1  x: ADD         R0.x, -C0.y,  1.0f      
         y: ADD         R1.y, -C0.z,  1.0f      
         w: MUL         ____,  PV0.x,  (0xC105999A, -8.350000381f).x      
         t: MOV         R2.w,  0.0f      
      2  t: EXP_e       ____,  PV1.w      
      3  x: MULADD      R2.x,  PS2,  R0.y,  C0.x      
         y: MULADD      R2.y,  PS2,  R0.x,  C0.y      
         z: MULADD      R2.z,  PS2,  R1.y,  C0.z      VEC_021 
01 EXP_DONE: PIX0, R2
END_OF_PROGRAM

Version1

; --------  Disassembly --------------------
00 ALU: ADDR(32) CNT(16) 
      0  x: DOT4        ____,  R0.x,  R1.x      
         y: DOT4        R0.y,  R0.y,  R1.y      
         z: DOT4        ____,  R0.z,  R1.z      
         w: DOT4        ____,  (0x80000000, -0.0f).x,  0.0f      
         t: ADD         R1.y, -C0.x,  1.0f      
      1  x: MULADD      R127.x,  PV0.x,  (0xC0B1C059, -5.554729939f).y,  (0xC0DF760C, -6.983160019f).x      
         y: ADD         R2.y, -C0.y,  1.0f      
         w: ADD         R0.w, -C0.z,  1.0f      
         t: MOV         R3.w,  0.0f      
      2  w: MUL         ____,  R0.y,  PV1.x      
      3  t: EXP_e       ____,  PV2.w      
      4  x: MULADD      R3.x,  PS3,  R1.y,  C0.x      
         y: MULADD      R3.y,  PS3,  R2.y,  C0.y      VEC_021 
         z: MULADD      R3.z,  PS3,  R0.w,  C0.z      
01 EXP_DONE: PIX0, R3
END_OF_PROGRAM

Fresnel at Disney BRDF

# Copyright Disney Enterprises, Inc.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License
# and the following modification to it: Section 6 Trademarks.
# deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the
# trade names, trademarks, service marks, or product names of the
# Licensor and its affiliates, except as required for reproducing
# the content of the NOTICE file.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0

float SchlickFresnel(float u)
{
    float m = clamp(1-u, 0, 1);
    float m2 = m*m;
    return m2*m2*m; // pow(m,5)
}

float FH = SchlickFresnel(LdotH);
vec3 Fs = mix(Cspec0, vec3(1), FH);
; --------  Disassembly --------------------
00 ALU: ADDR(32) CNT(15) 
      0  x: DOT4        ____,  R0.x,  R1.x      
         y: DOT4        R127.y,  R0.y,  R1.y      
         z: DOT4        ____,  R0.z,  R1.z      
         w: DOT4        ____,  (0x80000000, -0.0f).x,  0.0f      
         t: ADD         R126.y, -C0.x,  1.0f      
      1  x: MUL         ____,  PV0.x,  PV0.x      
         y: ADD         R125.y, -C0.y,  1.0f      
         w: ADD         R127.w, -C0.z,  1.0f      
         t: MOV         R0.w,  0.0f      
      2  w: MUL         ____,  PV1.x,  PV1.x      
      3  z: MUL         ____,  R127.y,  PV2.w      
      4  x: MULADD      R0.x,  R126.y,  PV3.z,  C0.x      
         y: MULADD      R0.y,  R125.y,  PV3.z,  C0.y      VEC_120 
         z: MULADD      R0.z,  R127.w,  PV3.z,  C0.z      
01 EXP_DONE: PIX0, R0
END_OF_PROGRAM