亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 9256 | 回復(fù): 14
打印 上一主題 下一主題

[Perl]使用 POGL Shader 實(shí)現(xiàn)高效渲染 Julia集 動畫 [復(fù)制鏈接]

論壇徽章:
12
子鼠
日期:2014-10-11 16:46:482016科比退役紀(jì)念章
日期:2018-03-16 10:24:0515-16賽季CBA聯(lián)賽之山東
日期:2017-11-10 14:32:142016科比退役紀(jì)念章
日期:2017-09-02 15:42:4715-16賽季CBA聯(lián)賽之佛山
日期:2017-08-28 17:11:5515-16賽季CBA聯(lián)賽之浙江
日期:2017-08-24 16:55:1715-16賽季CBA聯(lián)賽之青島
日期:2017-08-17 19:55:2415-16賽季CBA聯(lián)賽之天津
日期:2017-06-29 10:34:4315-16賽季CBA聯(lián)賽之四川
日期:2017-05-16 16:38:55黑曼巴
日期:2016-07-19 15:03:112015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-05-22 11:38:5315-16賽季CBA聯(lián)賽之北京
日期:2019-08-13 17:30:53
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2017-07-24 15:23 |只看該作者 |倒序?yàn)g覽
推薦 Perl 環(huán)境:5.24 Portable Edition
官方鏈接:Strawberry Perl Releases

Portable 版環(huán)境配置說明:Strawberry Perl 環(huán)境配置 以及 版本推薦

需要安裝的模塊:
https://metacpan.org/release/OpenGL
https://metacpan.org/pod/OpenGL::Shader

PDL版本的Strawberry Perl 雖然自帶OPENGL模塊,但是加載 Shader 有問題,最好下載源碼包重新編譯安裝。



      =info
          Auth:523066680
          Date:2017-07
          https://www.shadertoy.com/view/ld2fzw

          按 '['']' 調(diào)整閥值,按 -= 調(diào)整迭代深度
          空格鍵 - 暫停/繼續(xù)
          q or Q - 退出
      =cut

      use OpenGL qw/ :all /;
      use OpenGL::Config;
      use OpenGL::Shader;
      use Time::HiRes 'sleep';
      use feature 'state';
      use IO::Handle;
      STDOUT->autoflush(1);

      our $ang = 0.0;
      our $iter = 1000.0;
      our $test = 80.0;
      our ($cx, $cy);
      our $vTest;
      our $vIter;
      our $vC;

      our $PAUSE = 0;

      &Main();

      sub display
      {
          glClear(GL_COLOR_BUFFER_BIT);
          glDrawArrays(GL_POINTS, 0, 1);
          glutSwapBuffers();
      }

      sub idle
      {
          sleep 0.03;

          $ang += 0.05 if ($PAUSE == 0);
          $cx = cos($ang);
          $cy = sin($ang);

          glVertexAttrib2fARB($vC, $cx, $cy);

          glutPostRedisplay();
      }

      sub init
      {
          glClearColor(0.0, 0.0, 0.0, 1.0);
          my $shdr = new OpenGL::Shader('GLSL');
          my $ver = $shdr->GetVersion();
          my $stat = $shdr->Load( frag_Shader(), vert_Shader() );
          $shdr->Enable();

          #如果 shader 編譯不成功,錯(cuò)誤信息會返回到 $stat
          print "$stat $ver\n";
          glPointSize(480.0);
         
          $vTest = $shdr->MapAttr('vTest');
          $vIter = $shdr->MapAttr('vIter');
          $vC = $shdr->MapAttr('vC');

          glVertexAttrib1fARB($vTest, $test);
          glVertexAttrib1fARB($vIter, $iter);
          glVertexAttrib2fARB($vC, $cx, $cy);
      }

      sub hitkey
      {
          my $key = shift;
          my $char = chr($key);

          if ( lc($char) eq 'q' ) { glutDestroyWindow($WinID) }
          elsif ($char eq '[')  { $test -= 1.0 if ( $test > 1.0 ) }
          elsif ($char eq ']')  { $test += 1.0 }
          elsif ($char eq '-')  { $iter -= $iter*0.2 if ( $iter > 1.0 ) }
          elsif ($char eq '=')  { $iter += $iter*0.2  }
          elsif ($char eq ' ')  { $PAUSE = 1 - $PAUSE }

          printf("test: %.2f, iter: %.2f\n", $test, $iter );
          glVertexAttrib1fARB($vTest, $test);
          glVertexAttrib1fARB($vIter, $iter);
      }

      sub Main
      {
          glutInit();
          glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE );
          glutInitWindowSize(500, 500);
          glutInitWindowPosition(1,1);
          our $WinID = glutCreateWindow("title");
          &init();
          glutDisplayFunc(\&display);
          glutKeyboardFunc(\&hitkey);
          glutIdleFunc(\&idle);
          glutMainLoop();
      }

      sub frag_Shader
      {
          return '
          varying float fTest;
          varying float fIter;
          varying vec2 fC;

          void main(void)
          {
              vec2 coord = (gl_FragCoord.xy - 250.0) / 100.0;

              vec4 color;
              vec2 C = fC;
              vec2 Z = coord.xy;

              int iterations = 0;
              int max_iterations = int(fIter);

              float rate;
              float threshold_squared = fTest;

              while ( (iterations < max_iterations) && (dot(Z, Z) < threshold_squared) )
              {
                  vec2 tZ;
                  tZ.x = Z.x * Z.x - Z.y * Z.y + C.x;
                  tZ.y = Z.x * Z.y * 2.0 + C.y;
                  Z = tZ;
                  iterations++;
              }

              if (iterations == max_iterations)
              {
                  color = vec4(0.3, 0.1, 0.1, 1.0);
              }
              else
              {
                  rate =  float(iterations)/float(max_iterations)*100.0;
                  //color = vec4(rate, rate, rate, 1.0);  //default color
                  color = vec4(rate, smoothstep(exp(Z.x), 0.0, 0.5), rate, 1.0);
              }

              gl_FragColor = color;
          }
          '
      }

      sub vert_Shader
      {
          return '
          attribute float vTest;
          attribute float vIter;
          attribute vec2 vC;

          varying float fTest;
          varying float fIter;
          varying vec2 fC;

          void main(void)
          {
              fTest = vTest;
              fIter = vIter;
              fC    = vC;

              gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
          }
          ';
      }
