Created
September 19, 2019 19:00
-
-
Save mazelines/d2deecf29e21cc59fcfa3b03047c86dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vertex shader. | |
| //code start | |
| //Spherical harmonic shader opengl es | |
| //Sh.vsh | |
| attribute vec4 Position; | |
| attribute vec3 Normal; | |
| attribute vec3 DiffuseMaterial; | |
| varying vec3 EyespaceNormal; | |
| varying vec3 EyespaceLight; | |
| varying vec4 VertexPosition; | |
| varying vec3 Diffuse; | |
| varying vec3 Irrad; | |
| uniform vec3 LightPosition; | |
| uniform mat4 Projection; | |
| uniform mat4 Modelview; | |
| uniform mat3 NormalMatrix; | |
| const vec3 L_00 = vec3( 0.79, 0.44, 0.54); | |
| const vec3 L_1_1 = vec3( 0.39, 0.35, 0.60); | |
| const vec3 L_10 = vec3(-0.34, -0.18, -0.27); | |
| const vec3 L_11 = vec3(-0.29, -0.06, 0.01); | |
| const vec3 L_2_2 = vec3(-0.11, -0.05, -0.12); | |
| const vec3 L_2_1 = vec3(-0.26, -0.22, -0.45); | |
| const vec3 L_20 = vec3(-0.16, -0.09, -0.15); | |
| const vec3 L_21 = vec3( 0.56, 0.21, 0.14); | |
| const vec3 L_22 = vec3( 0.21, -0.05, -0.30); | |
| vec3 irradcoeffs(vec3 L00, vec3 L1_1, vec3 L10, vec3 L11, vec3 L2_2, vec3 L2_1, vec3 L20, vec3 L21, vec3 L22, vec3 n) | |
| { | |
| float x2, y2, z2; | |
| float xy, yz, xz; | |
| float x, y, z; | |
| const float c1 = 0.429043; | |
| const float c2 = 0.511664; | |
| const float c3 = 0.743125; | |
| const float c4 = 0.886227; | |
| const float c5 = 0.247708; | |
| x = n.x; y = n.y; z = n.z; | |
| x2 = x*x ; y2 = y*y ; z2 = z*z ; | |
| xy = x*y ; yz = y*z ; xz = x*z ; | |
| return c1*L22*(x2-y2) + c3*L20*z2 + c4*L00 - c5*L20 | |
| + 2.0*c1*(L2_2*xy + L21*xz + L2_1*yz) | |
| + 2.0*c2*(L11*x+L1_1*y+L10*z); | |
| } | |
| void main(void) | |
| { | |
| EyespaceNormal = NormalMatrix * Normal; | |
| Irrad = irradcoeffs(L_00, L_1_1, L_10, L_11, L_2_2, L_2_1, L_20, L_21, L_22, normalize(Normal)); | |
| Diffuse = DiffuseMaterial; | |
| gl_Position = Projection * Modelview * Position; | |
| EyespaceLight = normalize(LightPosition - vec3(gl_Position)); | |
| } | |
| //code end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment