Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbr sample has runtime error #212

Closed
markknol opened this issue Jan 19, 2017 · 2 comments
Closed

pbr sample has runtime error #212

markknol opened this issue Jan 19, 2017 · 2 comments

Comments

@markknol
Copy link
Collaborator

In webGL:

ERROR: 0:45: 'fragmentParams' :  left of '[' is not of type array, matrix, or vector  
ERROR: 0:45: 'xy' :  field selection requires structure or vector on left hand side 
ERROR: 0:45: 'return' : function return is not matching type: 
(return fragmentParams[int(i2)].xy;)

1    #version 100
2    precision mediump float;
3    varying vec2 uv_2;
4    
5    float roughness;
6    float NoV;
7    vec3 v;
8    vec3 n;
9    int numSamples;
10    float a;
11    float b;
12    int i;
13    vec2 xi;
14    int i2;
15    vec3 h;
16    float roughness2;
17    vec2 p;
18    vec3 n2;
19    float a2;
20    float phi;
21    float cosT;
22    float sinT;
23    vec3 ltan;
24    vec3 up;
25    vec3 tanX;
26    vec3 tanY;
27    vec3 l;
28    float NoL;
29    float NoH;
30    float VoH;
31    float g;
32    float roughness3;
33    float nDotV;
34    float nDotL;
35    float NdotV;
36    float roughness4;
37    float k;
38    float NdotV2;
39    float roughness5;
40    float gvis;
41    float fresnel;
42    
43    vec2 val0(void){
44        i2 = i;
45        return fragmentParams[int(i2)].xy;
46    }
47    
48    vec3 val1(void){
49        roughness2 = roughness;
50        p = xi;
51        n2 = n;
52        a2 = roughness2 * roughness2;
53        phi = 6.283185307179586 * p.x;
54        cosT = min(sqrt((1. - p.y) / (1. + (a2 * a2 - 1.) * p.y)), 1.);
55        sinT = sqrt(1. - cosT * cosT);
56        ltan = vec3(sinT * cos(phi), sinT * sin(phi), cosT);
57        up = ( abs(n2.z) < 0.999 ) ? vec3(0., 0., 1.) : vec3(1., 0., 0.);
58        tanX = normalize(cross(up, n2));
59        tanY = normalize(cross(n2, tanX));
60        return tanX * ltan.x + tanY * ltan.y + n2 * ltan.z;
61    }
62    
63    float val3(void){
64        NdotV = nDotL;
65        roughness4 = roughness3;
66        k = (roughness4 * roughness4) * 0.5;
67        return NdotV / (NdotV * (1. - k) + k);
68    }
69    
70    float val4(void){
71        NdotV2 = nDotV;
72        roughness5 = roughness3;
73        k = (roughness5 * roughness5) * 0.5;
74        return NdotV2 / (NdotV2 * (1. - k) + k);
75    }
76    
77    float val2(void){
78        roughness3 = roughness;
79        nDotV = NoV;
80        nDotL = NoL;
81        return val3() * val4();
82    }
83    
84    void main(void) {
85        roughness = uv_2.x;
86        NoV = uv_2.y;
87        v = vec3(sqrt(1. - NoV * NoV), 0., NoV);
88        n = vec3(0., 0., 1.);
89        numSamples = 1024;
90        a = 0.;
91        b = 0.;
92        for(i=0;i<numSamples;i++) {
93            xi = val0();
94            h = val1();
95            l = reflect(-v, h);
96            NoL = clamp(dot(n, l), 0., 1.);
97            NoH = clamp(dot(n, h), 0., 1.);
98            VoH = clamp(dot(v, h), 0., 1.);
99            if( NoL > 0.) {
100                g = val2();
101                gvis = g * VoH / (NoH * NoV);
102                fresnel = pow(1. - VoH, 5.);
103                a += (1. - fresnel) * gvis;
104                b += fresnel * gvis;
105            };
106        }
107        gl_FragColor = vec4(a / float(numSamples), b / float(numSamples), 0., 1.);
108    }
109    
110    
    at h3d_impl_GlDriver.compileShader ```
@ncannasse
Copy link
Member

PBR will most likely require WebGL 2.0 support (maybe can be done with 1.0 extensions, not sure)

@ncannasse
Copy link
Member

Now supports WebGL2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants