summaryrefslogtreecommitdiff
path: root/shaders/tesseract/287.shader_test
blob: 46164cab2a505e76b8e7ed86faf7a6e46f673e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
[require]
GLSL >= 1.10

[vertex shader]
#version 120
#extension GL_ARB_texture_rectangle : enable
#define flat
#define texture2DRectOffset(sampler, coords, offset) texture2DRect(sampler, coords + vec2(offset))
#define shadow2DRectOffset(sampler, coords, offset) shadow2DRect(sampler, coords + vec2(offset))
attribute vec4 vvertex, vtangent;
        attribute vec2 vtexcoord0;
        
        attribute vec4 vboneweight, vboneindex; 
        #pragma CUBE2_uniform animdata
        uniform vec4 animdata[192];
    
        uniform mat4 modelmatrix;
        uniform mat3 modelworld;
        uniform vec3 modelcamera;
        uniform vec2 texscroll;
        
            varying mat3 world;
        
        
            varying vec3 camvec;
        
        
        varying vec2 texcoord0;

        void main(void)
        {
            
        int index = int(vboneindex.x);
        
            vec4 dqreal = animdata[index] * vboneweight.x;
            vec4 dqdual = animdata[index+1] * vboneweight.x;
            index = int(vboneindex.y);
            dqreal += animdata[index] * vboneweight.y;
            dqdual += animdata[index+1] * vboneweight.y;
            
            
            float len = length(dqreal);
            dqreal /= len;
            dqdual /= len;
        

        vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.0 + vvertex.xyz, vvertex.w);

        
            vec4 mquat = vec4(cross(dqreal.xyz, vtangent.xyz) + dqreal.xyz*vtangent.w + vtangent.xyz*dqreal.w, dqreal.w*vtangent.w - dot(dqreal.xyz, vtangent.xyz));
            
        vec4 qxyz = mquat.xxyy*mquat.yzyz, qxzw = vec4(mquat.xzw, -mquat.w);
        vec3 mtangent = (qxzw.yzw*mquat.zzy + qxyz.zxy)*vec3(-2.0, 2.0, 2.0) + vec3(1.0, 0.0, 0.0);
        vec3 mnormal = (qxzw.zwx*mquat.yxx + qxyz.ywz)*vec3(2.0, 2.0, -2.0) + vec3(0.0, 0.0, 1.0);
        
        
    
        
    

            gl_Position = modelmatrix * mpos;

            texcoord0 = vtexcoord0 + texscroll;

            

            
                camvec = modelworld * normalize(modelcamera - mpos.xyz);
            

            
                
                
                vec3 wnormal = modelworld * mnormal;
                vec3 wtangent = modelworld * mtangent;
                vec3 wbitangent = cross(wnormal, wtangent) * (vtangent.w < 0.0 ? -1.0 : 1.0);
                world = mat3(wtangent, wbitangent, wnormal);
            
        }
    
[fragment shader]
#version 120
#extension GL_ARB_texture_rectangle : enable
#define flat
#define texture2DRectOffset(sampler, coords, offset) texture2DRect(sampler, coords + vec2(offset))
#define shadow2DRectOffset(sampler, coords, offset) shadow2DRect(sampler, coords + vec2(offset))
#define fragdata(loc, name, type)
#define gcolor gl_FragData[0]
#define gnormal gl_FragData[1]
#define gglow gl_FragData[2]
varying mat3 world; 
        
        
            uniform vec2 envmapscale;
            varying vec3 camvec;
        
        uniform vec4 colorscale;
        uniform vec2 fullbright;
        uniform vec2 maskscale;
        
        uniform sampler2D tex0;
        uniform sampler2D tex1;
        uniform samplerCube tex2;
        uniform sampler2D tex3;
        
        
        fragdata(0, gcolor, vec4)
        fragdata(1, gnormal, vec4)
        fragdata(2, gglow, vec4)
        
        
    
        varying vec2 texcoord0;
        uniform float aamask;

        void main(void)
        {
            vec4 diffuse = texture2D(tex0, texcoord0);

            

            gcolor.rgb = diffuse.rgb*colorscale.rgb;

            

            
                vec3 normal = texture2D(tex3, texcoord0).rgb - 0.5;
                
                normal = normalize(world * normal);
            

            float spec = maskscale.x;
            
                vec3 masks = texture2D(tex1, texcoord0).rgb;
                spec *= masks.r; 

                
                    vec3 camn = normalize(camvec);
                    float invfresnel = dot(camn, normal);
                    vec3 rvec = 2.0*invfresnel*normal - camn;
                    float rmod = envmapscale.x*clamp(invfresnel, 0.0, 1.0) + envmapscale.y;
                    vec3 reflect = textureCube(tex2, rvec).rgb;
                    gcolor.rgb = mix(gcolor.rgb, reflect, rmod*masks.b); 
                
            
            gcolor.a = 0.5*spec;

            
                float glowk = max(maskscale.y*masks.g, fullbright.y), colork = max(fullbright.x-glowk, 0.0); 
            

            
                gglow.rgb = gcolor.rgb*glowk;
                gcolor.rgb *= colork;
                #define packnorm colorscale.a
            

            
        gnormal.rgb = normal*0.5 + 0.5;
        #ifdef packnorm
            gnormal.a = (packnorm);
        #else
            gnormal.a = 1.0;
        #endif
    

            
        
        
    
        }