This commit is contained in:
2025-11-28 23:13:44 +05:30
commit a3a8e79709
7360 changed files with 1156074 additions and 0 deletions

138
kaplademo/externals/resources/AABox.cgfx vendored Normal file
View File

@ -0,0 +1,138 @@
//--------------------------------------------------------------------------------------
//
// Implementation of different downsampling methods for supersampled AA
//
// Copyright (c) NVIDIA Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
float2 SSTexelSize;
float blendFactor = 1.0;
sampler2D SSsampler = sampler_state
{
minFilter = Linear;
magFilter = Linear;
};
sampler2D DepthSSsampler = sampler_state
{
minFilter = Linear;
magFilter = Linear;
};
struct v2fConnector {
float4 projCoord : POSITION;
float2 tex : TEXCOORD0;
};
///////////////////////////////////////////////////////////////////////
// Vertex programs
///////////////////////////////////////////////////////////////////////
void vpPassThrough(float4 P : POSITION, float4 tc : TEXCOORD0, out v2fConnector v2f)
{
v2f.tex = tc.xy;
v2f.projCoord = P;
}
struct PixelOut
{
float4 color : COLOR;
float depth : DEPTH;
};
///////////////////////////////////////////////////////////////////////
// Fragment programs
///////////////////////////////////////////////////////////////////////
//
// Simple down samling : just using the fact we are in between 4 texels.
// so the HW will do a bilinear filtering of these 4 samples
//
PixelOut DownSample1( float2 tc : TEXCOORD0 )
{
PixelOut pix;
pix.color = f4tex2D(SSsampler, tc);
pix.depth = f4tex2D(DepthSSsampler, tc).r;
return pix;
}
//
// add 4 fetches around the original filtered one
// each of the 4 additional fetches will also benefit from the HW bilinear filtering
// the offsets are chosen to benefit from various texels in a specific % amout
//
PixelOut DownSample2( float2 tc : TEXCOORD0 )
{
float4 tap0 = f4tex2D(SSsampler, tc);
float4 tap1 = f4tex2D(SSsampler, tc + SSTexelSize * float2( 0.4, 0.9 ));
float4 tap2 = f4tex2D(SSsampler, tc + SSTexelSize * float2( -0.4, -0.9 ));
float4 tap3 = f4tex2D(SSsampler, tc + SSTexelSize * float2( -0.9, 0.4 ));
float4 tap4 = f4tex2D(SSsampler, tc + SSTexelSize * float2( 0.9, -0.4 ));
float4 color = 0.2 * ( tap0 + tap1 + tap2 + tap3 + tap4 );
float tap0d = f4tex2D(DepthSSsampler, tc).r;
float tap1d = f4tex2D(DepthSSsampler, tc + SSTexelSize * float2( 0.4, 0.9 )).r;
float tap2d = f4tex2D(DepthSSsampler, tc + SSTexelSize * float2( -0.4, -0.9 )).r;
float tap3d = f4tex2D(DepthSSsampler, tc + SSTexelSize * float2( -0.9, 0.4 )).r;
float tap4d = f4tex2D(DepthSSsampler, tc + SSTexelSize * float2( 0.9, -0.4 )).r;
float depth = 0.2 * ( tap0d + tap1d + tap2d + tap3d + tap4d );
PixelOut pix;
pix.color = color;
pix.depth = depth;
return pix;
}
//
// same process are the previous one
// but we are using 2 kernels : one 'normal', one bigger (more blurry, then)
// we will lerp from one to the other depending on downsampled alpha from the bigger kernel
// this technique is good to blur 'high frequencies' marked by alpha =0,
// i.e thin primitives, like lines or sharp triangles
//
float4 DownSample3( float2 tc : TEXCOORD0 ) : COLOR
{
float4 color;
float4 tap0 = f4tex2D(SSsampler, tc);
float4 tap1 = f4tex2D(SSsampler, tc + SSTexelSize * float2( 0.4, 0.9 ));
float4 tap2 = f4tex2D(SSsampler, tc + SSTexelSize * float2( -0.4, -0.9 ));
float4 tap3 = f4tex2D(SSsampler, tc + SSTexelSize * float2( -0.9, 0.4 ));
float4 tap4 = f4tex2D(SSsampler, tc + SSTexelSize * float2( 0.9, -0.4 ));
color = 0.2 * ( tap0 + tap1 + tap2 + tap3 + tap4 );
float4 tap11 = f4tex2D(SSsampler, tc + SSTexelSize * float2( 0.9, 1.9 ));
float4 tap21 = f4tex2D(SSsampler, tc + SSTexelSize * float2( -0.9, -1.9 ));
float4 tap31 = f4tex2D(SSsampler, tc + SSTexelSize * float2( -1.9, 0.9 ));
float4 tap41 = f4tex2D(SSsampler, tc + SSTexelSize * float2( 1.9, -0.9 ));
float4 color2 = 0.2 * ( tap0 + tap11 + tap21 + tap31 + tap41 );
float mask = saturate(color2.w * 1);
color = lerp(color2, color, mask);
color.w = mask;
return color;
}
///////////////////////////////////////////////////////////////////////
// Technique
///////////////////////////////////////////////////////////////////////
technique DownSample_Filter1
{
pass drawFinal
{
DepthMask = true;
VertexProgram = compile arbvp1 vpPassThrough();
FragmentProgram = compile arbfp1 DownSample1();
}
}
technique DownSample_Filter2
{
pass drawFinal
{
DepthMask = true;
VertexProgram = compile arbvp1 vpPassThrough();
FragmentProgram = compile arbfp1 DownSample2();
}
}
technique DownSample_Filter3
{
pass drawFinal
{
DepthMask = true;
VertexProgram = compile arbvp1 vpPassThrough();
FragmentProgram = compile arbfp1 DownSample3();
}
}

2236
kaplademo/externals/resources/asteroid.obj vendored Normal file

File diff suppressed because it is too large Load Diff

763
kaplademo/externals/resources/bullet.obj vendored Normal file
View File

