@@ -8,17 +8,42 @@ void main()
88{
99 vec2 sphereCenter = v_sphereParams.xy;
1010 float sphereSize = v_sphereParams.z;
11- float fDistanceToCenter = length(v_screenSpacePosition - sphereCenter);
11+ float fDistanceToCenter = length(v_screenSpacePosition.xy - sphereCenter);
1212 if (fDistanceToCenter > sphereSize)
1313 discard;
1414
1515 int color = int(v_texcoord0.x * 15 .f);
1616 int bank = int(v_texcoord0.y * 15 .f);
17+ int material = (int)v_sphereParams.w;
1718
18- int colorOffset = (bank << 4 ) + color;
19+ if (material == 0 ) { // flat
20+ int colorOffset = (bank << 4 ) + color;
21+ gl_FragColor.r = (texelFetch(s_paletteTexture, ivec2(0 , colorOffset), 0 ) / 255 .f).r;
22+ gl_FragColor.g = (texelFetch(s_paletteTexture, ivec2(1 , colorOffset), 0 ) / 255 .f).r;
23+ gl_FragColor.b = (texelFetch(s_paletteTexture, ivec2(2 , colorOffset), 0 ) / 255 .f).r;
24+ gl_FragColor.w = 1 ;
25+ } else if (material == 2 ) { // transparent
26+ int colorOffset = (bank << 4 ) + color;
27+ gl_FragColor.r = (texelFetch(s_paletteTexture, ivec2(0 , colorOffset), 0 ) / 255 .f).r;
28+ gl_FragColor.g = (texelFetch(s_paletteTexture, ivec2(1 , colorOffset), 0 ) / 255 .f).r;
29+ gl_FragColor.b = (texelFetch(s_paletteTexture, ivec2(2 , colorOffset), 0 ) / 255 .f).r;
30+ gl_FragColor.w = 0.5 ;
31+ } else if (material == 3 ) { // marbre
32+ vec2 normalizedPosition = (v_screenSpacePosition.xy - sphereCenter.xy) / sphereSize;
33+ float angle = asin(normalizedPosition.y);
34+ float distanceToCircleOnScanline = cos(angle) - normalizedPosition.x; // value is in 0/2 range
35+ distanceToCircleOnScanline /= 2 .f; // remap to 0 / 1
36+ color = (1 .f - distanceToCircleOnScanline) * 15 .f;
1937
20- gl_FragColor.r = (texelFetch(s_paletteTexture, ivec2(0 , colorOffset), 0 ) / 255 .f).r;
21- gl_FragColor.g = (texelFetch(s_paletteTexture, ivec2(1 , colorOffset), 0 ) / 255 .f).r;
22- gl_FragColor.b = (texelFetch(s_paletteTexture, ivec2(2 , colorOffset), 0 ) / 255 .f).r;
23- gl_FragColor.w = 1 ;
38+ int colorOffset = (bank << 4 ) + color;
39+ gl_FragColor.r = (texelFetch(s_paletteTexture, ivec2(0 , colorOffset), 0 ) / 255 .f).r;
40+ gl_FragColor.g = (texelFetch(s_paletteTexture, ivec2(1 , colorOffset), 0 ) / 255 .f).r;
41+ gl_FragColor.b = (texelFetch(s_paletteTexture, ivec2(2 , colorOffset), 0 ) / 255 .f).r;
42+ gl_FragColor.w = 1 ;
43+ } else {
44+ gl_FragColor.r = 1 .f;
45+ gl_FragColor.g = 0 ;
46+ gl_FragColor.b = 0 ;
47+ gl_FragColor.w = 1 ;
48+ }
2449}
0 commit comments