Demo entry 6787563

HLSL shader

   

Submitted by anonymous on Apr 13, 2019 at 18:58
Language: HLSL. Code size: 2.2 kB.

      
      float3 DisneyBRDF(float3 L, float3 V, float3 X, float3 Y, float3 N){


            float NdotH = dot(normal, halfvec);
            float LdotH = dot(light, halfvec);
            float NdotL = dot(normal, light);
            float NdotV = dot(normal, view);
            float HdotX = dot(halfvec, tangent);
            float HdotY = dot(halfvec, bitangent);
            float LdotX = dot(light, tangent);
            float LdotY = dot(light, bitangent);
            float VdotX = dot(view, tangent);
            float VdotY = dot(view, bitangent);



            // BRDF Parameters:
            // basecolor		[0,1]^3
            // metallic			[0,1]	
            // specular			[0,1]
            // roughness		[0,1]
            // anisotropic		[0,1]

            // Geometry Parameters:
            // normal			[0,1]^3
            // tangent			[0,1]^3


            // Diffuse part
            float Fd90 = 0.5 + 2*LdotH*LdotH*roughness;
            float FL = SchlickFresnel(NdotL), FV = SchlickFresnel(NdotV);
            float3 fDiff = lerp(1, Fd90, FL)* lerp(1, Fd90, FV) * (1-metallic) * basecolor / PI;

            // Specular part
            float3 colSpec = 0.08 * specular * (1-metallic) * lerp(float3(1, 1, 1), basecolor, speculartint) + basecolor * metallic;
            float aspect = sqrt(1-0.9*anisotropic);
            float roughness2 = roughness*roughness;
            float alpha_x = max(0.001, roughness2 / aspect);
            float alpha_y = max(0.001, roughness2*aspect);
            float Ds = 1 / (PI * alpha_x * alpha_y * sqr( sqr(HdotX/ alpha_x) + sqr(HdotY/alpha_y) + sqr(NdotH) ));  // Anisotropic GTR2
            float FH = SchlickFresnel(LdotH);
            float3 Fs = lerp(colSpec, float3(1, 1, 1), FH);
            float Gs = 1/( (NdotL + sqrt(sqr(LdotX*alpha_x)+sqr(LdotY*alpha_y)+sqr(NdotL))) * (NdotV + sqrt(sqr(VdotX*alpha_x)+sqr(VdotY*alpha_y)+sqr(NdotV))) ); // GGX
            float3 fSpec = Ds*Fs*Gs;

            float3 f = fDiff + fSpec;

            // return float4(uv, 0,1);
            float ambient = 2.0;
            return float4(f* (_I * NdotL / light_dist2 + ambient), 1.0);
      }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).