@ -0,0 +1,763 @@
# Wavefront OBJ exported by MilkShape 3D
v 0.126627 -0.015394 0.000504
v 0.109628 -0.015394 0.063504
v 0.063128 -0.015394 0.110004
v 0.000127 -0.015394 0.127004
v -0.062872 -0.015394 0.110004
v -0.109373 -0.015394 0.063504
v -0.126373 -0.015394 0.000504
v -0.109373 -0.015394 -0.062496
v -0.062872 -0.015394 -0.108996
v 0.000127 -0.015394 -0.125996
v 0.063128 -0.015394 -0.108996
v 0.109628 -0.015394 -0.062496
v 0.126627 0.004106 0.000504
v 0.109628 0.004106 0.063504
v 0.063128 0.004106 0.110004
v 0.000127 0.004106 0.127004
v -0.062872 0.004106 0.110004
v -0.109373 0.004106 0.063504
v -0.126373 0.004106 0.000504
v -0.109373 0.004106 -0.062496
v -0.062872 0.004106 -0.108996
v 0.000127 0.004106 -0.125996
v 0.063128 0.004106 -0.108996
v 0.109628 0.004106 -0.062496
v 0.131627 0.011606 0.000504
v 0.114127 0.011606 0.066004
v 0.065628 0.011606 0.114504
v 0.000127 0.011606 0.132004
v -0.065373 0.011606 0.114504
v -0.113873 0.011606 0.066004
v -0.131372 0.011606 0.000504
v -0.113873 0.011606 -0.064996
v -0.065373 0.011606 -0.113496
v 0.000127 0.011606 -0.130996
v 0.065628 0.011606 -0.113496
v 0.114127 0.011606 -0.064996
v 0.128128 0.172606 0.000504
v 0.110627 0.172606 0.064504
v 0.064127 0.172606 0.111004
v 0.000127 0.172606 0.128504
v -0.063873 0.172606 0.111004
v -0.110372 0.172606 0.064504
v -0.127872 0.172606 0.000504
v -0.110372 0.172606 -0.063496
v -0.063873 0.172606 -0.109996
v 0.000127 0.172606 -0.127496
v 0.064127 0.172606 -0.109996
v 0.110627 0.172606 -0.063496
v 0.116627 0.333606 0.000504
v 0.101128 0.333606 0.058504
v 0.058127 0.333606 0.101504
v 0.000127 0.333606 0.117004
v -0.057873 0.333606 0.101504
v -0.100872 0.333606 0.058504
v -0.116373 0.333606 0.000504
v -0.100872 0.333606 -0.057496
v -0.057873 0.333606 -0.100496
v 0.000127 0.333606 -0.115996
v 0.058127 0.333606 -0.100496
v 0.101128 0.333606 -0.057496
v 0.094127 0.494606 0.000504
v 0.081628 0.494606 0.047504
v 0.047128 0.494606 0.082004
v 0.000127 0.494606 0.094504
v -0.046872 0.494606 0.082004
v -0.081373 0.494606 0.047504
v -0.093873 0.494606 0.000504
v -0.081373 0.494606 -0.046496
v -0.046872 0.494606 -0.080996
v 0.000127 0.494606 -0.093496
v 0.047128 0.494606 -0.080996
v 0.081628 0.494606 -0.046496
v 0.067127 0.655606 0.000504
v 0.058127 0.655606 0.034004
v 0.033628 0.655606 0.058504
v 0.000127 0.655606 0.067504
v -0.033373 0.655606 0.058504
v -0.057873 0.655606 0.034004
v -0.066873 0.655606 0.000504
v -0.057873 0.655606 -0.032996
v -0.033373 0.655606 -0.057496
v 0.000127 0.655606 -0.066496
v 0.033628 0.655606 -0.057496
v 0.058127 0.655606 -0.032996
v 0.035627 0.816606 0.000504
v 0.031127 0.816606 0.018504
v 0.018127 0.816606 0.031504
v 0.000127 0.816606 0.036004
v -0.017873 0.816606 0.031504
v -0.030873 0.816606 0.018504
v -0.035373 0.816606 0.000504
v -0.030873 0.816606 -0.017496
v -0.017873 0.816606 -0.030496
v 0.000127 0.816606 -0.034996
v 0.018127 0.816606 -0.030496
v 0.031127 0.816606 -0.017496
v 0.026627 0.828606 0.000504
v 0.023127 0.828606 0.013504
v 0.013127 0.828606 0.023504
v 0.000127 0.828606 0.027004
v -0.012873 0.828606 0.023504
v -0.022873 0.828606 0.013504
v -0.026373 0.828606 0.000504
v -0.022873 0.828606 -0.012496
v -0.012873 0.828606 -0.022496
v 0.000127 0.828606 -0.025996
v 0.013127 0.828606 -0.022496
v 0.023127 0.828606 -0.012496
v 0.010627 0.836606 0.000504
v 0.009127 0.836606 0.006004
v 0.005627 0.836606 0.009504
v 0.000127 0.836606 0.011004
v -0.005373 0.836606 0.009504
v -0.008872 0.836606 0.006004
v -0.010372 0.836606 0.000504
v -0.008872 0.836606 -0.004996
v -0.005373 0.836606 -0.008496
v 0.000127 0.836606 -0.009996
v 0.005627 0.836606 -0.008496
v 0.009127 0.836606 -0.004996
v 0.000127 0.836606 0.000504
v 0.000127 0.836606 0.006004
v 0.000127 0.836606 -0.008496
v 0.000127 0.836606 -0.004996
v 0.000127 0.836606 0.009504
v -0.065373 -0.022894 0.114504
v 0.000127 -0.022894 0.132004
v 0.065628 -0.022894 0.114504
v 0.114127 -0.022894 0.066004
v 0.131627 -0.022894 0.000504
v 0.114127 -0.022894 -0.064996
v 0.065628 -0.022894 -0.113496
v 0.000127 -0.022894 -0.130996
v -0.065373 -0.022894 -0.113496
v -0.113873 -0.022894 -0.064996
v -0.131372 -0.022894 0.000504
v -0.113873 -0.022894 0.066004
v -0.062872 -0.182894 0.110004
v 0.000127 -0.182894 0.127004
v 0.063128 -0.182894 0.110004
v 0.109628 -0.182894 0.063504
v 0.126627 -0.182894 0.000504
v 0.109628 -0.182894 -0.062496
v 0.063128 -0.182894 -0.108996
v 0.000127 -0.182894 -0.125996
v -0.062872 -0.182894 -0.108996
v -0.109373 -0.182894 -0.062496
v -0.126373 -0.182894 0.000504
v -0.109373 -0.182894 0.063504
v -0.059873 -0.277894 0.104504
v 0.000127 -0.277894 0.120504
v 0.060127 -0.277894 0.104504
v 0.104127 -0.277894 0.060504
v 0.120127 -0.277894 0.000504
v 0.104127 -0.277894 -0.059496
v 0.060127 -0.277894 -0.103496
v 0.000127 -0.277894 -0.119496
v -0.059873 -0.277894 -0.103496
v -0.103873 -0.277894 -0.059496
v -0.119872 -0.277894 0.000504
v -0.103873 -0.277894 0.060504
v -0.048372 -0.457894 0.084504
v 0.000127 -0.457894 0.097504
v 0.048627 -0.457894 0.084504
v 0.084127 -0.457894 0.049004
v 0.097127 -0.457894 0.000504
v 0.084127 -0.457894 -0.047996
v 0.048627 -0.457894 -0.083496
v 0.000127 -0.457894 -0.096496
v -0.048372 -0.457894 -0.083496
v -0.083873 -0.457894 -0.047996
v -0.096873 -0.457894 0.000504
v -0.083873 -0.457894 0.049004
v -0.041873 -0.470394 0.073004
v 0.000127 -0.470394 0.084504
v 0.042128 -0.470394 0.073004
v 0.072627 -0.470394 0.042504
v 0.084127 -0.470394 0.000504
v 0.072627 -0.470394 -0.041496
v 0.042128 -0.470394 -0.071996
v 0.000127 -0.470394 -0.083496
v -0.041873 -0.470394 -0.071996
v -0.072373 -0.470394 -0.041496
v -0.083873 -0.470394 0.000504
v -0.072373 -0.470394 0.042504
v 0.000127 -0.470394 0.000504
v 0.000127 -0.470394 0.042504
v 0.000127 -0.470394 0.073004
v 0.000127 -0.470394 -0.071996
v 0.000127 -0.470394 -0.041496
# 190 vertices
vt 0.000000 1.000000
# 1 texture coordinates
vn 0.830163 0.297447 -0.471545
vn 0.823333 -0.295545 -0.484537
vn 0.955802 -0.293896 -0.008215
vn 0.955801 0.293900 0.008215
vn 0.830164 -0.297444 0.471546
vn 0.823332 0.295549 0.484536
vn 0.484537 -0.295548 0.823332
vn 0.471545 0.297448 0.830162
vn -0.000000 -0.193594 0.981082
vn -0.000000 0.390797 0.920477
vn -0.484536 -0.295550 0.823331
vn -0.471544 0.297451 0.830162
vn -0.830162 -0.297448 0.471546
vn -0.823331 0.295551 0.484537
vn -0.955801 -0.293898 -0.008216
vn -0.955800 0.293902 0.008216
vn -0.823332 -0.295548 -0.484537
vn -0.830161 0.297452 -0.471545
vn -0.471545 -0.297448 -0.830163
vn -0.484536 0.295553 -0.823330
vn -0.000000 -0.390792 -0.920479
vn -0.000000 0.193597 -0.981081
vn 0.471546 -0.297445 -0.830163
vn 0.484537 0.295552 -0.823331
vn 0.833165 -0.286523 -0.473013
vn 0.959065 -0.283061 0.008422
vn 0.826404 -0.284623 0.485846
vn 0.473013 -0.286524 0.833164
vn -0.000000 -0.384176 0.923260
vn -0.473012 -0.286527 0.833164
vn -0.826403 -0.284626 0.485846
vn -0.959065 -0.283062 0.008422
vn -0.833164 -0.286527 -0.473012
vn -0.485846 -0.284628 -0.826402
vn -0.000000 -0.178360 -0.983965
vn 0.485847 -0.284626 -0.826402
vn 0.864239 0.046656 -0.500914
vn 0.998915 0.046560 -0.000077
vn 0.864350 0.046361 0.500750
vn 0.500914 0.046656 0.864238
vn -0.000000 0.039090 0.999236
vn -0.500914 0.046656 0.864238
vn -0.864350 0.046362 0.500749
vn -0.998915 0.046561 -0.000076
vn -0.864238 0.046657 -0.500914
vn -0.500750 0.046362 -0.864350
vn -0.000000 0.054029 -0.998539
vn 0.500750 0.046362 -0.864350
vn 0.861447 0.103957 -0.497093
vn 0.994530 0.104438 -0.001459
vn 0.861164 0.103933 0.497589
vn 0.497093 0.103957 0.861447
vn -0.000000 0.092886 0.995677
vn -0.497094 0.103957 0.861447
vn -0.861164 0.103933 0.497589
vn -0.994530 0.104437 -0.001459
vn -0.861447 0.103957 -0.497093
vn -0.497589 0.103933 -0.861164
vn -0.000000 0.115966 -0.993253
vn 0.497589 0.103933 -0.861164
vn 0.856156 0.151747 -0.493933
vn 0.988391 0.151930 0.000038
vn 0.856409 0.152001 0.493416
vn 0.493933 0.151746 0.856156
vn -0.000000 0.147267 0.989097
vn -0.493933 0.151746 0.856156
vn -0.856409 0.152000 0.493416
vn -0.988391 0.151930 0.000039
vn -0.856156 0.151746 -0.493934
vn -0.493417 0.152000 -0.856409
vn -0.000000 0.156590 -0.987664
vn 0.493417 0.152000 -0.856409
vn 0.853321 0.178267 -0.489964
vn 0.983932 0.178524 -0.002637
vn 0.852360 0.177811 0.491798
vn 0.489966 0.178267 0.853320
vn -0.000000 0.174531 0.984652
vn -0.489965 0.178267 0.853320
vn -0.852360 0.177811 0.491798
vn -0.983932 0.178524 -0.002636
vn -0.853320 0.178267 -0.489966
vn -0.491800 0.177811 -0.852359
vn 0.000000 0.182510 -0.983204
vn 0.491799 0.177811 -0.852360
vn 0.786929 0.414037 -0.457510
vn 0.912605 0.408762 -0.008151
vn 0.793599 0.418021 0.442108
vn 0.457512 0.414038 0.786928
vn 0.000001 0.335466 0.942052
vn -0.457512 0.414038 0.786927
vn -0.793599 0.418021 0.442108
vn -0.912604 0.408763 -0.008150
vn -0.786929 0.414037 -0.457512
vn -0.442109 0.418022 -0.793598
vn 0.000001 0.479299 -0.877652
vn 0.442108 0.418022 -0.793599
vn 0.538684 0.775595 -0.329047
vn 0.637027 0.770739 -0.012563
vn 0.558900 0.772092 0.302496
vn 0.329046 0.775594 0.538686
vn 0.000001 0.720369 0.693591
vn -0.329047 0.775594 0.538685
vn -0.558901 0.772092 0.302496
vn -0.637026 0.770740 -0.012564
vn -0.538684 0.775595 -0.329047
vn -0.302497 0.772093 -0.558899
vn 0.000001 0.816671 -0.577104
vn 0.302495 0.772093 -0.558900
vn 0.189358 0.972724 -0.133981
vn 0.228679 0.973286 -0.020494
vn 0.209130 0.972972 0.097928
vn 0.160700 0.960516 0.227122
vn 0.000001 0.952575 0.304303
vn -0.160701 0.960516 0.227120
vn -0.209130 0.972972 0.097927
vn -0.228678 0.973286 -0.020494
vn -0.189360 0.972724 -0.133980
vn -0.097929 0.972972 -0.209130
vn 0.000001 0.973449 -0.228902
vn 0.097929 0.972972 -0.209130
vn 0.000000 1.000000 0.000000
vn -0.834538 0.282304 0.473129
vn -0.486469 0.280396 0.827482
vn -0.000000 0.172427 0.985022
vn 0.486469 0.280394 0.827482
vn 0.834539 0.282300 0.473129
vn 0.960343 0.278712 -0.007840
vn 0.827484 0.280391 -0.486469
vn 0.473130 0.282301 -0.834538
vn -0.000000 0.381406 -0.924408
vn -0.473129 0.282304 -0.834538
vn -0.827483 0.280394 -0.486469
vn -0.960342 0.278713 -0.007840
vn -0.864736 -0.049355 0.499795
vn -0.499753 -0.048748 0.864795
vn -0.000000 -0.055268 0.998472
vn 0.499753 -0.048748 0.864795
vn 0.864737 -0.049355 0.499795
vn 0.998769 -0.049607 0.000148
vn 0.864795 -0.048748 -0.499753
vn 0.499795 -0.049355 -0.864736
vn -0.000000 -0.043945 -0.999034
vn -0.499795 -0.049355 -0.864737
vn -0.864795 -0.048748 -0.499753
vn -0.998769 -0.049608 0.000149
vn -0.862059 -0.096388 0.497557
vn -0.497350 -0.096915 0.862119
vn 0.000000 -0.107417 0.994214
vn 0.497350 -0.096915 0.862119
vn 0.862059 -0.096389 0.497557
vn 0.995258 -0.097267 0.000526
vn 0.862119 -0.096915 -0.497351
vn 0.497557 -0.096389 -0.862059
vn 0.000000 -0.087104 -0.996199
vn -0.497557 -0.096388 -0.862059
vn -0.862120 -0.096916 -0.497350
vn -0.995258 -0.097267 0.000526
vn -0.764118 -0.454627 0.457644
vn -0.433085 -0.455591 0.777736
vn 0.000000 -0.555385 0.831594
vn 0.433085 -0.455591 0.777736
vn 0.764119 -0.454626 0.457643
vn 0.891196 -0.453435 0.012870
vn 0.777736 -0.455591 -0.433086
vn 0.457643 -0.454625 -0.764120
vn 0.000000 -0.344639 -0.938735
vn -0.457643 -0.454625 -0.764120
vn -0.777736 -0.455591 -0.433086
vn -0.891196 -0.453437 0.012869
vn -0.300920 -0.929676 0.212484
vn -0.187024 -0.896646 0.401309
vn 0.000000 -0.871161 0.490997
vn 0.187024 -0.896646 0.401309
vn 0.300920 -0.929676 0.212484
vn 0.368540 -0.929036 0.032700
vn 0.334928 -0.929226 -0.156087
vn 0.212484 -0.929676 -0.300920
vn 0.000000 -0.872898 -0.487902
vn -0.212484 -0.929676 -0.300920
vn -0.334927 -0.929226 -0.156088
vn -0.368539 -0.929037 0.032700
vn 0.000000 -1.000000 0.000000
# 182 normals
g default
s 1
f 12/1/1 24/1/2 13/1/3
f 12/1/1 13/1/3 1/1/4
f 1/1/4 13/1/3 14/1/5
f 1/1/4 14/1/5 2/1/6
f 2/1/6 14/1/5 15/1/7
f 2/1/6 15/1/7 3/1/8
f 3/1/8 15/1/7 16/1/9
f 3/1/8 16/1/9 4/1/10
f 16/1/9 17/1/11 5/1/12
f 16/1/9 5/1/12 4/1/10
f 17/1/11 18/1/13 6/1/14
f 17/1/11 6/1/14 5/1/12
f 18/1/13 19/1/15 7/1/16
f 18/1/13 7/1/16 6/1/14
f 19/1/15 20/1/17 8/1/18
f 19/1/15 8/1/18 7/1/16
f 20/1/17 21/1/19 9/1/20
f 20/1/17 9/1/20 8/1/18
f 21/1/19 22/1/21 10/1/22
f 21/1/19 10/1/22 9/1/20
f 10/1/22 22/1/21 23/1/23
f 10/1/22 23/1/23 11/1/24
f 11/1/24 23/1/23 24/1/2
f 11/1/24 24/1/2 12/1/1
f 24/1/2 36/1/25 25/1/26
f 24/1/2 25/1/26 13/1/3
f 13/1/3 25/1/26 26/1/27
f 13/1/3 26/1/27 14/1/5
f 14/1/5 26/1/27 27/1/28
f 14/1/5 27/1/28 15/1/7
f 15/1/7 27/1/28 28/1/29
f 15/1/7 28/1/29 16/1/9
f 28/1/29 29/1/30 17/1/11
f 28/1/29 17/1/11 16/1/9
f 29/1/30 30/1/31 18/1/13
f 29/1/30 18/1/13 17/1/11
f 30/1/31 31/1/32 19/1/15
f 30/1/31 19/1/15 18/1/13
f 31/1/32 32/1/33 20/1/17
f 31/1/32 20/1/17 19/1/15
f 32/1/33 33/1/34 21/1/19
f 32/1/33 21/1/19 20/1/17
f 33/1/34 34/1/35 22/1/21
f 33/1/34 22/1/21 21/1/19
f 22/1/21 34/1/35 35/1/36
f 22/1/21 35/1/36 23/1/23
f 23/1/23 35/1/36 36/1/25
f 23/1/23 36/1/25 24/1/2
f 36/1/25 48/1/37 37/1/38
f 36/1/25 37/1/38 25/1/26
f 25/1/26 37/1/38 38/1/39
f 25/1/26 38/1/39 26/1/27
f 26/1/27 38/1/39 39/1/40
f 26/1/27 39/1/40 27/1/28
f 27/1/28 39/1/40 40/1/41
f 27/1/28 40/1/41 28/1/29
f 40/1/41 41/1/42 29/1/30
f 40/1/41 29/1/30 28/1/29
f 41/1/42 42/1/43 30/1/31
f 41/1/42 30/1/31 29/1/30
f 42/1/43 43/1/44 31/1/32
f 42/1/43 31/1/32 30/1/31
f 43/1/44 44/1/45 32/1/33
f 43/1/44 32/1/33 31/1/32
f 44/1/45 45/1/46 33/1/34
f 44/1/45 33/1/34 32/1/33
f 45/1/46 46/1/47 34/1/35
f 45/1/46 34/1/35 33/1/34
f 34/1/35 46/1/47 47/1/48
f 34/1/35 47/1/48 35/1/36
f 35/1/36 47/1/48 48/1/37
f 35/1/36 48/1/37 36/1/25
f 48/1/37 60/1/49 49/1/50
f 48/1/37 49/1/50 37/1/38
f 37/1/38 49/1/50 50/1/51
f 37/1/38 50/1/51 38/1/39
f 38/1/39 50/1/51 51/1/52
f 38/1/39 51/1/52 39/1/40
f 39/1/40 51/1/52 52/1/53
f 39/1/40 52/1/53 40/1/41
f 52/1/53 53/1/54 41/1/42
f 52/1/53 41/1/42 40/1/41
f 53/1/54 54/1/55 42/1/43
f 53/1/54 42/1/43 41/1/42
f 54/1/55 55/1/56 43/1/44
f 54/1/55 43/1/44 42/1/43
f 55/1/56 56/1/57 44/1/45
f 55/1/56 44/1/45 43/1/44
f 56/1/57 57/1/58 45/1/46
f 56/1/57 45/1/46 44/1/45
f 57/1/58 58/1/59 46/1/47
f 57/1/58 46/1/47 45/1/46
f 46/1/47 58/1/59 59/1/60
f 46/1/47 59/1/60 47/1/48
f 47/1/48 59/1/60 60/1/49
f 47/1/48 60/1/49 48/1/37
f 60/1/49 72/1/61 61/1/62
f 60/1/49 61/1/62 49/1/50
f 49/1/50 61/1/62 62/1/63
f 49/1/50 62/1/63 50/1/51
f 50/1/51 62/1/63 63/1/64
f 50/1/51 63/1/64 51/1/52
f 51/1/52 63/1/64 64/1/65
f 51/1/52 64/1/65 52/1/53
f 64/1/65 65/1/66 53/1/54
f 64/1/65 53/1/54 52/1/53
f 65/1/66 66/1/67 54/1/55
f 65/1/66 54/1/55 53/1/54
f 66/1/67 67/1/68 55/1/56
f 66/1/67 55/1/56 54/1/55
f 67/1/68 68/1/69 56/1/57
f 67/1/68 56/1/57 55/1/56
f 68/1/69 69/1/70 57/1/58
f 68/1/69 57/1/58 56/1/57
f 69/1/70 70/1/71 58/1/59
f 69/1/70 58/1/59 57/1/58
f 58/1/59 70/1/71 71/1/72
f 58/1/59 71/1/72 59/1/60
f 59/1/60 71/1/72 72/1/61
f 59/1/60 72/1/61 60/1/49
f 72/1/61 84/1/73 73/1/74
f 72/1/61 73/1/74 61/1/62
f 61/1/62 73/1/74 74/1/75
f 61/1/62 74/1/75 62/1/63
f 62/1/63 74/1/75 75/1/76
f 62/1/63 75/1/76 63/1/64
f 63/1/64 75/1/76 76/1/77
f 63/1/64 76/1/77 64/1/65
f 76/1/77 77/1/78 65/1/66
f 76/1/77 65/1/66 64/1/65
f 77/1/78 78/1/79 66/1/67
f 77/1/78 66/1/67 65/1/66
f 78/1/79 79/1/80 67/1/68
f 78/1/79 67/1/68 66/1/67
f 79/1/80 80/1/81 68/1/69
f 79/1/80 68/1/69 67/1/68
f 80/1/81 81/1/82 69/1/70
f 80/1/81 69/1/70 68/1/69
f 81/1/82 82/1/83 70/1/71
f 81/1/82 70/1/71 69/1/70
f 70/1/71 82/1/83 83/1/84
f 70/1/71 83/1/84 71/1/72
f 71/1/72 83/1/84 84/1/73
f 71/1/72 84/1/73 72/1/61
f 84/1/73 96/1/85 85/1/86
f 84/1/73 85/1/86 73/1/74
f 73/1/74 85/1/86 86/1/87
f 73/1/74 86/1/87 74/1/75
f 74/1/75 86/1/87 87/1/88
f 74/1/75 87/1/88 75/1/76
f 75/1/76 87/1/88 88/1/89
f 75/1/76 88/1/89 76/1/77
f 88/1/89 89/1/90 77/1/78
f 88/1/89 77/1/78 76/1/77
f 89/1/90 90/1/91 78/1/79
f 89/1/90 78/1/79 77/1/78
f 90/1/91 91/1/92 79/1/80
f 90/1/91 79/1/80 78/1/79
f 91/1/92 92/1/93 80/1/81
f 91/1/92 80/1/81 79/1/80
f 92/1/93 93/1/94 81/1/82
f 92/1/93 81/1/82 80/1/81
f 93/1/94 94/1/95 82/1/83
f 93/1/94 82/1/83 81/1/82
f 82/1/83 94/1/95 95/1/96
f 82/1/83 95/1/96 83/1/84
f 83/1/84 95/1/96 96/1/85
f 83/1/84 96/1/85 84/1/73
f 96/1/85 108/1/97 97/1/98
f 96/1/85 97/1/98 85/1/86
f 85/1/86 97/1/98 98/1/99
f 85/1/86 98/1/99 86/1/87
f 86/1/87 98/1/99 99/1/100
f 86/1/87 99/1/100 87/1/88
f 87/1/88 99/1/100 100/1/101
f 87/1/88 100/1/101 88/1/89
f 100/1/101 101/1/102 89/1/90
f 100/1/101 89/1/90 88/1/89
f 101/1/102 102/1/103 90/1/91
f 101/1/102 90/1/91 89/1/90
f 102/1/103 103/1/104 91/1/92
f 102/1/103 91/1/92 90/1/91
f 103/1/104 104/1/105 92/1/93
f 103/1/104 92/1/93 91/1/92
f 104/1/105 105/1/106 93/1/94
f 104/1/105 93/1/94 92/1/93
f 105/1/106 106/1/107 94/1/95
f 105/1/106 94/1/95 93/1/94
f 94/1/95 106/1/107 107/1/108
f 94/1/95 107/1/108 95/1/96
f 95/1/96 107/1/108 108/1/97
f 95/1/96 108/1/97 96/1/85
f 108/1/97 120/1/109 109/1/110
f 108/1/97 109/1/110 97/1/98
f 97/1/98 109/1/110 110/1/111
f 97/1/98 110/1/111 98/1/99
f 98/1/99 110/1/111 111/1/112
f 98/1/99 111/1/112 99/1/100
f 99/1/100 111/1/112 112/1/113
f 99/1/100 112/1/113 100/1/101
f 112/1/113 113/1/114 101/1/102
f 112/1/113 101/1/102 100/1/101
f 113/1/114 114/1/115 102/1/103
f 113/1/114 102/1/103 101/1/102
f 114/1/115 115/1/116 103/1/104
f 114/1/115 103/1/104 102/1/103
f 115/1/116 116/1/117 104/1/105
f 115/1/116 104/1/105 103/1/104
f 116/1/117 117/1/118 105/1/106
f 116/1/117 105/1/106 104/1/105
f 117/1/118 118/1/119 106/1/107
f 117/1/118 106/1/107 105/1/106
f 106/1/107 118/1/119 119/1/120
f 106/1/107 119/1/120 107/1/108
f 107/1/108 119/1/120 120/1/109
f 107/1/108 120/1/109 108/1/97
f 124/1/121 123/1/121 117/1/118
f 124/1/121 117/1/118 116/1/117
f 121/1/121 124/1/121 116/1/117
f 121/1/121 116/1/117 115/1/116
f 122/1/121 121/1/121 115/1/116
f 122/1/121 115/1/116 114/1/115
f 125/1/121 122/1/121 114/1/115
f 125/1/121 114/1/115 113/1/114
f 119/1/120 123/1/121 124/1/121
f 119/1/120 124/1/121 120/1/109
f 120/1/109 124/1/121 121/1/121
f 120/1/109 121/1/121 109/1/110
f 109/1/110 121/1/121 122/1/121
f 109/1/110 122/1/121 110/1/111
f 110/1/111 122/1/121 125/1/121
f 110/1/111 125/1/121 111/1/112
f 123/1/121 119/1/120 118/1/119
f 123/1/121 118/1/119 117/1/118
f 112/1/113 111/1/112 125/1/121
f 112/1/113 125/1/121 113/1/114
f 5/1/12 6/1/14 137/1/122
f 5/1/12 137/1/122 126/1/123
f 4/1/10 5/1/12 126/1/123
f 4/1/10 126/1/123 127/1/124
f 128/1/125 3/1/8 4/1/10
f 128/1/125 4/1/10 127/1/124
f 129/1/126 2/1/6 3/1/8
f 129/1/126 3/1/8 128/1/125
f 130/1/127 1/1/4 2/1/6
f 130/1/127 2/1/6 129/1/126
f 131/1/128 12/1/1 1/1/4
f 131/1/128 1/1/4 130/1/127
f 132/1/129 11/1/24 12/1/1
f 132/1/129 12/1/1 131/1/128
f 133/1/130 10/1/22 11/1/24
f 133/1/130 11/1/24 132/1/129
f 9/1/20 10/1/22 133/1/130
f 9/1/20 133/1/130 134/1/131
f 8/1/18 9/1/20 134/1/131
f 8/1/18 134/1/131 135/1/132
f 7/1/16 8/1/18 135/1/132
f 7/1/16 135/1/132 136/1/133
f 6/1/14 7/1/16 136/1/133
f 6/1/14 136/1/133 137/1/122
f 126/1/123 137/1/122 149/1/134
f 126/1/123 149/1/134 138/1/135
f 127/1/124 126/1/123 138/1/135
f 127/1/124 138/1/135 139/1/136
f 140/1/137 128/1/125 127/1/124
f 140/1/137 127/1/124 139/1/136
f 141/1/138 129/1/126 128/1/125
f 141/1/138 128/1/125 140/1/137
f 142/1/139 130/1/127 129/1/126
f 142/1/139 129/1/126 141/1/138
f 143/1/140 131/1/128 130/1/127
f 143/1/140 130/1/127 142/1/139
f 144/1/141 132/1/129 131/1/128
f 144/1/141 131/1/128 143/1/140
f 145/1/142 133/1/130 132/1/129
f 145/1/142 132/1/129 144/1/141
f 134/1/131 133/1/130 145/1/142
f 134/1/131 145/1/142 146/1/143
f 135/1/132 134/1/131 146/1/143
f 135/1/132 146/1/143 147/1/144
f 136/1/133 135/1/132 147/1/144
f 136/1/133 147/1/144 148/1/145
f 137/1/122 136/1/133 148/1/145
f 137/1/122 148/1/145 149/1/134
f 138/1/135 149/1/134 161/1/146
f 138/1/135 161/1/146 150/1/147
f 139/1/136 138/1/135 150/1/147
f 139/1/136 150/1/147 151/1/148
f 152/1/149 140/1/137 139/1/136
f 152/1/149 139/1/136 151/1/148
f 153/1/150 141/1/138 140/1/137
f 153/1/150 140/1/137 152/1/149
f 154/1/151 142/1/139 141/1/138
f 154/1/151 141/1/138 153/1/150
f 155/1/152 143/1/140 142/1/139
f 155/1/152 142/1/139 154/1/151
f 156/1/153 144/1/141 143/1/140
f 156/1/153 143/1/140 155/1/152
f 157/1/154 145/1/142 144/1/141
f 157/1/154 144/1/141 156/1/153
f 146/1/143 145/1/142 157/1/154
f 146/1/143 157/1/154 158/1/155
f 147/1/144 146/1/143 158/1/155
f 147/1/144 158/1/155 159/1/156
f 148/1/145 147/1/144 159/1/156
f 148/1/145 159/1/156 160/1/157
f 149/1/134 148/1/145 160/1/157
f 149/1/134 160/1/157 161/1/146
f 150/1/147 161/1/146 173/1/158
f 150/1/147 173/1/158 162/1/159
f 151/1/148 150/1/147 162/1/159
f 151/1/148 162/1/159 163/1/160
f 164/1/161 152/1/149 151/1/148
f 164/1/161 151/1/148 163/1/160
f 165/1/162 153/1/150 152/1/149
f 165/1/162 152/1/149 164/1/161
f 166/1/163 154/1/151 153/1/150
f 166/1/163 153/1/150 165/1/162
f 167/1/164 155/1/152 154/1/151
f 167/1/164 154/1/151 166/1/163
f 168/1/165 156/1/153 155/1/152
f 168/1/165 155/1/152 167/1/164
f 169/1/166 157/1/154 156/1/153
f 169/1/166 156/1/153 168/1/165
f 158/1/155 157/1/154 169/1/166
f 158/1/155 169/1/166 170/1/167
f 159/1/156 158/1/155 170/1/167
f 159/1/156 170/1/167 171/1/168
f 160/1/157 159/1/156 171/1/168
f 160/1/157 171/1/168 172/1/169
f 161/1/146 160/1/157 172/1/169
f 161/1/146 172/1/169 173/1/158
f 162/1/159 173/1/158 185/1/170
f 162/1/159 185/1/170 174/1/171
f 163/1/160 162/1/159 174/1/171
f 163/1/160 174/1/171 175/1/172
f 176/1/173 164/1/161 163/1/160
f 176/1/173 163/1/160 175/1/172
f 177/1/174 165/1/162 164/1/161
f 177/1/174 164/1/161 176/1/173
f 178/1/175 166/1/163 165/1/162
f 178/1/175 165/1/162 177/1/174
f 179/1/176 167/1/164 166/1/163
f 179/1/176 166/1/163 178/1/175
f 180/1/177 168/1/165 167/1/164
f 180/1/177 167/1/164 179/1/176
f 181/1/178 169/1/166 168/1/165
f 181/1/178 168/1/165 180/1/177
f 170/1/167 169/1/166 181/1/178
f 170/1/167 181/1/178 182/1/179
f 171/1/168 170/1/167 182/1/179
f 171/1/168 182/1/179 183/1/180
f 172/1/169 171/1/168 183/1/180
f 172/1/169 183/1/180 184/1/181
f 173/1/158 172/1/169 184/1/181
f 173/1/158 184/1/181 185/1/170
f 182/1/179 189/1/182 190/1/182
f 182/1/179 190/1/182 183/1/180
f 183/1/180 190/1/182 186/1/182
f 183/1/180 186/1/182 184/1/181
f 184/1/181 186/1/182 187/1/182
f 184/1/181 187/1/182 185/1/170
f 185/1/170 187/1/182 188/1/182
f 185/1/170 188/1/182 174/1/171
f 190/1/182 189/1/182 180/1/177
f 190/1/182 180/1/177 179/1/176
f 186/1/182 190/1/182 179/1/176
f 186/1/182 179/1/176 178/1/175
f 187/1/182 186/1/182 178/1/175
f 187/1/182 178/1/175 177/1/174
f 188/1/182 187/1/182 177/1/174
f 188/1/182 177/1/174 176/1/173
f 189/1/182 182/1/179 181/1/178
f 189/1/182 181/1/178 180/1/177
f 174/1/171 188/1/182 176/1/173
f 174/1/171 176/1/173 175/1/172
# 376 triangles in group
# 376 triangles total

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
kaplademo/externals/resources/car2.raw vendored Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 KiB

