Thursday, May 18, 2017

glsl - Ward model implementation: specular component too weak


I'm trying to implement the Ward shading model, the anisotropic, computationally efficient version:


enter image description here enter image description here


This is how I made it:


float alphaX=0.5, alphaY=0.5; // asinotropic roughness
float minFloat= 1.e-6;

vec4 Ward(vec3 L, vec3 N, vec3 V)
{

vec3 H= normalize(L+V);
float NdotL= max(dot(N,L),0.0);
float NdotV= max(dot(N,V),0.0);

vec3 e= vec3(1.0,0.0,0.0);
vec3 T= normalize(cross(N,e));
vec3 B= normalize(cross(N,T));
float HdotT= max(dot(H,T),0.0);
float HdotB= max(dot(H,B),0.0);
float HdotN= max(dot(H,N),0.0);


float beta= -2.0 * ( pow(HdotN/alphaX, 2.0) + pow(HdotB/alphaY,2.0) ) / (1.0 + HdotN);
float den= max(minFloat, 4.0 * pi * alphaX * alphaY * sqrt(NdotL * NdotV) );
vec4 specular= Ps * 1.0/den * exp(beta);
return (Pd + specular) * NdotL;
}

But I get a result similar to a lambertian surface or Oren-Nayar model, where the specular component is absent:


enter image description here


enter image description here




Answer



The problem was solved by just changing the e vector to (0,0,-1). I also needed to clamp the returned color:


return clamp((Pd + specular) * NdotL, 0.0, 1.0);

Result:


enter image description here


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...