RSS

(root)/iphone/common : 61 : MarineCompass/source/fresnel.fs

To get this branch, use:
bzr branch /browse/iphone/common

« back to all changes in this revision

Viewing changes to MarineCompass/source/fresnel.fs

Dömötör Gulyás
2010-01-18 09:03:51
Revision ID: dognotdog@gmail.com-20100118080351-ib2knxvk4w8ssw3h
made common a nested tree

Show diffs side-by-side

added added

removed removed

1
 
/*
2
 
 *  fresnel.fs
3
 
 *  MarineCompass
4
 
 *
5
 
 *  Created by döme on 29.07.2009.
6
 
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
7
 
 *
8
 
 */
9
 
 
10
 
precision mediump float;
11
 
 
12
 
uniform sampler2D tex0;
13
 
 
14
 
varying mediump vec3 N;
15
 
varying mediump vec2 tx0;
16
 
varying mediump vec4 epos;
17
 
 
18
 
void main()
19
 
{
20
 
        vec3 NN = normalize(N)*(float(gl_FrontFacing)*2.0 - 1.0);
21
 
        vec3 lightdir = normalize(epos.xyz);
22
 
 
23
 
        lowp vec4 tex0color = texture2D(tex0, tx0);
24
 
        
25
 
        float diffuse = -dot(NN, lightdir);
26
 
        
27
 
        const float n1 = 1.0;
28
 
        const float n2 = 1.4;
29
 
        const float n12 = n1/n2;
30
 
 
31
 
        float cost0 = diffuse;
32
 
        float cost1 = sqrt(1.0 - n12*n12*(1.0 - cost0*cost0));
33
 
        
34
 
        float Rs = (n1*cost0 - n2*cost1)/(n1*cost0 + n2*cost1);
35
 
        float Rp = (n1*cost1 - n2*cost0)/(n1*cost1 + n2*cost0);
36
 
        float R = 0.5*(Rs*Rs+Rp*Rp);
37
 
 
38
 
 
39
 
        gl_FragColor = vec4(tex0color.rgb*(R+0.0*diffuse), R);
40
 
}

Loggerhead 1.17 is a web-based interface for Bazaar branches