1416
kaplademo/externals/resources/fxaa.fs vendored Normal file

File diff suppressed because it is too large Load Diff

6
kaplademo/externals/resources/fxaa.vs vendored Normal file
View File

@ -0,0 +1,6 @@
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_Vertex * 2.0f - 1.0f;
}

View File

@ -0,0 +1,24 @@
uniform sampler2D colorTex;
uniform float sx;
void main (void)
{
vec3 bloom = vec3(0.0, 0.0, 0.0);
const float hdrScale = 1.5;
const int kernelSize = 10;
const float invScale = 1.0 / (hdrScale * float(kernelSize));
for (int x = -kernelSize; x <= kernelSize; x++)
{
float s = gl_TexCoord[0].s + x * sx;
float t = gl_TexCoord[0].t;
vec3 color = texture2D(colorTex, vec2(s,t)).rgb;
float luminance = dot(color, vec3(0.2125, 0.7154, 0.0721));
if (luminance > 1.0)
{
bloom += color * ((kernelSize+1) - abs(float(x)));
}
}
gl_FragColor = vec4(bloom * invScale, 1.0);
}

View File

@ -0,0 +1,30 @@
uniform sampler2D colorTex;
uniform sampler2D blurTex;
uniform float sy;
void main (void)
{
const float hdrScale = 1.5;
const int kernelSize = 10;
const float invScale = 1.0 / (hdrScale * float(kernelSize) * 100.0);
vec3 colorP = texture2D(colorTex, gl_TexCoord[0]).rgb;
vec3 bloom = vec3(0.0, 0.0, 0.0);
for (int y = -kernelSize; y <= kernelSize; y++)
{
float s = gl_TexCoord[0].s;
float t = gl_TexCoord[0].t + y * sy;
vec3 color = texture2D(blurTex, vec2(s,t)).rgb;
float luminance = dot(color, vec3(0.2125, 0.7154, 0.0721));
if (luminance > 1.0)
{
bloom += color * ((kernelSize+1) - abs(float(y)));
}
}
vec3 hdrColor = invScale * bloom + colorP;
vec3 toneMappedColor = 2.0 * hdrColor / (hdrColor + vec3(1.0));
gl_FragColor = vec4(toneMappedColor, 1.0);
}