[Finished in 0.3s]

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2017-07-24 22:28 |只看該作者
本帖最后由 hztj2005 于 2017-07-29 12:55 編輯

我想學(xué)習(xí)下,下載OpenGL-0.70安裝后,說時(shí)間戳沒有更新,不知是否重要,又如何手動更新?
D:\strawberryportable\OpenGL-0.70>dmake install
"D:\strawberryportable\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- OpenGL.bs blib\arch\auto\OpenGL\OpenGL.bs 644
Files found in blib\arch: installing files in blib\lib into architecture dependent library tree
Installing D:\strawberryportable\perl\site\lib\auto\OpenGL\freeglut.dll
Installing D:\strawberryportable\perl\site\lib\auto\OpenGL\OpenGL.xs.dll
Installing D:\strawberryportable\perl\site\lib\OpenGL.pm
Installing D:\strawberryportable\perl\site\lib\OpenGL.pod
Installing D:\strawberryportable\perl\site\lib\auto\OpenGL\autosplit.ix
Installing D:\strawberryportable\perl\site\lib\OpenGL\Array.pod
Installing D:\strawberryportable\perl\site\lib\OpenGL\Config.pm
Installing D:\strawberryportable\perl\site\lib\OpenGL\Tessellation.pod
Appending installation info to D:\strawberryportable\perl\lib/perllocal.pod
dmake:  Warning: -- Target [install] was made but the time stamp has not been updated.


接著,下載OpenGL-Shader-1.01,安裝不能通過測試。#version directive missing

D:\strawberryportable\OpenGL-Shader-1.01>dmake test
"D:\strawberryportable\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/OpenGL-Shader.t ..
________________________________________
Testing OpenGL::Shader
----------------------------------------
* ok: Installed: OpenGL v0.7
* ok: OpenGL::Shader module loaded: v1.01
Available shader types:
  ARB v1.0 - ARBfp1.0 and ARBvp1.0 Assembly
  GLSL v4.40 - OpenGL Shader Language
