Guest User

mdlopt sourcecode

a guest
Sep 19th, 2011
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1031    modelvertexshader = [
  2.     1032        modeltype = $arg1
  3.     1033        result [
  4.     1034            @(if (|| (mdlopt "b") (mdlopt "B")) [skelanimdefs $arg2 1 (mdlopt "n")])
  5.     1035            #pragma CUBE2_fog opos
  6.     1036            @(if (mdlopt "n") [result [
  7.     1037                #pragma CUBE2_attrib vtangent 1
  8.     1038                attribute vec4 vtangent;
  9.     1039            ]])
  10.     1040            uniform vec4 camera, lightdir, lightscale, texscroll;
  11.     1041            @(if (mdlopt "n") [result [
  12.     1042                @(if (mdlopt "e") [result [
  13.     1043                    varying vec3 camvec;
  14.     1044                    varying mat3 world;
  15.     1045                ]] [result [
  16.     1046                    varying vec3 lightvec, halfangle;
  17.     1047                ]])
  18.     1048            ]] [result [
  19.     1049                @(if (mdlopt "s") [result [
  20.     1050                    varying vec3 nvec, halfangle;
  21.     1051                ]])
  22.     1052                @(if (mdlopt "e") [result [
  23.     1053                    uniform vec4 envmapscale;
  24.     1054                    varying vec3 rvec;
  25.     1055                    varying float rmod;
  26.     1056                ]])
  27.     1057            ]])
  28.     1058            void main(void)
  29.     1059            {
  30.     1060                @(if (mdlopt "B") [skelmatanim $arg2 1 (mdlopt "n")])
  31.     1061                @(if (mdlopt "b") [skelquatanim $arg2 1 (mdlopt "n")])
  32.     1062                @(if (|| (mdlopt "b") (mdlopt "B")) [result [
  33.     1063                    gl_Position = gl_ModelViewProjectionMatrix * opos;
  34.     1064                ]] [result [
  35.     1065                    gl_Position = ftransform();
  36.     1066                    #define opos gl_Vertex
  37.     1067                    #define onormal gl_Normal
  38.     1068                    #define otangent vtangent.xyz
  39.     1069                ]])
  40.     1070   
  41.     1071                @(if (|| (mdlopt "n") (mdlopt "s") (mdlopt "i")) [result [
  42.     1072                    gl_FrontColor = gl_Color;
  43.     1073                ]])
  44.     1074                gl_TexCoord[0].xy = gl_MultiTexCoord0.xy + texscroll.yz;
  45.     1075   
  46.     1076                @(if (|| (mdlopt "e") (mdlopt "s")) [result [
  47.     1077                    vec3 camdir = normalize(camera.xyz - opos.xyz);
  48.     1078                ]])
  49.     1079   
  50.     1080                @(if (mdlopt "n") [
  51.     1081                    if (mdlopt "e") [result [
  52.     1082                        camvec = mat3(gl_TextureMatrix[0][0].xyz, gl_TextureMatrix[0][1].xyz, gl_TextureMatrix[0][2].xyz) * camdir;
  53.     1083                        // composition of tangent -> object and object -> world transforms
  54.     1084                        // becomes tangent -> world
  55.     1085                        vec3 wnormal = mat3(gl_TextureMatrix[0][0].xyz, gl_TextureMatrix[0][1].xyz, gl_TextureMatrix[0][2].xyz) * onormal;
  56.     1086                        vec3 wtangent = mat3(gl_TextureMatrix[0][0].xyz, gl_TextureMatrix[0][1].xyz, gl_TextureMatrix[0][2].xyz) * otangent;
  57.     1087                        world = mat3(wtangent, cross(wnormal, wtangent) * vtangent.w, wnormal);
  58.     1088                    ]] [result [
  59.     1089                        vec3 obitangent = cross(onormal, otangent) * vtangent.w;
  60.     1090                        lightvec = vec3(dot(lightdir.xyz, otangent), dot(lightdir.xyz, obitangent), dot(lightdir.xyz, onormal));
  61.     1091                        @(if (mdlopt "s") [result [
  62.     1092                            vec3 halfdir = lightdir.xyz + camdir;
  63.     1093                            halfangle = vec3(dot(halfdir, otangent), dot(halfdir, obitangent), dot(halfdir, onormal));
  64.     1094                        ]])
  65.     1095                    ]]
  66.     1096                ] [result [
  67.     1097                    @(if (mdlopt "s") [result [
  68.     1098                        nvec = onormal;
  69.     1099                        halfangle = lightdir.xyz + camdir;
  70.     1100                    ]] [if (! (mdlopt "i")) [result [
  71.     1101                        gl_FrontColor = vec4(gl_Color.rgb*max(dot(onormal, lightdir.xyz) + 0.5, lightscale.y), gl_Color.a);
  72.     1102                    ]]])
  73.     1103                    @(if (mdlopt "e") [result [
  74.     1104                        float invfresnel = dot(camdir, onormal);
  75.     1105                        rvec = mat3(gl_TextureMatrix[0][0].xyz, gl_TextureMatrix[0][1].xyz, gl_TextureMatrix[0][2].xyz) * (2.0*invfresnel*onormal - camdir);
  76.     1106                        rmod = envmapscale.x*max(invfresnel, 0.0) + envmapscale.y;
  77.     1107                    ]])
  78.     1108                ]])
  79.     1109            }
  80.     1110        ]
  81.     1111    ]
  82.     1112   
  83.     1113    modelfragmentshader = [
  84.     1114        modeltype = $arg1
  85.     1115        result [
  86.     1116            @(if (|| (mdlopt "b") (mdlopt "B")) [skelanimfragdefs])
  87.     1117            @(if (mdlopt "n") [result [
  88.     1118                @(if (mdlopt "e") [result [
  89.     1119                    #define lightvec lightdirworld.xyz
  90.     1120                    uniform vec4 lightdirworld, envmapscale;
  91.     1121                    varying vec3 camvec;
  92.     1122                    varying mat3 world;
  93.     1123                ]] [result [
  94.     1124                    varying vec3 lightvec, halfangle;
  95.     1125                ]])
  96.     1126            ]] [result [
  97.     1127                @(if (mdlopt "s") [result [
  98.     1128                    #define lightvec lightdir.xyz
  99.     1129                    uniform vec4 lightdir;
  100.     1130                    varying vec3 nvec, halfangle;
  101.     1131                ]])
  102.     1132                @(if (mdlopt "e") [result [
  103.     1133                    varying vec3 rvec;
  104.     1134                    varying float rmod;
  105.     1135                ]])
  106.     1136            ]])
  107.     1137            @(if (|| (mdlopt "s") (mdlopt "m") (&& (mdlopt "n") (! (mdlopt "i")))) [result [uniform vec4 lightscale;]])
  108.     1138            @(if (&& (mdlopt "i") (|| (mdlopt "s") (mdlopt "m"))) [result [uniform vec4 glarescale;]])
  109.     1139            uniform sampler2D tex0;
  110.     1140            @(if (mdlopt "m") [result [uniform sampler2D tex1;]])
  111.     1141            @(if (mdlopt "e") [result [uniform samplerCube tex2;]])
  112.     1142            @(if (mdlopt "n") [result [uniform sampler2D tex3;]])
  113.     1143            void main(void)
  114.     1144            {
  115.     1145                vec4 light = texture2D(tex0, gl_TexCoord[0].xy);
  116.     1146   
  117.     1147                @(if (mdlopt "m") [result [
  118.     1148                    vec3 masks = texture2D(tex1, gl_TexCoord[0].xy).rgb;
  119.     1149                    vec3 glow = light.rgb * lightscale.z;
  120.     1150                ]])
  121.     1151   
  122.     1152                @(if (mdlopt "n") [result [
  123.     1153                    vec3 normal = normalize(texture2D(tex3, gl_TexCoord[0].xy).rgb - 0.5);
  124.     1154                    @(if (mdlopt "e") [result [
  125.     1155                        normal = world * normal;
  126.     1156                    ]])
  127.     1157                ]])
  128.     1158   
  129.     1159                @(if (mdlopt "s") [result [
  130.     1160                    @(if (mdlopt "n") [
  131.     1161                        if (mdlopt "e") [result [
  132.     1162                            vec3 halfangle = lightvec + camvec;
  133.     1163                        ]]
  134.     1164                    ] [result [
  135.     1165                        vec3 normal = normalize(nvec);
  136.     1166                    ]])
  137.     1167                    float spec = lightscale.x * pow(clamp(dot(normalize(halfangle), normal), 0.0, 1.0), @(? (mdlopt "i") "256.0" "128.0"));
  138.     1168                    @(if (mdlopt "m") [result [spec *= masks.r;]]) // specmap in red channel
  139.     1169                ]])
  140.     1170   
  141.     1171                @(if (mdlopt "i") [
  142.     1172                    if (mdlopt "s") [result [
  143.     1173                        spec *= glarescale.x;
  144.     1174                        @(? (mdlopt "m") "light.rgb" "gl_FragColor.rgb") = spec * gl_Color.rgb;
  145.     1175                    ]] [
  146.     1176                        if (! (mdlopt "m")) [result [gl_FragColor.rgb = vec3(0.0);]]
  147.     1177                    ]
  148.     1178                ] [result [
  149.     1179                    @(if (|| (mdlopt "s") (mdlopt "n")) [result [
  150.     1180                        light.rgb *= max(dot(normal, lightvec) + 0.5, lightscale.y);
  151.     1181                    ]])
  152.     1182                    @(if (mdlopt "s") [result [
  153.     1183                        light.rgb += spec;
  154.     1184                    ]])
  155.     1185                    @(if (mdlopt "m") [result [
  156.     1186                        light.rgb *= gl_Color.rgb;
  157.     1187                    ]] [result [
  158.     1188                        gl_FragColor = light * gl_Color;
  159.     1189                    ]])
  160.     1190                ]])
  161.     1191   
  162.     1192                @(if (mdlopt "m") [result [
  163.     1193                    @(if (mdlopt "e") [result [
  164.     1194                        light.rgb = mix(light.rgb, glow, masks.g); // glow mask in green channel
  165.     1195   
  166.     1196                        @(if (mdlopt "n") [result [
  167.     1197                            vec3 camn = normalize(camvec);
  168.     1198                            float invfresnel = dot(camn, normal);
  169.     1199                            vec3 rvec = 2.0*invfresnel*normal - camn;
  170.     1200                            float rmod = envmapscale.x*max(invfresnel, 0.0) + envmapscale.y;
  171.     1201                        ]])
  172.     1202                        vec3 reflect = textureCube(tex2, rvec).rgb;
  173.     1203                        gl_FragColor.rgb = mix(light.rgb, reflect, rmod*masks.b); // envmap mask in blue channel
  174.     1204                    ]] [if (mdlopt "i") [result [
  175.     1205                        float k = min(masks.g*masks.g*glarescale.y, 1.0); // glow mask in green channel
  176.     1206                        gl_FragColor.rgb = @(? (mdlopt "s") "glow*k + light.rgb" "glow*k");
  177.     1207                    ]] [result [
  178.     1208                        gl_FragColor.rgb = mix(light.rgb, glow, masks.g); // glow mask in green channel
  179.     1209                    ]]])
  180.     1210                ]])
  181.     1211   
  182.     1212                @(if (|| (mdlopt "i") (mdlopt "m")) [result [
  183.     1213                    gl_FragColor.a = light.a * gl_Color.a;
  184.     1214                ]])
  185.     1215            }
  186.     1216        ]
  187.     1217    ]
RAW Paste Data