| 448 | #if 1 |
| 449 | char vertexShaderSource[] = |
| 450 | "uniform vec3 dv_i;\n" |
| 451 | "uniform vec3 dv_j;\n" |
| 452 | "uniform vec3 dv_k;\n" |
| 453 | "\n" |
| 454 | "uniform float inversePeriod;\n" |
| 455 | "uniform vec4 particleColour;\n" |
| 456 | "uniform float particleSize;\n" |
| 457 | "\n" |
| 458 | "uniform float osg_FrameTime;\n" |
| 459 | "uniform float osg_DeltaFrameTime;\n" |
| 460 | "uniform mat4 previousModelViewMatrix;\n" |
| 461 | "\n" |
| 462 | "varying vec4 colour;\n" |
| 463 | "varying vec2 texCoord;\n" |
| 464 | "\n" |
| 465 | "void main(void)\n" |
| 466 | "{\n" |
| 467 | " vec3 pos = gl_Normal.xyz + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y);\n" |
| 468 | " \n" |
| 469 | " float offset = gl_Vertex.z;\n" |
| 470 | " texCoord = gl_MultiTexCoord0.xy;\n" |
| 471 | " float startTime = gl_MultiTexCoord1.x;\n" |
| 472 | "\n" |
| 473 | " vec3 v_previous = pos + dv_k * fract( (osg_FrameTime - startTime)*inversePeriod - offset);\n" |
| 474 | " vec3 v_current = v_previous + dv_k * (osg_DeltaFrameTime*inversePeriod);\n" |
| 475 | " \n" |
| 476 | " colour = particleColour;\n" |
| 477 | " \n" |
| 478 | " vec4 v1 = gl_ModelViewMatrix * vec4(v_current,1.0);\n" |
| 479 | " vec4 v2 = previousModelViewMatrix * vec4(v_previous,1.0);\n" |
| 480 | " \n" |
| 481 | " vec3 dv = v2.xyz - v1.xyz;\n" |
| 482 | " \n" |
| 483 | " vec2 dv_normalized = normalize(dv.xy);\n" |
| 484 | " dv.xy += dv_normalized * particleSize;\n" |
| 485 | " vec2 dp = vec2( -dv_normalized.y, dv_normalized.x ) * particleSize;\n" |
| 486 | " \n" |
| 487 | " float area = length(dv.xy);\n" |
| 488 | " colour.a = 0.05+(particleSize)/area;\n" |
| 489 | " \n" |
| 490 | "\n" |
| 491 | " v1.xyz += dv*texCoord.y;\n" |
| 492 | " v1.xy += dp*texCoord.x;\n" |
| 493 | " \n" |
| 494 | " gl_Position = gl_ProjectionMatrix * v1;\n" |
| 495 | "}\n"; |
| 496 | |
| 497 | char fragmentShaderSource[] = |
| 498 | "uniform sampler2D baseTexture;\n" |
| 499 | "varying vec2 texCoord;\n" |
| 500 | "varying vec4 colour;\n" |
| 501 | "\n" |
| 502 | "void main (void)\n" |
| 503 | "{\n" |
| 504 | " gl_FragColor = colour * texture2D( baseTexture, texCoord);\n" |
| 505 | "}\n"; |
| 506 | |
| 507 | program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); |
| 508 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); |
| 509 | #else |
| 527 | #if 1 |
| 528 | char vertexShaderSource[] = |
| 529 | "uniform vec3 dv_i;\n" |
| 530 | "uniform vec3 dv_j;\n" |
| 531 | "uniform vec3 dv_k;\n" |
| 532 | "\n" |
| 533 | "uniform float inversePeriod;\n" |
| 534 | "uniform vec4 particleColour;\n" |
| 535 | "uniform float particleSize;\n" |
| 536 | "\n" |
| 537 | "uniform float osg_FrameTime;\n" |
| 538 | "uniform float osg_DeltaFrameTime;\n" |
| 539 | "uniform mat4 previousModelViewMatrix;\n" |
| 540 | "\n" |
| 541 | "varying vec4 colour;\n" |
| 542 | "varying vec2 texCoord;\n" |
| 543 | "\n" |
| 544 | "void main(void)\n" |
| 545 | "{\n" |
| 546 | " vec3 pos = gl_Normal.xyz + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y);\n" |
| 547 | " \n" |
| 548 | "\n" |
| 549 | " float offset = gl_Vertex.z;\n" |
| 550 | " texCoord = gl_MultiTexCoord0.xy;\n" |
| 551 | " float startTime = gl_MultiTexCoord1.x;\n" |
| 552 | "\n" |
| 553 | " vec3 v_previous = pos + dv_k * fract( (osg_FrameTime - startTime)*inversePeriod - offset);\n" |
| 554 | " vec3 v_current = v_previous + dv_k * (osg_DeltaFrameTime*inversePeriod);\n" |
| 555 | " \n" |
| 556 | " colour = particleColour;\n" |
| 557 | " \n" |
| 558 | " vec4 v1 = gl_ModelViewMatrix * vec4(v_current,1.0);\n" |
| 559 | " vec4 v2 = previousModelViewMatrix * vec4(v_previous,1.0);\n" |
| 560 | " \n" |
| 561 | " vec3 dv = v2.xyz - v1.xyz;\n" |
| 562 | " \n" |
| 563 | " vec2 dv_normalized = normalize(dv.xy);\n" |
| 564 | " dv.xy += dv_normalized * particleSize;\n" |
| 565 | " \n" |
| 566 | " float area = length(dv.xy);\n" |
| 567 | " colour.a = 0.1+(particleSize)/area;\n" |
| 568 | " \n" |
| 569 | " v1.xyz += dv*texCoord.y;\n" |
| 570 | " \n" |
| 571 | " gl_Position = gl_ProjectionMatrix * v1;\n" |
| 572 | "}"; |
| 573 | |
| 574 | char fragmentShaderSource[] = |
| 575 | "uniform sampler2D baseTexture;\n" |
| 576 | "varying vec2 texCoord;\n" |
| 577 | "varying vec4 colour;\n" |
| 578 | "\n" |
| 579 | "void main (void)\n" |
| 580 | "{\n" |
| 581 | " gl_FragColor = colour * texture2D( baseTexture, texCoord);\n" |
| 582 | "}\n"; |
| 583 | |
| 584 | program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); |
| 585 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); |
| 586 | #else |
| 603 | #if 1 |
| 604 | char vertexShaderSource[] = |
| 605 | "uniform vec3 dv_i;\n" |
| 606 | "uniform vec3 dv_j;\n" |
| 607 | "uniform vec3 dv_k;\n" |
| 608 | "\n" |
| 609 | "uniform float inversePeriod;\n" |
| 610 | "uniform vec4 particleColour;\n" |
| 611 | "uniform float particleSize;\n" |
| 612 | "\n" |
| 613 | "uniform float osg_FrameTime;\n" |
| 614 | "\n" |
| 615 | "varying vec4 colour;\n" |
| 616 | "varying vec2 texCoord;\n" |
| 617 | "\n" |
| 618 | "void main(void)\n" |
| 619 | "{\n" |
| 620 | " vec3 pos = gl_Normal.xyz + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y);\n" |
| 621 | " texCoord = gl_MultiTexCoord0.xy;\n" |
| 622 | "\n" |
| 623 | " float startTime = gl_MultiTexCoord1.x;\n" |
| 624 | "\n" |
| 625 | " vec3 v_current = pos + dv_k * fract( (osg_FrameTime - startTime)*inversePeriod - gl_Vertex.z);\n" |
| 626 | " \n" |
| 627 | " colour = particleColour;\n" |
| 628 | "\n" |
| 629 | " gl_Position = gl_ModelViewProjectionMatrix * vec4(v_current,1.0);\n" |
| 630 | "\n" |
| 631 | " //float pointSize = min(abs(1280*particleSize / gl_Position.w), 20.0);\n" |
| 632 | " float pointSize = abs(1280*particleSize / gl_Position.w);\n" |
| 633 | " //gl_PointSize = max(ceil(pointSize),2);\n" |
| 634 | " gl_PointSize = ceil(pointSize);\n" |
| 635 | " \n" |
| 636 | " colour.a = 0.05+(pointSize*pointSize)/(gl_PointSize*gl_PointSize);\n" |
| 637 | "}\n"; |
| 638 | |
| 639 | char fragmentShaderSource[] = |
| 640 | "uniform sampler2D baseTexture;\n" |
| 641 | "varying vec2 texCoord;\n" |
| 642 | "varying vec4 colour;\n" |
| 643 | "\n" |
| 644 | "void main (void)\n" |
| 645 | "{\n" |
| 646 | " gl_FragColor = colour * texture2D( baseTexture, texCoord);\n" |
| 647 | "}\n"; |
| 648 | |
| 649 | program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); |
| 650 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); |
| 651 | #else |