fragment_shaders.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. typedef struct FragmentTestRec {
  2. const char * name;
  3. uint32_t texCount;
  4. const char * txt;
  5. } FragmentTest;
  6. static FragmentTest fpFill = {
  7. "Solid color", 0,
  8. "precision mediump float;\n"
  9. "uniform vec4 u_color;\n"
  10. "void main() {\n"
  11. " gl_FragColor = u_color;\n"
  12. "}\n"
  13. };
  14. static FragmentTest fpGradient = {
  15. "Solid gradient", 0,
  16. "precision mediump float;\n"
  17. "varying lowp vec4 v_color;\n"
  18. "void main() {\n"
  19. " gl_FragColor = v_color;\n"
  20. "}\n"
  21. };
  22. static FragmentTest fpCopyTex = {
  23. "Texture copy", 1,
  24. "precision mediump float;\n"
  25. "varying vec2 v_tex0;\n"
  26. "uniform sampler2D u_tex0;\n"
  27. "void main() {\n"
  28. " gl_FragColor = texture2D(u_tex0, v_tex0);\n"
  29. "}\n"
  30. };
  31. static FragmentTest fpCopyTexGamma = {
  32. "Texture copy with gamma", 1,
  33. "precision mediump float;\n"
  34. "varying vec2 v_tex0;\n"
  35. "uniform sampler2D u_tex0;\n"
  36. "void main() {\n"
  37. " vec4 t = texture2D(u_tex0, v_tex0);\n"
  38. " t.rgb = pow(t.rgb, vec3(1.4, 1.4, 1.4));\n"
  39. " gl_FragColor = t;\n"
  40. "}\n"
  41. };
  42. static FragmentTest fpTexSpec = {
  43. "Texture spec", 1,
  44. "precision mediump float;\n"
  45. "varying vec2 v_tex0;\n"
  46. "uniform sampler2D u_tex0;\n"
  47. "void main() {\n"
  48. " vec4 t = texture2D(u_tex0, v_tex0);\n"
  49. " float simSpec = dot(gl_FragCoord.xyz, gl_FragCoord.xyz);\n"
  50. " simSpec = pow(clamp(simSpec, 0.1, 1.0), 40.0);\n"
  51. " gl_FragColor = t + vec4(simSpec, simSpec, simSpec, simSpec);\n"
  52. "}\n"
  53. };
  54. static FragmentTest fpDepTex = {
  55. "Dependent Lookup", 1,
  56. "precision mediump float;\n"
  57. "varying vec2 v_tex0;\n"
  58. "uniform sampler2D u_tex0;\n"
  59. "void main() {\n"
  60. " vec4 t = texture2D(u_tex0, v_tex0);\n"
  61. " t += texture2D(u_tex0, t.xy);\n"
  62. " gl_FragColor = t;\n"
  63. "}\n"
  64. };
  65. static FragmentTest fpModulateConstantTex = {
  66. "Texture modulate constant", 1,
  67. "precision mediump float;\n"
  68. "varying vec2 v_tex0;\n"
  69. "uniform sampler2D u_tex0;\n"
  70. "uniform vec4 u_color;\n"
  71. "void main() {\n"
  72. " lowp vec4 c = texture2D(u_tex0, v_tex0);\n"
  73. " c *= u_color;\n"
  74. " gl_FragColor = c;\n"
  75. "}\n"
  76. };
  77. static FragmentTest fpModulateVaryingTex = {
  78. "Texture modulate gradient", 1,
  79. "precision mediump float;\n"
  80. "varying vec2 v_tex0;\n"
  81. "varying lowp vec4 v_color;\n"
  82. "uniform sampler2D u_tex0;\n"
  83. "void main() {\n"
  84. " lowp vec4 c = texture2D(u_tex0, v_tex0);\n"
  85. " c *= v_color;\n"
  86. " gl_FragColor = c;\n"
  87. "}\n"
  88. };
  89. static FragmentTest fpModulateVaryingConstantTex = {
  90. "Texture modulate gradient constant", 1,
  91. "precision mediump float;\n"
  92. "varying vec2 v_tex0;\n"
  93. "varying lowp vec4 v_color;\n"
  94. "uniform sampler2D u_tex0;\n"
  95. "uniform vec4 u_color;\n"
  96. "void main() {\n"
  97. " lowp vec4 c = texture2D(u_tex0, v_tex0);\n"
  98. " c *= v_color;\n"
  99. " c *= u_color;\n"
  100. " gl_FragColor = c;\n"
  101. "}\n"
  102. };
  103. static FragmentTest *gFragmentTests[] = {
  104. &fpFill,
  105. &fpGradient,
  106. &fpCopyTex,
  107. &fpCopyTexGamma,
  108. &fpTexSpec,
  109. &fpDepTex,
  110. &fpModulateConstantTex,
  111. &fpModulateVaryingTex,
  112. &fpModulateVaryingConstantTex,
  113. };
  114. static const size_t gFragmentTestCount = sizeof(gFragmentTests) / sizeof(gFragmentTests[0]);