View File

@ -0,0 +1,529 @@
uniform sampler3D ttt3D;
uniform float extraNoiseScale = 1.0f;
uniform float noiseScale = 0.03f;
float noise(float p) {
return texture3D(ttt3D, vec3(p*noiseScale*extraNoiseScale, 0.5, 0.5)).x;
}
float noise(float p, float q) {
return texture3D(ttt3D, vec3(p*noiseScale*extraNoiseScale, q*noiseScale*extraNoiseScale, 0.5)).x;
}
float snoise(float p) {
return noise(p)*2.0f - 1.0f;
}
float snoise(float p, float q) {
return noise(p, q)*2.0f - 1.0f;
}
float boxstep(float a, float b, float x) {
return (clamp(((x)-(a)) / ((b)-(a)), 0, 1));
}
uniform float Ka = 1;
uniform float Kd = 0.75;
uniform float Ks = 0.15;
uniform float roughness = 0.025;
uniform vec3 specularcolor = vec3(1, 1, 1);
uniform float ringscale = 0;
uniform float grainscale = 0;
uniform float txtscale = 1;
uniform float plankspertile = 4;
uniform vec3 lightwood = vec3(0.57, 0.292, 0.125);
uniform vec3 darkwood = vec3(0.275, 0.15, 0.06);
uniform vec3 groovecolor = vec3(.05, .04, .015);
//uniform float plankwidth = .05;
uniform float plankwidth = .2;
uniform float groovewidth = 0.001;
uniform float plankvary = 0.8;
uniform float grainy = 1;
uniform float wavy = 0.08;
uniform float MINFILTERWIDTH = 1.0e-7;
vec3 myTexture3D_0(vec3 p)
{
float r;
float r2;
float whichrow;
float whichplank;
float swidth;
float twidth;
float fwidth;
float ss;
float tt;
float w;
float h;
float fade;
float ttt;
vec3 Ct;
vec3 woodcolor;
float groovy;
float PGWIDTH;
float PGHEIGHT;
float GWF;
float GHF;
float tilewidth;
float whichtile;
float tmp;
float planklength;
PGWIDTH = plankwidth + groovewidth;
planklength = PGWIDTH * plankspertile - groovewidth;
PGHEIGHT = planklength + groovewidth;
GWF = groovewidth*0.5 / PGWIDTH;
GHF = groovewidth*0.5 / PGHEIGHT;
// Determine how wide in s-t space one pixel projects to
float s = p.x;
float t = p.y;
float du = 1.0;
float dv = 1.0;
swidth = (max(abs(dFdx(s)*du) + abs(dFdy(s)*dv), MINFILTERWIDTH) /
PGWIDTH) * txtscale;
twidth = (max(abs(dFdx(t)*du) + abs(dFdy(t)*dv), MINFILTERWIDTH) /
PGHEIGHT) * txtscale;
fwidth = max(swidth, twidth);
ss = (txtscale * s) / PGWIDTH;
whichrow = floor(ss);
tt = (txtscale * t) / PGHEIGHT;
whichplank = floor(tt);
if (mod(whichrow / plankspertile + whichplank, 2) >= 1) {
ss = txtscale * t / PGWIDTH;
whichrow = floor(ss);
tt = txtscale * s / PGHEIGHT;
whichplank = floor(tt);
tmp = swidth; swidth = twidth; twidth = tmp;
}
ss -= whichrow;
tt -= whichplank;
whichplank += 20 * (whichrow + 10);
if (swidth >= 1)
w = 1 - 2 * GWF;
else w = clamp(boxstep(GWF - swidth, GWF, ss), max(1 - GWF / swidth, 0), 1)
- clamp(boxstep(1 - GWF - swidth, 1 - GWF, ss), 0, 2 * GWF / swidth);
if (twidth >= 1)
h = 1 - 2 * GHF;
else h = clamp(boxstep(GHF - twidth, GHF, tt), max(1 - GHF / twidth, 0), 1)
- clamp(boxstep(1 - GHF - twidth, 1 - GHF, tt), 0, 2 * GHF / twidth);
// This would be the non-antialiased version:
//w = step (GWF,ss) - step(1-GWF,ss);
//h = step (GHF,tt) - step(1-GHF,tt);
groovy = w*h;
// Add the ring patterns
fade = smoothstep(1 / ringscale, 8 / ringscale, fwidth);
if (fade < 0.999) {
ttt = tt / 4 + whichplank / 28.38 + wavy * noise(8 * ss, tt / 4);
r = ringscale * noise(ss - whichplank, ttt);
r -= floor(r);
r = 0.3 + 0.7*smoothstep(0.2, 0.55, r)*(1 - smoothstep(0.75, 0.8, r));
r = (1 - fade)*r + 0.65*fade;
// Multiply the ring pattern by the fine grain
fade = smoothstep(2 / grainscale, 8 / grainscale, fwidth);
if (fade < 0.999) {
r2 = 1.3 - noise(ss*grainscale, (tt*grainscale / 4));
r2 = grainy * r2*r2 + (1 - grainy);
r *= (1 - fade)*r2 + (0.75*fade);
}
else r *= 0.75;
}
else r = 0.4875;
// Mix the light and dark wood according to the grain pattern
woodcolor = lerp(lightwood, darkwood, r);
// Add plank-to-plank variation in overall color
woodcolor *= (1 - plankvary / 2 + plankvary * noise(whichplank + 0.5));
Ct = lerp(groovecolor, woodcolor, groovy);
return Ct;
}
float noise3D_1(vec3 p)
{
return texture3D(ttt3D, p).x*2.0f - 1.0f;
}
float turbulence_1(vec3 p, int octaves, float lacunarity, float gain) {
float freq = 1.0f;
float amp = 0.8f;
float sum = 0.0f;
for (int i = 0; i<octaves; i++) {
sum += abs(noise3D_1(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float spike_1(float c, float w, float x) {
return smoothstep(c - w, c, x) * smoothstep(c + w, c, x);
}
vec3 myTexture3D_1(vec3 p)
{
float noiseScale = 0.1f*extraNoiseScale;
float noise = turbulence_1(p*noiseScale, 3, 3.0f, 0.5f);
//noise = turbulence(p*noiseScale + vec3(noise, noise, noise*0.3)*0.01f, 8, 3.0f, 0.5f);
//noise = spike(0.35f, 0.05f, noise);
//noise = noise;
vec3 base = lerp(vec3(164, 148, 108)*1.63 / 255, vec3(178, 156, 126)*1.73 / 255, spike_1(0.5f, 0.3f, turbulence_1(p*noiseScale*0.7f + vec3(noise*0.5, noise, noise)*0.011f, 2, 2.0f, 0.5f)));
//vec3 b2 = lerp(base, vec3(0.0f, 0.0f, 0.0f), noise);
vec3 b2 = lerp(base, vec3(173, 160, 121)*1.73 / 255, noise);
return b2*0.75f;
}
vec3 myTexture3DCom(vec3 p, float mat) {
// Depend on material ID
if (mat < 0.5f) {
//return myTexture3D_0(p);
return vec3(173, 160, 151) *0.85/ 255;
//return lightwood*1.3;
}
else
if (mat < 1.5f) {
//return myTexture3D_1(p);
return vec3(173, 100, 21)*1.73 / 255;
} else {
return vec3(1.0f, 0.0f, 0.0f);
}
}
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform float hdrScale = 5.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform float roughnessScale;
uniform vec3 ambientColor;
uniform sampler2DArray diffuseTexArray;
uniform sampler2DArray bumpTexArray;
uniform sampler2DArray specularTexArray;
uniform sampler2DArray emissiveReflectSpecPowerTexArray;
uniform vec2 shadowTaps[12];
float shadowCoeff1(float bscale)
{
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd*bscale;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 6;
float radius = 0.0003f/pow(2,index);
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
uniform float RollOff = 0.5f;
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
void main()
{
/*
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
if (index == 3) gl_FragColor = vec4(1,0,0,1);
if (index == 2) gl_FragColor = vec4(0,1,0,1);
if (index == 1) gl_FragColor = vec4(0,0,1,1);
if (index == 0) gl_FragColor = vec4(1,1,0,1);
return;*/
/*
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index)*0.33333333f;
gl_FragColor = vec4(shadow_coord.xyz,1.0f);
return;
*/
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 t0 = gl_TexCoord[3].xyz;
vec3 t1 = gl_TexCoord[4].xyz;
vec3 diffuseMat;
vec3 specularMat;
vec3 bump;
vec3 emissiveReflectSpecPow;
// read in material color for diffuse, specular, bump, emmisive
// 3D texture
diffuseMat = myTexture3DCom(gl_TexCoord[0].xyz, gl_TexCoord[6].w);
//diffuseMat = myTexture3D(gl_TexCoord[0].xyz);//texture3D(ttt3D, gl_TexCoord[0].xyz);
//diffuseMat = texture3D(ttt3D, gl_TexCoord[0].xyz);
specularMat = vec3(1.0);
bump = texture2D(texture, gl_TexCoord[5].xy).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
// apply bump to the normal
bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f;
bump.xy *= roughnessScale*0.1;
float sc = 1.0f;
normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z);
//gl_FragColor.xyz = normal*0.5 + vec3(0.5,0.5,0.5);
//gl_FragColor.w = 1;
//return;
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
//diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = 0.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 shadowColor = vec3(0.4, 0.4, 0.7); // colored shadow
//vec3 lvec = normalize(spotLightDir);
vec3 lvec = normalize(spotLightPos - gl_TexCoord[1].xyz);
float ldn = max(0.0f, dot(normal, lvec));
float cosine = dot(lvec, spotLightDir);
float intensity = smoothstep(spotLightCosineDecayBegin, spotLightCosineDecayEnd, cosine);
float bscale = 1;//1.0f-ldn;
float shadowC = shadowCoeff1(bscale);
//gl_FragColor = vec4(shadowC,shadowC,shadowC,1.0f);
//return;
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance*intensity;
// add colored shadow
diffuseColor += (1.0 - shadowC*ldn) * shadowAmbient * shadowColor * diffuseMat*intensity;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r, eyeVec)), specularPower)*shadowC*intensity;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,79 @@
uniform float uvScale = 1.0f;
uniform sampler2D transTex;
uniform int transTexSize;
uniform float iTransTexSize;
uniform float bumpTextureUVScale;
//attribute mat4 transformmatrix;
void main()
{
int ti = (int)(gl_MultiTexCoord0.w);
//int ti = tq;
int tpr = transTexSize / 4;
int row = ti / tpr;
int col = (ti - row*tpr)*4;
float fx = (col+0.5f)*iTransTexSize;
float fy = (row+0.5f)*iTransTexSize;
vec4 r0 = texture2D(transTex, vec2(fx,fy));
vec4 r1 = texture2D(transTex, vec2(fx+iTransTexSize,fy));
vec4 r2 = texture2D(transTex, vec2(fx+iTransTexSize*2.0f,fy));
vec4 r3 = texture2D(transTex, vec2(fx+iTransTexSize*3.0f,fy));
// vec4 r3 = vec4(0,0,0,1);
vec3 offset = vec3(r0.w, r1.w, r2.w);
r0.w = 0.0f;
r1.w = 0.0f;
r2.w = 0.0f;
float material = r3.w;
r3.w = 1.0f;
mat4 transformmatrix = mat4(r0,r1,r2,r3);
mat4 mvp = gl_ModelViewMatrix * transformmatrix;
mat4 mvpt = gl_ModelViewMatrixInverseTranspose * transformmatrix;
vec4 t0 = vec4(gl_MultiTexCoord0.xyz, 0.0f);
vec4 t1 = vec4(cross(gl_Normal.xyz, t0.xyz), 0.0f);
// mat4 mvp = gl_ModelViewMatrix;
// mat4 mvpt = gl_ModelViewMatrixInverseTranspose;
vec4 eyeSpacePos = mvp * gl_Vertex;
//eyeSpacePos.y += gl_InstanceID * 0.2f;
//gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz*uvScale;
vec3 coord3d = gl_Vertex.xyz + offset;
gl_TexCoord[0].xyz = (coord3d)*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3] = mvpt * t0;
gl_TexCoord[4].xyz = mvpt * t1;
gl_TexCoord[5].xy = vec2(dot(coord3d, t0.xyz), dot(coord3d, t1.xyz))*bumpTextureUVScale*2;
gl_TexCoord[6].xyz = vec3(gl_MultiTexCoord1.xy, material);
gl_TexCoord[6].y = 1.0 - gl_TexCoord[6].y;
float MAX_3D_TEX = 8.0;
if (gl_TexCoord[6].x >= 5.0f) {
// 2D Tex
gl_TexCoord[6].x -= 5.0f;
gl_TexCoord[6].z = floor(gl_TexCoord[6].z / MAX_3D_TEX);
} else {
gl_TexCoord[6].z -= floor(gl_TexCoord[6].z / MAX_3D_TEX)*MAX_3D_TEX;
gl_TexCoord[6].z -= 100.0f;
}
gl_TexCoord[6].w = floor(fract(material / MAX_3D_TEX)*MAX_3D_TEX + 0.5f);
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
}

View File

@ -0,0 +1,309 @@
uniform sampler3D ttt3D;
uniform float extraNoiseScale = 1.0f;
float noise3D(vec3 p)
{
return texture3D(ttt3D, p).x*2.0f - 1.0f;
}
float turbulence(vec3 p, int octaves, float lacunarity, float gain) {
float freq = 1.0f;
float amp = 0.8f;
float sum = 0.0f;
for(int i=0; i<octaves; i++) {
sum += abs(noise3D(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float spike(float c, float w, float x) {
return smoothstep(c-w, c, x) * smoothstep(c+w, c, x);
}
vec3 myTexture3D(vec3 p)
{
float noiseScale = 0.1f*extraNoiseScale;
float noise = turbulence(p*noiseScale, 3, 3.0f, 0.5f);
//noise = turbulence(p*noiseScale + vec3(noise, noise, noise*0.3)*0.01f, 8, 3.0f, 0.5f);
//noise = spike(0.35f, 0.05f, noise);
//noise = noise;
vec3 base = lerp(vec3(164,148,108)*1.63/255, vec3(178,156,126)*1.73/255, spike(0.5f, 0.3f, turbulence(p*noiseScale*0.7f + vec3(noise*0.5, noise, noise)*0.011f, 2, 2.0f, 0.5f)));
//vec3 b2 = lerp(base, vec3(0.0f, 0.0f, 0.0f), noise);
vec3 b2 = lerp(base, vec3(173, 160, 121)*1.73/255, noise);
return b2;
}
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform float hdrScale = 5.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform float roughnessScale;
uniform vec3 ambientColor;
uniform sampler2DArray diffuseTexArray;
uniform sampler2DArray bumpTexArray;
uniform sampler2DArray specularTexArray;
uniform sampler2DArray emissiveReflectSpecPowerTexArray;
float shadowCoeff1()
{
const int index = 0;
//int index = 3;
//
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
uniform float RollOff = 0.5f;
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
void main()
{
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 t0 = gl_TexCoord[3].xyz;
vec3 t1 = gl_TexCoord[4].xyz;
vec3 diffuseMat;
vec3 specularMat;
vec3 bump;
vec3 emissiveReflectSpecPow;
// read in material color for diffuse, specular, bump, emmisive
if (gl_TexCoord[6].z >= 0.0f) {
// 2D texture
diffuseMat = texture2DArray(diffuseTexArray, gl_TexCoord[6].xyz).rgb;
//specularMat = texture2DArray(specularTexArray, gl_TexCoord[6].xyz).rgb; // TODO Does not seem to work
specularMat = vec3(1.0f);
bump = texture2DArray(bumpTexArray, gl_TexCoord[6].xyz).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = texture2DArray(emissiveReflectSpecPowerTexArray, gl_TexCoord[6].xyz).xyz;
} else {
// 3D texture
diffuseMat = myTexture3D(gl_TexCoord[0].xyz) * vec3(0.5,0.5,0.5);//texture3D(ttt3D, gl_TexCoord[0].xyz);
specularMat = vec3(1.0);
bump = texture2D(texture, gl_TexCoord[5].xy).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
}
// apply bump to the normal
bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f;
bump.xy *= roughnessScale*2;
float sc = 1.0f;
normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z);
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = emissiveReflectSpecPow.r*10.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 0.9, 0.9);
vec3 shadowColor = vec3(0.4, 0.4, 0.9); // colored shadow
vec3 lvec = normalize(spotLightDir);
float ldn = max(0.0f, dot(normal, lvec));
float shadowC = shadowCoeff1();
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
// add colored shadow
diffuseColor += (1.0 - shadowC) * shadowAmbient * shadowColor * diffuseMat;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r,eyeVec)), specularPower)*shadowC;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = rimLightIntensity * vec3(1.0, 0.9, 0.9);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
//color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
//color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,44 @@
uniform float uvScale = 1.0f;
attribute mat4 transformmatrix;
uniform float bumpTextureUVScale;
void main()
{
mat4 mvp = gl_ModelViewMatrix * transformmatrix;
mat4 mvpt = gl_ModelViewMatrixInverseTranspose * transformmatrix;
//mat4 mvp2 = gl_ModelViewMatrix * transformmatrix;
//mat4 mvp = gl_ModelViewMatrix;
//mat4 mvpt = gl_ModelViewMatrixInverseTranspose;
vec4 eyeSpacePos = mvp * gl_Vertex;
vec4 t0 = vec4(gl_MultiTexCoord0.xyz, 0.0f);
vec4 t1 = vec4(cross(gl_Normal.xyz, t0.xyz), 0.0f);
vec3 coord3d = gl_Vertex.xyz;
gl_TexCoord[0].xyz = (coord3d)*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3] = mvpt * t0;
gl_TexCoord[4] = mvpt * t1;
gl_TexCoord[5].xy = vec2(dot(coord3d, t0.xyz), dot(coord3d, t1.xyz))*bumpTextureUVScale*2;
gl_TexCoord[6].xyz = vec3(0,0,-100); // TODO: 2D UV are 0 and material id is -100 (first 3D texture)
/*
//vec4 eyeSpacePos2 = mvp2 * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
//gl_FrontColor.x += eyeSpacePos2.x;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
*/
}

View File

@ -0,0 +1,308 @@
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform float hdrScale = 5.0;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform vec3 ambientColor;
uniform vec2 shadowTaps[12];
float shadowCoeff1()
{
//const int index = 0;
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 12;
float radius = 0.0003f / pow(2, index);
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 12;
float radius = 1.0f;
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 12;
float radius = 0.02f;
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float filterwidth(float2 v)
{
float2 fw = max(abs(ddx(v)), abs(ddy(v)));
return max(fw.x, fw.y);
}
float2 bump(float2 x)
{
return (floor((x) / 2) + 2.f * max(((x) / 2) - floor((x) / 2) - .5f, 0.f));
}
float checker(float2 uv)
{
float width = filterwidth(uv);
float2 p0 = uv - 0.5 * width;
float2 p1 = uv + 0.5 * width;
float2 i = (bump(p1) - bump(p0)) / width;
return i.x * i.y + (1 - i.x) * (1 - i.y);
}
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
uniform float RollOff = 0.5f;
void main()
{
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 diffuseMat;
vec3 specularMat;
vec3 emissiveReflectSpecPow;
specularMat = vec3(1.0);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 wnormal = normalize(gl_TexCoord[4].xyz);
// read in material color for diffuse, specular, bump, emmisive
// 3D texture
vec4 colorx;
if (useTexture > 0)
colorx = texture2D(texture, gl_TexCoord[0]);
else {
colorx = gl_Color;
colorx *= 1.0 - 0.25*checker(float2(gl_TexCoord[3].x, gl_TexCoord[3].z));
}
colorx = clamp(colorx,0,1);
diffuseMat = colorx.xyz*0.4;
//diffuseMat = myTexture3D(gl_TexCoord[0].xyz);//texture3D(ttt3D, gl_TexCoord[0].xyz);
//diffuseMat = texture3D(ttt3D, gl_TexCoord[0].xyz);
if (dot(normal, gl_TexCoord[1].xyz) > 0) {
normal.xyz *= -1;
}
//gl_FragColor.xyz = normal*0.5 + vec3(0.5,0.5,0.5);
//gl_FragColor.w = 1;
//return;
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
//diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = 0.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 shadowColor = vec3(0.4, 0.4, 0.7); // colored shadow
//vec3 lvec = normalize(spotLightDir);
vec3 lvec = normalize(spotLightPos - gl_TexCoord[1].xyz);
float cosine = dot(lvec, spotLightDir);
float intensity = smoothstep(spotLightCosineDecayBegin, spotLightCosineDecayEnd, cosine);
float ldn = max(0.0f, dot(normal, lvec));
float shadowC = shadowCoeff1();
//gl_FragColor = vec4(shadowC,shadowC,shadowC,1.0f);
//return;
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance*intensity;
// add colored shadow
diffuseColor += (1.0 - shadowC*ldn) * shadowAmbient * shadowColor * diffuseMat*intensity;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r, eyeVec)), specularPower)*shadowC*intensity;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
//float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
//vec4 fogCol = gl_Fog.color;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,13 @@
uniform float uvScale = 1.0f;
void main()
{
vec4 eyeSpacePos = gl_ModelViewMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = gl_ModelViewMatrixInverseTranspose * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3].xyz = gl_Vertex.xyz;
gl_TexCoord[4].xyz = gl_Normal.xyz;
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
}