* ok: 2 shader type(s) reported
Use of uninitialized value $type in uc at D:\strawberryportable\OpenGL-Shader-1.01\blib\lib/OpenGL/Shader/Common.pm line 109.
Instantiated ARB v1.0
* ok: Loaded ARB shader from: fragment.arb, vertex.arb
Use of uninitialized value $type in uc at D:\strawberryportable\OpenGL-Shader-1.01\blib\lib/OpenGL/Shader/Common.pm line 109.
Instantiated GLSL v4.40
* fail: Unable to load GLSL shader: Fragment shader: WARNING: 0:2: '' :  #version directive missing

* skip: CG shader test
________________________________________
t/OpenGL-Shader.t .. Failed 1/6 subtests
        (less 1 skipped subtest: 4 okay)
Test Summary Report
-------------------
t/OpenGL-Shader.t (Wstat: 0 Tests: 6 Failed: 1)
  Failed test:  5
Files=1, Tests=6,  0 wallclock secs ( 0.05 usr +  0.02 sys =  0.06 CPU)
Result: FAIL
Failed 1/1 test programs. 1/6 subtests failed.
dmake:  Error code 255, while making 'test_dynamic'

論壇徽章:
12
子鼠
日期:2014-10-11 16:46:482016科比退役紀(jì)念章
日期:2018-03-16 10:24:0515-16賽季CBA聯(lián)賽之山東
日期:2017-11-10 14:32:142016科比退役紀(jì)念章
日期:2017-09-02 15:42:4715-16賽季CBA聯(lián)賽之佛山
日期:2017-08-28 17:11:5515-16賽季CBA聯(lián)賽之浙江
日期:2017-08-24 16:55:1715-16賽季CBA聯(lián)賽之青島
日期:2017-08-17 19:55:2415-16賽季CBA聯(lián)賽之天津
日期:2017-06-29 10:34:4315-16賽季CBA聯(lián)賽之四川
日期:2017-05-16 16:38:55黑曼巴
日期:2016-07-19 15:03:112015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-05-22 11:38:5315-16賽季CBA聯(lián)賽之北京
日期:2019-08-13 17:30:53
3 [報(bào)告]
發(fā)表于 2017-07-25 11:27 |只看該作者

各種魔改公式后生成的圖片

Sharp
  
迭代公式:
uZ.x = exp(tZ.x) * cos(tZ.y) * C.x;
uZ.y = exp(tZ.x) * sin(tZ.y) * C.y;

Julia之眼

迭代公式:
tZ.x = Z.x * Z.x - Z.y * Z.y + C.x;
tZ.y = Z.x * Z.y * 2.0 + C.y;
著色:
color = vec4(rate, exp(Z.x), rate, 1.0);

機(jī)械臂

tZ.x = Z.x * Z.x - Z.y * Z.y + C.x;
tZ.y = Z.x * Z.y * 1.0 + C.y;
著色:
color = vec4(rate, exp(Z.x), rate, 1.0);

圖騰


Z=Z^3+C

浩瀚



旋轉(zhuǎn)的階梯

論壇徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龍
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥豬
日期:2014-04-01 08:56:02亥豬
日期:2014-04-08 08:38:58程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-05 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-07 06:20:00
4 [報(bào)告]
發(fā)表于 2017-07-25 20:46 |只看該作者
lz威武。

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
5 [報(bào)告]
發(fā)表于 2017-07-26 23:09 |只看該作者
O~~ BTF!!
3 Q ~~:

論壇徽章:
12
子鼠
日期:2014-10-11 16:46:482016科比退役紀(jì)念章
日期:2018-03-16 10:24:0515-16賽季CBA聯(lián)賽之山東
日期:2017-11-10 14:32:142016科比退役紀(jì)念章
日期:2017-09-02 15:42:4715-16賽季CBA聯(lián)賽之佛山
日期:2017-08-28 17:11:5515-16賽季CBA聯(lián)賽之浙江
日期:2017-08-24 16:55:1715-16賽季CBA聯(lián)賽之青島
日期:2017-08-17 19:55:2415-16賽季CBA聯(lián)賽之天津
日期:2017-06-29 10:34:4315-16賽季CBA聯(lián)賽之四川
日期:2017-05-16 16:38:55黑曼巴
日期:2016-07-19 15:03:112015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-05-22 11:38:5315-16賽季CBA聯(lián)賽之北京
日期:2019-08-13 17:30:53
6 [報(bào)告]
發(fā)表于 2017-07-28 21:43 |只看該作者
Colorful


  

