FragShader.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // This file was created by Filewrap 1.1
  2. // Little endian mode
  3. // DO NOT EDIT
  4. #include "../PVRTMemoryFileSystem.h"
  5. // using 32 bit to guarantee alignment.
  6. #ifndef A32BIT
  7. #define A32BIT static const unsigned int
  8. #endif
  9. // ******** Start: FragShader.fsh ********
  10. // File data
  11. static const char _FragShader_fsh[] =
  12. "uniform sampler2D\t\tNormalTex;\r\n"
  13. "uniform sampler2D\t\tReflectionTex;\r\n"
  14. "#ifdef ENABLE_REFRACTION\r\n"
  15. "\tuniform sampler2D\t\tRefractionTex;\r\n"
  16. "#endif\r\n"
  17. "uniform samplerCube NormalisationCubeMap;\r\n"
  18. "\r\n"
  19. "uniform mediump mat4\tModelViewMatrix;\r\n"
  20. "uniform lowp vec4\t\tWaterColour;\r\n"
  21. "#ifdef ENABLE_DISTORTION\r\n"
  22. "\tuniform mediump float\tWaveDistortion;\r\n"
  23. "#endif\r\n"
  24. "uniform mediump vec2 \tRcpWindowSize;\r\n"
  25. "\r\n"
  26. "varying mediump vec2 \tBumpCoord0;\r\n"
  27. "varying mediump vec2 \tBumpCoord1;\r\n"
  28. "varying mediump vec3\tWaterToEye;\r\n"
  29. "varying mediump float\tWaterToEyeLength;\r\n"
  30. "\r\n"
  31. "void main()\r\n"
  32. "{\t\r\n"
  33. "\t// Calculate the tex coords of the fragment (using it's position on the screen)\r\n"
  34. "\tlowp vec3 vAccumulatedNormal = vec3(0.0,1.0,0.0);\r\n"
  35. "\tmediump vec2 vTexCoord = gl_FragCoord.xy * RcpWindowSize;\r\n"
  36. "\t\r\n"
  37. "\t#ifdef ENABLE_DISTORTION\r\n"
  38. "\t\t// When distortion is enabled, use the normal map to calculate perturbation\r\n"
  39. "\t\tvAccumulatedNormal = texture2D(NormalTex, BumpCoord0).rgb;\r\n"
  40. "\t\tvAccumulatedNormal += texture2D(NormalTex, BumpCoord1).rgb;\r\n"
  41. "\t\tvAccumulatedNormal -= 1.0; // Same as * 2.0 - 2.0\r\n"
  42. "\t\r\n"
  43. "\t\tlowp vec2 vTmp = vAccumulatedNormal.xz;\r\n"
  44. "\t\t/* \t\r\n"
  45. "\t\t\tDivide by WaterToEyeLength to scale down the distortion\r\n"
  46. "\t\t \tof fragments based on their distance from the camera \r\n"
  47. "\t\t*/\r\n"
  48. "\t\tvTexCoord.xy -= vTmp * (WaveDistortion / length(WaterToEye));\r\n"
  49. "\t#endif\r\n"
  50. "\r\n"
  51. "#ifdef ENABLE_REFRACTION\r\n"
  52. "\tlowp vec4 vReflectionColour = texture2D(ReflectionTex, vTexCoord);\r\n"
  53. "\tlowp vec4 vRefractionColour = texture2D(RefractionTex, vTexCoord);\r\n"
  54. "\t\r\n"
  55. "\t#ifdef ENABLE_FRESNEL\r\n"
  56. "\t\t// Calculate the Fresnel term to determine amount of reflection for each fragment\r\n"
  57. "\t\t\r\n"
  58. "\t\t// Use normalisation cube map instead of normalize() - See section 3.3.1 of white paper for more info\r\n"
  59. "\t\tlowp vec3 vWaterToEyeCube = textureCube(NormalisationCubeMap,WaterToEye).rgb * 2.0 - 1.0;\r\n"
  60. "\r\n"
  61. "\t\tmediump float fEyeToNormalAngle = clamp(dot(vWaterToEyeCube, vAccumulatedNormal),0.0,1.0);\r\n"
  62. "\t\t\r\n"
  63. "\t\tmediump float fAirWaterFresnel = 1.0 - fEyeToNormalAngle;\r\n"
  64. "\t\tfAirWaterFresnel = pow(fAirWaterFresnel, 5.0);\r\n"
  65. "\t\tfAirWaterFresnel = (0.98 * fAirWaterFresnel) + 0.02;\t// R(0)-1 = ~0.98 , R(0)= ~0.02\r\n"
  66. "\t\tlowp float fTemp = fAirWaterFresnel;\r\n"
  67. "\t\t\r\n"
  68. "\t\t// Blend reflection and refraction\r\n"
  69. "\t\tgl_FragColor = mix(vRefractionColour, vReflectionColour, fTemp);\r\n"
  70. "\t#else\r\n"
  71. "\t\tgl_FragColor = mix(vRefractionColour, vReflectionColour, 0.4);\t// Constant mix\r\n"
  72. "\t#endif\r\n"
  73. "#else\r\n"
  74. "\tgl_FragColor = texture2D(ReflectionTex, vTexCoord);\t\t\t\t\t// Reflection only\r\n"
  75. "#endif\r\n"
  76. "}\r\n";
  77. // Register FragShader.fsh in memory file system at application startup time
  78. static CPVRTMemoryFileSystem RegisterFile_FragShader_fsh("FragShader.fsh", _FragShader_fsh, 2388);
  79. // ******** End: FragShader.fsh ********
  80. // This file was created by Filewrap 1.1
  81. // Little endian mode
  82. // DO NOT EDIT
  83. #include "../PVRTMemoryFileSystem.h"
  84. // using 32 bit to guarantee alignment.
  85. #ifndef A32BIT
  86. #define A32BIT static const unsigned int
  87. #endif
  88. // ******** Start: FragShader.fsc ********
  89. // File data
  90. A32BIT _FragShader_fsc[] = {
  91. 0x10fab438,0xae9474a9,0x30050100,0x2501,0xd363e337,0x2000000,0x20000000,0xc2030000,0x1000000,0x4000000,0x0,0x0,0x56,0x0,0x0,0x0,0x0,0x80010000,0x55535020,0x20,0x174,0x1,0x0,0x0,0x224,0x80,0x2,0x7d,0x0,0x8,0x0,0xffffffff,0x0,0x770009,0xffff,0x2,0x0,0x10000,0x6,0x0,0x0,0x0,0x0,0x3fffc,0x40000,0x1,0x0,0xffff0003,0xffffffff,0x30000,0x800000,0x4,0x2000e,0x20001,0x40002,0x0,0x50002,0x100000,0x80002,0x1,0x90002,0x100001,0xa0002,0x2,
  92. 0xb0002,0x100002,0xffffffff,0xffffffff,0x0,0x0,0x4,0x20003,0x60000,0x80010002,0x80018001,0x8001,0x0,0x40000,0x40004,0x40004,0x10004,0x1d7ea000,0x168b4000,0x100e7020,0x568a3002,0x10867000,0x16b03002,0x11065000,0x3003,0x1b72a022,0x44b04001,0x1006d000,0x53001,0x0,0x80010002,0x80018001,0x8001,0x0,0x100000,0xf0000,0x60a000f,0x30003,0x30003,0x0,0x0,0x40004,0x40004,0x10000,0x30002,0x10001,0x0,0xa0000000,0xe003140c,0x6,0x80010000,0x55535020,0x20,0x174,0x1,0x0,0x0,0x2a4,0x80,0x2,0x7d,0x0,0x8,0x0,
  93. 0xffffffff,0x0,0x770009,0xffff,0x20002,0x0,0x10000,0x6,0x0,0x0,0x0,0x0,0x1fffc,0x40000,0x1,0x0,0xffff0003,0xffffffff,0x30000,0x800000,0x4,0x2000e,0x20001,0x40002,0x0,0x50002,0x100000,0x80002,0x1,0x90002,0x100001,0xa0002,0x2,0xb0002,0x100002,0xffffffff,0xffffffff,0x0,0x0,0x4,0x20003,0x60000,0x80010002,0x80018001,0x8001,0x0,0x40000,0x40004,0x40004,0x10004,0x1d7ca000,0x168b4000,0x10087020,0x568a3002,0x10807000,0x16b03002,0x11005000,0x3003,0x1b702022,0x44b04001,0x1000d000,0x53001,0x0,0x80010002,
  94. 0x80018001,0x8001,0x0,0x0,0xf0000,0x60a000f,0x10001,0x10001,0x0,0x0,0x40004,0x40004,0x10000,0x30002,0x10001,0x0,0xa0000000,0xe0031408,0x6,0xc00,0x803f0000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3000000,0x57706352,0x6f646e69,0x7a695377,0x65,0x20303,0x100,0x2040001,0x300,0x6c666552,0x69746365,0x65546e6f,0x78,0x10318,0x100,0x1000002,0x100,0x505f6c67,0x6f50584d,0x6a644173,0x747375,0x3055700,0x1000002,0x10000,0xf000408,0x0,
  95. };
  96. // Register FragShader.fsc in memory file system at application startup time
  97. static CPVRTMemoryFileSystem RegisterFile_FragShader_fsc("FragShader.fsc", _FragShader_fsc, 994);
  98. // ******** End: FragShader.fsc ********