View File

@ -0,0 +1,38 @@
uniform sampler2D colorTex;
uniform sampler2D depthTex;
uniform float sx;
uniform float sy;
void main (void)
{
const float depthEnd = 0.993;
const float depthSize = 0.015;
vec3 colorP = texture2D(colorTex, gl_TexCoord[0]).rgb;
float depth = texture2D(depthTex, gl_TexCoord[0].st).r;
if ((depth - depthEnd) < depthSize)
{
const int depthKernelSize = 5;
vec3 colorSum = vec3(0.0);
float cnt = 0.0;
for (int x = -depthKernelSize; x <= depthKernelSize; x++)
for (int y = -depthKernelSize; y <= depthKernelSize; y++)
{
float s = gl_TexCoord[0].s + x * sy;
float t = gl_TexCoord[0].t + y * sy;
float scalex = ((depthKernelSize+1) - abs(float(x))) / depthKernelSize;
float scaley = ((depthKernelSize+1) - abs(float(y))) / depthKernelSize;
float scale = scalex * scaley;
vec3 color = texture2D(colorTex, vec2(s,t)).rgb;
colorSum += scale * color;
cnt += scale;
}
colorSum /= cnt;
float depthScale = pow(max(0.0f,min(1.0, ( abs(depth-depthEnd)) / depthSize)),1.5);
colorP = depthScale * colorSum + (1.0 - depthScale) * colorP;
}
gl_FragColor = vec4(colorP, 1.0);
}