Mandbrot: Z=Z^4+C

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2017-07-31 11:33 |只看該作者
樓主,我在2樓說到,安裝 OpenGL::Shader不能通過測試,然后我在下面鏈接中發(fā)帖問,仍然沒有成功。
http://www.perlmonks.com/?node_id=1196261
但是,上面鏈接中有這么一段建議:
A somewhat more recent version of OpenGL bindings is OpenGL::Modern, which also tries to be compatible to OpenGL and OpenGL::Shader, so maybe you want to try that if you want to do shader oriented programming.
與OpenGL相綁定的某種程度更新版本是OpenGL :: Modern,它也嘗試兼容OpenGL和OpenGL :: Shader,所以也許你想嘗試這樣做,如果你想做著色器方向編程。

樓主能否嘗試一下,把上面代碼用OpenGL::Modern模塊修改一下。

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2017-07-31 11:47 |只看該作者
樓主,我從安裝包中D:\strawberryportable\OpenGL-Shader-1.01\blib\lib\OpenGL 找到的下面代碼: shader-test.pl 是可以運(yùn)行的。

  1. #!/usr/bin/perl

  2. # Purpose: Simple demo of per-pixel lighting with GLSL and OpenGL::Shader

  3. # Copyright (c) 2007, Geoff Broadwell; this script is released
  4. # as open source and may be distributed and modified under the terms
  5. # of either the Artistic License or the GNU General Public License,
  6. # in the same manner as Perl itself.  These licenses should have been
  7. # distributed to you as part of your Perl distribution, and can be
  8. # read using `perldoc perlartistic` and `perldoc perlgpl` respectively.

  9. use strict;
  10. use warnings;
  11. use OpenGL ':all';
  12. use OpenGL::Shader;
  13. use Time::HiRes 'time';

  14. our $VERSION = '0.1.0';

  15. my $width  = 1000;
  16. my $height = 1000;
  17. my ($frames, $start);
  18. my ($window, $teapot);
  19. my ($shader, $shader_enabled);

  20. go();

  21. sub go {
  22.     # Simple usage
  23.     print "Press 'Q' or 'Esc' to exit, or any other key to toggle shader.\n";

  24.     # GLUT setup
  25.     glutInit;
  26.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  27.     glutInitWindowSize($width, $height);

  28.     $window = glutCreateWindow('Shader Test');

  29.     glutIdleFunc    (\&cb_draw);
  30.     glutDisplayFunc (\&cb_draw);
  31.     glutKeyboardFunc(\&cb_keyboard);

  32.     # Shader program
  33.     $shader      = new OpenGL::Shader('GLSL');
  34.     die "This program requires support for GLSL shaders.\n" unless $shader;

  35.     my $fragment = fragment_shader();
  36.     my $vertex   = vertex_shader();
  37.     my $info     = $shader->Load($fragment, $vertex);
  38.     print $info if $info;
  39.     toggle_shader();

  40.     # Display list for teapot
  41.     $teapot = glGenLists(1);
  42.     glNewList($teapot, GL_COMPILE);
  43.     glutSolidTeapot(1);
  44.     glEndList;

  45.     # Unchanging GL config
  46.     glViewport(0, 0, $width, $height);

  47.     glEnable(GL_DEPTH_TEST);

  48.     glMatrixMode(GL_PROJECTION);
  49.     glLoadIdentity;
  50.     gluPerspective(90, $width/$height, 1, 10);
  51.     glMatrixMode(GL_MODELVIEW);

  52.     glShadeModel(GL_SMOOTH);
  53.     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
  54.     glEnable(GL_LIGHTING);
  55.     glEnable(GL_LIGHT0);
  56.     glLightfv_p(GL_LIGHT0, GL_POSITION, 4, 4, 4, 1);

  57.     glMaterialfv_p(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, 1, .7, .7, 1);
  58.     glMaterialfv_p(GL_FRONT_AND_BACK, GL_SPECULAR,            1,  1,  1, 1);
  59.     glMaterialf   (GL_FRONT_AND_BACK, GL_SHININESS,           50          );

  60.     # Actually start the test
  61.     $start = time;
  62.     glutMainLoop;
  63. }

  64. sub cb_draw {
  65.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  66.     glLoadIdentity;
  67.     glTranslatef(0, 0, -3);

  68.     my $slow_time = time / 5;
  69.     my $frac_time = $slow_time - int $slow_time;
  70.     my $angle     = $frac_time * 360;
  71.     glRotatef($angle, 0, 1, 0);
  72.     glRotatef(30, 1, 0, 0);

  73.     glCallList($teapot);

  74.     glutSwapBuffers;

  75.     $frames++;
  76. }

  77. sub cb_keyboard {
  78.     my $key = shift;
  79.     my $chr = lc chr $key;

  80.     if ($key == 27 or $chr eq 'q') {
  81.         my $time = time - $start;
  82.         my $fps  = $frames / $time;
  83.         printf "%.3f FPS\n", $fps;

  84.         glutDestroyWindow($window);
  85.         exit(0);
  86.     }
  87.     else {
  88.         toggle_shader();
  89.     }
  90. }

  91. sub toggle_shader {
  92.     $shader_enabled = !$shader_enabled;
  93.     $shader_enabled ? $shader->Enable : $shader->Disable;
  94. }

  95. sub vertex_shader {
  96.     return <<'VERTEX';

  97. varying vec3 Normal;
  98. varying vec3 Position;

  99. void main(void) {
  100.     gl_Position = ftransform();
  101.     Position    = vec3(gl_ModelViewMatrix * gl_Vertex);
  102.     Normal      = gl_NormalMatrix * gl_Normal;
  103. }

  104. VERTEX
  105. }

  106. sub fragment_shader {
  107.     return <<'FRAGMENT';

  108. varying vec3 Position;
  109. varying vec3 Normal;

  110. void main(void) {
  111.     vec3 normal    = normalize(Normal);
  112.     vec3 reflected = normalize(reflect(Position, normal));
  113.     vec3 light_dir = normalize(vec3(gl_LightSource[0].position) - Position);

  114.     float diffuse  = max  (dot(light_dir, normal   ), 0.0);
  115.     float spec     = clamp(dot(light_dir, reflected), 0.0, 1.0);
  116.           spec     = pow  (spec, gl_FrontMaterial.shininess);

  117.     gl_FragColor   =             gl_FrontLightModelProduct.sceneColor
  118.                      +           gl_FrontLightProduct[0].ambient
  119.                      + diffuse * gl_FrontLightProduct[0].diffuse
  120.                      + spec    * gl_FrontLightProduct[0].specular;
  121. }

  122. FRAGMENT
  123. }
