Code Demo

shader.c
uniform float		uRoughness;//粗糙度
uniform float		uMetallic;//金属
uniform float		uSpecular;//高光
 
uniform sampler2D uRadianceMap;
uniform sampler2D uIrradianceMap;
 
#define PI 		3.14159265359
#define invPI 	0.3183098861837697
#define invTWO_PI 	0.15915494309
#define saturate(x) clamp(x, 0.0, 1.0)
 
vec3 Diffuse_Lambert( vec3 DiffuseColor )
{
	return DiffuseColor * (1.0 / PI);
    //return vec3(0,0,0);
}
 
float D_GGX( float Roughness, float NoH )
{
	float m = Roughness * Roughness;
	float m2 = m * m;
	float d = ( NoH * m2 - NoH ) * NoH + 1.0;	// 2 mad
	return m2 / ( PI*d*d );					// 4 mul, 1 rcp
}
 
float Vis_Smith( float Roughness, float NoV, float NoL )
{
	float a = Roughness * Roughness ;
	float a2 = a*a;
 
	float Vis_SmithV = NoV + sqrt( NoV * (NoV - NoV * a2) + a2 );
	float Vis_SmithL = NoL + sqrt( NoL * (NoL - NoL * a2) + a2 );
	return 1.0 / ( Vis_SmithV * Vis_SmithL );
}
 
vec3 F_Schlick( vec3 SpecularColor, float VoH )
{
	float Fc = pow( 1.0 - VoH, 5.0 );
	return Fc + (1.0 - Fc) * SpecularColor;
	//return saturate( 50.0 * SpecularColor.y ) * Fc + (1.0 - Fc) * SpecularColor;
}

Fun Demo

$$ \int_{a}^{b}F(x)G(x) = x^2 $$ $$ \frac{d}{dx}\left( \int_{0}^{x} f(u)\,du\right)=f(x) $$ $$ 1+2+\dots+n=\frac{n(n+1)}{2} $$ \[ \sin A \cos B = \frac{1}{2}\left[ \sin(A-B)+\sin(A+B) \right] \] \begin{align*} e^x & = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \cdots \\ & = \sum_{n\geq 0} \frac{x^n}{n!} \end{align*}