View File

@ -0,0 +1,5 @@
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_Vertex * 2.0 - 1.0;
}

View File

@ -0,0 +1,123 @@
uniform sampler2DArrayShadow stex;
uniform float shadowAmbient = 0.3;
float shadowCoef()
{
const int index = 0;
/*
int index = 3;
// find the appropriate depth map to look up in based on the depth of this fragment
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
*/
// transform this fragment's position from view space to scaled light clip space
// such that the xy coordinates are in [0;1]
// note there is no need to divide by w for othogonal light sources
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[2].xyz, 1);
shadow_coord.w = shadow_coord.z;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
return shadow2DArray(stex, shadow_coord).x;
}
uniform float ispotMaxDist;
uniform vec3 spotOriginEye;
uniform sampler2D spot_a0123;
uniform sampler2D spot_b123;
uniform sampler2D smokeTex;
const float PI = 3.1415926535897932384626433832795;
const vec3 _2pik = vec3(2.0) * vec3(PI,2.0*PI,3.0*PI);
const vec3 factor_a = vec3(2.0*PI)*vec3(1.0,2.0,3.0);
const vec3 factor_b = vec3(2.0*PI)*vec3(1.0,2.0,3.0);
const vec3 value_1 = vec3(1.0);
uniform mat4 eyeToSpotMatrix;
void main()
{
//gl_FragColor = gl_Color;
//return;
/*
gl_FragColor = texture2D(smokeTex, gl_TexCoord[0].xy);
gl_FragColor.w = gl_FragColor.r;
gl_FragColor.xyz = vec3(1,1,1);
return;
*/
// calculate eye-space normal from texture coordinates
vec3 N;
N.xy = gl_TexCoord[0].xy*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
float mag = dot(N.xy, N.xy);
if (mag > 1.0) discard; // kill pixels outside circle
float falloff = pow(1.0-mag,1.0);//exp(-mag);
//falloff = 1.0f;
float shadowC = shadowCoef();
vec3 shadowColor = vec3(0.4, 0.4, 0.9)*0.8;
// Also FOM
// vec4 projectionCoordinate = eyeToSpotMatrix*vec4(gl_TexCoord[2].xyz, 1.0f);
vec4 projectionCoordinate = eyeToSpotMatrix*vec4(gl_TexCoord[2].xyz, 1.0f);
//gl_FragColor.xyz = gl_TexCoord[3].xyz*0.25f;
//gl_FragColor.xyz = projectionCoordinate.xyz / projectionCoordinate.w;
//gl_FragColor.w = 1.0f;
//read Fourier series coefficients for color extinction on RGB
vec4 sR_a0123 = texture2DProj(spot_a0123,projectionCoordinate);
vec3 sR_b123 = texture2DProj(spot_b123,projectionCoordinate).rgb;
//gl_FragColor.xyz = sR_a0123.xyz;
//gl_FragColor.w = 1.0f;
//return;
//compute absolute and normalized distance (in spot depth range)
float distance2spotCenter = length(spotOriginEye-gl_TexCoord[2].xyz);//distance from spot origin to surfel in world space
float d = distance2spotCenter*ispotMaxDist;
//compute some value to recover the extinction coefficient using the Fourier series
vec3 sin_a123 = sin(factor_a*vec3(d));
vec3 cos_b123 = value_1-cos(factor_b*vec3(d));
//compute the extinction coefficients using Fourier
float att = (sR_a0123.r*d/2.0) + dot(sin_a123*(sR_a0123.gba/_2pik) ,value_1) + dot(cos_b123*(sR_b123.rgb/_2pik) ,value_1);
att = max(0.0f, att);
att = min(1.0f, att);
shadowC *= (1.0f-att);
float inS = shadowC;
shadowC = (shadowAmbient + (1.0f -shadowAmbient)*shadowC);
//....
if (gl_TexCoord[0].z > 1) shadowC = 1;
vec4 texColor = texture2D(smokeTex, gl_TexCoord[0].xy*0.25+gl_TexCoord[1].xy);
gl_FragColor.xyz = (texColor.x)*gl_Color.xyz*(shadowColor + (vec3(1.0f,1,1) -shadowColor)*shadowC);//*falloff;
gl_FragColor.w = gl_Color.w*texColor.r;
//float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[2].z), 0.0, 1.0);
//float fog = exp(-gl_Fog.density*(gl_TexCoord[0].z*gl_TexCoord[0].z));
//gl_FragColor = mix(gl_Fog.color, gl_FragColor, fog);
gl_FragColor.xyz *= 1.6f;
gl_FragColor.w *= max(min(falloff,1.0f),0.0f) * max(min(gl_TexCoord[0].w,1.0f),0.0f);
//gl_FragColor.w = 1;
//gl_FragColor.xyz = vec3(shadowC, shadowC, shadowC);
// gl_FragColor.w = 0.2f;
//gl_FragColor.w = falloff * gl_TexCoord[0].w;
//gl_FragColor.xyz = sR_a0123.xyz;
gl_FragColor.xyz *= ((gl_TexCoord[0].z)+inS*0.3)*0.7;
//gl_FragDepth = gl_FragCoord.z - (1-mag)*0.00002;
}