復(fù)制代碼

論壇徽章:
12
子鼠
日期:2014-10-11 16:46:482016科比退役紀(jì)念章
日期:2018-03-16 10:24:0515-16賽季CBA聯(lián)賽之山東
日期:2017-11-10 14:32:142016科比退役紀(jì)念章
日期:2017-09-02 15:42:4715-16賽季CBA聯(lián)賽之佛山
日期:2017-08-28 17:11:5515-16賽季CBA聯(lián)賽之浙江
日期:2017-08-24 16:55:1715-16賽季CBA聯(lián)賽之青島
日期:2017-08-17 19:55:2415-16賽季CBA聯(lián)賽之天津
日期:2017-06-29 10:34:4315-16賽季CBA聯(lián)賽之四川
日期:2017-05-16 16:38:55黑曼巴
日期:2016-07-19 15:03:112015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-05-22 11:38:5315-16賽季CBA聯(lián)賽之北京
日期:2019-08-13 17:30:53
9 [報(bào)告]
發(fā)表于 2017-07-31 14:32 |只看該作者
回復(fù) 8# hztj2005

那就更省事啦~ 我的可能是有什么變動導(dǎo)致……

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
10 [報(bào)告]
發(fā)表于 2017-08-02 01:42 |只看該作者
本帖最后由 rubyish 于 2017-08-01 21:45 編輯



1: ppm

評分

參與人數(shù) 1信譽(yù)積分 +5 收起 理由
523066680 + 5 贊一個(gè)!

查看全部評分

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP