# Ashikhmin-Shirley model implementation: ugly result

I am trying to implement the Ashikhmin-Shirley model using these formulas: This is the GLSL 1.2 fragment shader code:

uniform vec4 materialAmbient, materialDiffuse, materialSpecular;
uniform float materialShininess;
uniform vec4 lightAmbient, lightDiffuse, lightSpecular, lightPosition;

varying vec3 P,N;

float pi= 3.1415926535;

vec4 Fd(float NdotV, float NdotL) {
vec4 fd= (28.0 * materialDiffuse * lightDiffuse) / (23.0 * pi) * (1.0 - materialSpecular * lightSpecular);
fd*= 1.0 - pow(1.0-NdotV/2.0,5.0);
fd*= 1.0 - pow(1.0-NdotL/2.0, 5.0);
return fd;
}

vec4 Fr(float u, vec4 specular) {
return specular + (1.0-specular) * pow(1.0 - u, 5.0);
}

// f= phi
vec4 Fs(float VdotH, float NdotH, float NdotL, float NdotV, float et, float eb, float f) {
vec4 fs= Fr(VdotH, materialSpecular * lightSpecular);
fs*= sqrt((et+1.0) * (eb+1.0)) / (8.0 * pi);
fs*=  pow(NdotH, et*pow(cos(f),2.0) + eb*pow(sin(f),2.0)) / (VdotH * max(NdotL, NdotV));
return fs;
}

void main(void) {
vec3 L= normalize(vec3(lightPosition) - P);
vec3 V= cameraPosition;
vec3 H= normalize(L+V);
float NdotL= max(dot(N,L),0.0);
float NdotV= max(dot(N,V),0.0);
float NdotH= max(dot(N,H),0.0);
float VdotH= max(dot(V,H),0.0);
gl_FragColor= Fd(NdotV, NdotL) + Fs(VdotH, NdotH, NdotL, NdotV, 128.0,128.0,1.0);
}


I already checked and it seems like all the uniforms and varying are passed in the right way, I pass P and N from the vertex shader. The variables are:

1. Light direction: L;
2. Surface normal: N;
3. Camera direction: V;
4. Half vector: H;
5. Fragment position: P.

The uniforms I pass are:

1. light{Specular | Diffuse | Ambient} : 0xffffff (converted to a rgba vector of course);
2. materialAmbient: 0x543807 ;
3. materialDiffuse: 0xc6901d;
4. materialSpecular: 0xfdefce;
5. materialShininess: 27.8974.

This is the result I get: Which seems very strange to me, I've seen other images of Ashkhmin-Shirley implementations on the web, and they aren't similar. This is an example: I want one like this !! Maybe I am using wrong values of phi and other values? Or there's something wrong in the formula?

• can you provide a simpler shape in your test image, like a sphere or teapot? as it's hard to judge from this. – concept3d Nov 25 '13 at 14:23
• sorry I'm feeling too lazy to look your code over, but here is my tested implementation in use in my engine: szifler.com/gdsegj/ashikhmin_shirley.glsl – MickLH Nov 25 '13 at 14:41
• @concept3d Ok, I replaced the image, there's a teapot now. – Ramy Al Zuhouri Nov 25 '13 at 14:43
• it gives you vec2(diffuse, specular), multiply by your diffuse texture sample and light color... add the specular before or after depending on if your renderer supports separate specular color – MickLH Nov 25 '13 at 14:48
• also it looks like you are using "flat" normals instead of "smooth" ones, you most likely want to research normal smoothing and pre-calculate this in your models vertices to get rid of the square artifacts no matter what lighting model you use – MickLH Nov 25 '13 at 14:50

vec4 Fr(float u, vec4 specular) {
return specular + (1.0-specular) * pow(1.0 - u, 5.0);
}


what's the specular in this function ? I think you specular is wrong,you can change

float Fr(float u) {
float f = 0.125;
float fresnelCoe = f + (1 - f)*pow(1 - u, 5);
}


f is a constant, different object has difference number
{"ft_lang_label":"__label__en","ft_lang_prob":0.55382895,"math_prob":0.97737175,"size":2057,"snap":"2019-43-2019-47","text_gpt3_token_len":702,"char_repetition_ratio":0.14417925,"word_repetition_ratio":0.0,"special_character_ratio":0.33543995,"punctuation_ratio":0.2611465,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96254975,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,4,null,4,null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-14T06:28:56Z\",\"WARC-Record-ID\":\"<urn:uuid:d68cc2e4-3aa4-49a9-833a-ced0769caa39>\",\"Content-Length\":\"145469\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4eecbd92-ea23-48d4-a181-111d7f44e236>\",\"WARC-Concurrent-To\":\"<urn:uuid:38f2accb-d8a9-4fff-ba0c-19dd65769d53>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://gamedev.stackexchange.com/questions/66341/ashikhmin-shirley-model-implementation-ugly-result\",\"WARC-Payload-Digest\":\"sha1:734NQAWV23RSD4GTZKZRPTGZUISAWYYM\",\"WARC-Block-Digest\":\"sha1:6QG5Z5NNJB3UKNJWAROQAXWSFALG4DMT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496668004.65_warc_CC-MAIN-20191114053752-20191114081752-00391.warc.gz\"}"}