View File

@ -0,0 +1,116 @@
//#version 120\n
//#extension GL_EXT_geometry_shader4 : enable\n
uniform float pointRadius; // point size in world space
uniform float densityThreshold = 50.0;
uniform float idensityThreshold = 1.0 / 30.0;
uniform float pointShrink = 0.25;
uniform sampler2D meteorTex;
void main()
{
gl_FrontColor = gl_FrontColorIn[0];
float density = gl_TexCoordIn[0][1].x;
float life = gl_TexCoordIn[0][1].y;
gl_TexCoord[1].xy = 0.25f*vec2(gl_PrimitiveIDIn / 4, gl_PrimitiveIDIn % 4);
// scale down point size based on density
float factor = 1.0f;//density * idensityThreshold;
//smoothstep(0.0f, densityThreshold, density);
//density * idensityThreshold;
//clamp(density / 50.0f, 0, 1);
float pointSize = pointRadius*factor;//*(pointShrink + smoothstep(0.0, densityThreshold, density)*(1.0-pointShrink));
pointSize *= gl_TexCoordIn[0][3].x;
float tmp = gl_TexCoordIn[0][3].y;
float bb = 1.0f;
if (tmp > 0.5f) {
//gl_FrontColor = vec4(3*life,0,0,1);
// TODO: Meteor trail color here...
//vec2 fetchPos = vec2( min(max((3-lifeTime)/3,0),1), 0);
float val = 1-min(max((life-0.3)/0.2,0.01),0.99);
vec2 fetchPos = vec2(val, 0);
gl_FrontColor = texture2D(meteorTex, fetchPos);
if (gl_FrontColor.r > 0.5) bb += (gl_FrontColor.r-0.5)*(gl_FrontColor.r-0.5)*10;
}
// float pointSize = pointRadius;
// eye space
vec3 pos = gl_PositionIn[0].xyz;
vec3 pos2 = gl_TexCoordIn[0][0].xyz;
vec3 motion = pos - pos2;
vec3 dir = normalize(motion);
float len = length(motion);
vec3 x = dir * pointSize;
vec3 view = normalize(-pos);
vec3 y = normalize(cross(dir, view)) * pointSize;
float facing = dot(view, dir);
// check for very small motion to avoid jitter
float threshold = 0.01;
// if (len < threshold) {
if ((len < threshold) || (facing > 0.95) || (facing < -0.95)) {
pos2 = pos;
x = vec3(pointSize, 0.0, 0.0);
y = vec3(0.0, -pointSize, 0.0);
}
float angle = density;
float cv = cos(angle);
float sv = sin(angle);
vec3 xt = cv*x + sv*y;
vec3 yt = -sv*x + cv*y;
x = xt;
y = yt;
{
gl_TexCoord[0] = vec4(0, 0, bb, life);
gl_TexCoord[2] = vec4(pos + x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
gl_TexCoord[3] = gl_TexCoordIn[0][2];
EmitVertex();
gl_TexCoord[0] = vec4(0, 1, bb, life);
gl_TexCoord[2] = vec4(pos + x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 0, bb, life);
gl_TexCoord[2] = vec4(pos2 - x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 1, bb, life);
gl_TexCoord[2] = vec4(pos2 - x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
/*
gl_TexCoord[0] = vec4(0, 0, 0, life);
gl_TexCoord[2] = vec4(pos + x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(0, 1, 0, life);
gl_TexCoord[2] = vec4(pos + x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 0, 0, life);
gl_TexCoord[2] = vec4(pos2 - x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 1, 0, life);
gl_TexCoord[2] = vec4(pos2 - x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
*/
}
}

View File

@ -0,0 +1,19 @@
uniform float timestep = 0.02;
uniform vec3 eyeVel;
uniform float iStartFade = 1.0;
void main()
{
vec3 pos = gl_Vertex.xyz;
vec3 vel = gl_MultiTexCoord2.xyz;
//vel = vec3(10.0f,0.0f,0.0f);
vec3 pos2 = (pos - (vel+eyeVel)*timestep); // previous position
gl_Position = gl_ModelViewMatrix * vec4(pos, 1.0); // eye space
gl_TexCoord[0] = gl_ModelViewMatrix * vec4(pos2, 1.0);
gl_TexCoord[1].x = gl_MultiTexCoord1.x;
gl_TexCoord[1].y = max(0.0f, min(gl_MultiTexCoord3.x*iStartFade, 1.0f));
gl_TexCoord[2].xyz = pos;
gl_TexCoord[3] = gl_MultiTexCoord4;
gl_FrontColor = gl_Color;
}

View File

@ -0,0 +1,15 @@
uniform sampler2D ssaoTex;
uniform float sx;
void main (void)
{
float SSAO = 0.0;
for(int x = -4; x <= 4; x++)
{
SSAO += texture2D(ssaoTex,vec2(x * sx + gl_TexCoord[0].s,gl_TexCoord[0].t)).r * (5.0 - abs(float(x)));
}
gl_FragColor = vec4(vec3(SSAO / 25.0),1.0);
gl_FragColor.w = gl_FragColor.x;
}

View File

@ -0,0 +1,17 @@
uniform sampler2D ssaoTex;
uniform float sy;
void main (void)
{
float SSAO = 0.0;
for(int y = -4; y <= 4; y++)
{
SSAO += texture2D(ssaoTex,vec2(gl_TexCoord[0].s,y * sy + gl_TexCoord[0].t)).r * (5.0 - abs(float(y)));
}
gl_FragColor = vec4(vec3(pow(SSAO / 25.0,1.5)),1.0);
gl_FragColor.w = gl_FragColor.x;
//gl_FragColor = vec4(1,1,1,1);
}

View File

@ -0,0 +1,5 @@
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_Vertex * 2.0 - 1.0;
}

View File

@ -0,0 +1,7 @@
void main()
{
gl_Position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_Vertex;
gl_FrontColor = gl_Color;
}

View File

@ -0,0 +1,313 @@
uniform sampler3D ttt3D;
uniform float extraNoiseScale = 1.0f;
float noise3D(vec3 p)
{
return texture3D(ttt3D, p).x*2.0f - 1.0f;
}
float turbulence(vec3 p, int octaves, float lacunarity, float gain) {
float freq = 1.0f;
float amp = 0.8f;
float sum = 0.0f;
for(int i=0; i<octaves; i++) {
sum += abs(noise3D(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float spike(float c, float w, float x) {
return smoothstep(c-w, c, x) * smoothstep(c+w, c, x);
}
vec3 myTexture3D(vec3 p)
{
float noiseScale = 0.1f*extraNoiseScale;
float noise = turbulence(p*noiseScale, 3, 3.0f, 0.5f);
//noise = turbulence(p*noiseScale + vec3(noise, noise, noise*0.3)*0.01f, 8, 3.0f, 0.5f);
//noise = spike(0.35f, 0.05f, noise);
//noise = noise;
vec3 base = lerp(vec3(164,148,108)*1.63/255, vec3(178,156,126)*1.73/255, spike(0.5f, 0.3f, turbulence(p*noiseScale*0.7f + vec3(noise*0.5, noise, noise)*0.011f, 2, 2.0f, 0.5f)));
//vec3 b2 = lerp(base, vec3(0.0f, 0.0f, 0.0f), noise);
vec3 b2 = lerp(base, vec3(173, 160, 121)*1.73/255, noise);
return b2;
}
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform float hdrScale = 5.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform float roughnessScale;
uniform vec3 ambientColor;
uniform sampler2DArray diffuseTexArray;
uniform sampler2DArray bumpTexArray;
uniform sampler2DArray specularTexArray;
uniform sampler2DArray emissiveReflectSpecPowerTexArray;
float shadowCoeff1()
{
const int index = 0;
//int index = 3;
//
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
uniform float RollOff = 0.5f;
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
void main()
{
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 t0 = gl_TexCoord[3].xyz;
vec3 t1 = gl_TexCoord[4].xyz;
vec3 diffuseMat;
vec3 specularMat;
vec3 bump;
vec3 emissiveReflectSpecPow;
// read in material color for diffuse, specular, bump, emmisive
if (gl_TexCoord[6].z >= 0.0f) {
// 2D texture
diffuseMat = texture2DArray(diffuseTexArray, gl_TexCoord[6].xyz).rgb;
//specularMat = texture2DArray(specularTexArray, gl_TexCoord[6].xyz).rgb; // TODO Does not seem to work
specularMat = vec3(1.0f);
bump = texture2DArray(bumpTexArray, gl_TexCoord[6].xyz).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = texture2DArray(emissiveReflectSpecPowerTexArray, gl_TexCoord[6].xyz).xyz;
} else {
// 3D texture
diffuseMat = myTexture3D(gl_TexCoord[0].xyz) * vec3(0.5,0.5,0.5);//texture3D(ttt3D, gl_TexCoord[0].xyz);
specularMat = vec3(1.0);
bump = texture2D(texture, gl_TexCoord[5].xy).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
}
// apply bump to the normal
bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f;
bump.xy *= roughnessScale*2;
float sc = 1.0f;
normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z);
//gl_FragColor.xyz = normal*0.5 + vec3(0.5,0.5,0.5);
//gl_FragColor.w = 1;
//return;
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = emissiveReflectSpecPow.r*10.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 0.9, 0.9);
vec3 shadowColor = vec3(0.4, 0.4, 0.9); // colored shadow
vec3 lvec = normalize(spotLightDir);
float ldn = max(0.0f, dot(normal, lvec));
float shadowC = shadowCoeff1();
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
// add colored shadow
diffuseColor += (1.0 - shadowC) * shadowAmbient * shadowColor * diffuseMat;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r,eyeVec)), specularPower)*shadowC;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = rimLightIntensity * vec3(1.0, 0.9, 0.9);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,79 @@
uniform float uvScale = 1.0f;
uniform sampler2D transTex;
uniform int transTexSize;
uniform float iTransTexSize;
uniform float bumpTextureUVScale;
//attribute mat4 transformmatrix;
void main()
{
int ti = (int)(gl_MultiTexCoord0.w);
//int ti = tq;
int tpr = transTexSize / 4;
int row = ti / tpr;
int col = (ti - row*tpr)*4;
float fx = (col+0.5f)*iTransTexSize;
float fy = (row+0.5f)*iTransTexSize;
vec4 r0 = texture2D(transTex, vec2(fx,fy));
vec4 r1 = texture2D(transTex, vec2(fx+iTransTexSize,fy));
vec4 r2 = texture2D(transTex, vec2(fx+iTransTexSize*2.0f,fy));
vec4 r3 = texture2D(transTex, vec2(fx+iTransTexSize*3.0f,fy));
// vec4 r3 = vec4(0,0,0,1);
vec3 offset = vec3(r0.w, r1.w, r2.w);
r0.w = 0.0f;
r1.w = 0.0f;
r2.w = 0.0f;
float material = r3.w;
r3.w = 1.0f;
mat4 transformmatrix = mat4(r0,r1,r2,r3);
mat4 mvp = gl_ModelViewMatrix * transformmatrix;
mat4 mvpt = gl_ModelViewMatrixInverseTranspose * transformmatrix;
vec4 t0 = vec4(gl_MultiTexCoord0.xyz, 0.0f);
vec4 t1 = vec4(cross(gl_Normal.xyz, t0.xyz), 0.0f);
// mat4 mvp = gl_ModelViewMatrix;
// mat4 mvpt = gl_ModelViewMatrixInverseTranspose;
vec4 eyeSpacePos = mvp * gl_Vertex;
//eyeSpacePos.y += gl_InstanceID * 0.2f;
//gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz*uvScale;
vec3 coord3d = gl_Vertex.xyz + offset;
gl_TexCoord[0].xyz = (coord3d)*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3] = mvpt * t0;
gl_TexCoord[4].xyz = mvpt * t1;
gl_TexCoord[5].xy = vec2(dot(coord3d, t0.xyz), dot(coord3d, t1.xyz))*bumpTextureUVScale*2;
gl_TexCoord[6].xyz = vec3(gl_MultiTexCoord1.xy, material);
gl_TexCoord[6].y = 1.0 - gl_TexCoord[6].y;
float MAX_3D_TEX = 8.0;
if (gl_TexCoord[6].x >= 5.0f) {
// 2D Tex
gl_TexCoord[6].x -= 5.0f;
gl_TexCoord[6].z = floor(gl_TexCoord[6].z / MAX_3D_TEX);
} else {
gl_TexCoord[6].z -= floor(gl_TexCoord[6].z / MAX_3D_TEX)*MAX_3D_TEX;
gl_TexCoord[6].z -= 100.0f;
}
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
}

View File

@ -0,0 +1,8 @@
uniform sampler2DArrayShadow tex;
uniform float slice;
void main()
{
float v = shadow2DArray(tex, vec4(gl_TexCoord[0].xy,slice,10.001f));
gl_FragColor = vec4(v,v,v,1);
//gl_FragColor = vec4(1,0,0,1);
}

45
kaplademo/externals/resources/ssao.fs vendored Normal file
View File

@ -0,0 +1,45 @@
#define SAMPLEDIV 4
#define NUMSAMPLES SAMPLEDIV*SAMPLEDIV
#define iNUMSAMPLES 1.0f / (SAMPLEDIV * SAMPLEDIV)
#define BIAS 1.0f
uniform vec3 samples[NUMSAMPLES];
uniform sampler2D depthTex;
uniform sampler2D normalTex;
uniform sampler2D unitVecTex;
uniform mat4x4 biasProjMat;
uniform mat4x4 biasProjMatInv;
void main (void)
{
float ssao = 0.0;
float depth = texture2D(depthTex, gl_TexCoord[0].st).r;
if(depth < 1.0)
{
vec3 dir = normalize(texture2D(unitVecTex, gl_TexCoord[1].st).rgb * 2.0f - 1.0f);
vec3 n = normalize(texture2D(normalTex, gl_TexCoord[0].st).rgb * 2.0f - 1.0f);
vec4 myPosEye = biasProjMatInv * vec4(gl_TexCoord[0].st, depth, 1.0f);
myPosEye.xyz /= myPosEye.w;
vec3 t0 = normalize(dir - n * dot(dir, n));
vec3 t1 = cross(n, t0);
mat3x3 rmat = mat3x3(t0, t1, n);
for(int i = 0; i < NUMSAMPLES; i++)
{
vec3 samplePosEye = rmat * samples[i] + myPosEye.xyz;
vec4 samplePosScreen = biasProjMat * vec4(samplePosEye, 1.0f);
samplePosScreen.xyz /= samplePosScreen.w;
float sampleDepth = texture2D(depthTex, samplePosScreen.st).r;
if(sampleDepth < samplePosScreen.z)
{
vec4 surfacePosWorld = biasProjMatInv * vec4(samplePosScreen.st, sampleDepth, 1.0f);
surfacePosWorld.xyz /= surfacePosWorld.w;
vec3 p2p = surfacePosWorld.xyz - myPosEye.xyz;
ssao += 1.0f / (BIAS+dot(p2p, p2p));
}
}
ssao = 1.0f - ssao * iNUMSAMPLES;
} else {
ssao = 1.0f;
}
gl_FragColor = vec4(ssao,ssao,ssao,1.0f);
}

7
kaplademo/externals/resources/ssao.vs vendored Normal file
View File

@ -0,0 +1,7 @@
uniform vec2 scaleXY;
void main(void)
{
gl_TexCoord[0] = gl_Vertex;
gl_TexCoord[1] = vec4(gl_Vertex.xy * scaleXY, gl_Vertex.zw);
gl_Position = gl_Vertex * 2.0f - 1.0f;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB