2014-10-14 2 views
0

glLineStipple()을 사용하여 OpenGL 2.0으로 패턴을 만듭니다. 그것은 괜찮지 만 패턴은 항상 흔들리지 않습니다.glLineStipple() 및 웨이브 패턴

이전 OpenGL 함수 또는 셰이더에서이 문제를 해결할 방법이 있습니까?

내가 VTK의 매퍼와 그 정점과 프래그먼트 쉐이더

/*========================================================================= 

    Program: Visualization Toolkit 
    Module: vtkglPolyDataVSNoLighting.glsl 

    Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 
    All rights reserved. 
    See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 

    This software is distributed WITHOUT ANY WARRANTY; without even 
    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
    PURPOSE. See the above copyright notice for more information. 

=========================================================================*/ 
// The following line handle system declarations such a 
// default precisions, or defining precisions to null 
//VTK::System::Dec 

// all variables that represent positions or directions have a suffix 
// indicating the coordinate system they are in. The possible values are 
// MC - Model Coordinates 
// WC - WC world coordinates 
// VC - View Coordinates 
// DC - Display Coordinates 
attribute vec4 vertexMC; 

// material property values 
//VTK::Color::Dec 

// camera and actor matrix values 
uniform mat4 MCVCMatrix; // combined Model to View transform 
uniform mat4 VCDCMatrix; // the camera's projection matrix 

// Texture coordinates 
//VTK::TCoord::Dec 

void main() 
{ 
    //VTK::Color::Impl 

    //VTK::TCoord::Impl 

    gl_Position = VCDCMatrix * MCVCMatrix * vertexMC; 
} 


/*========================================================================= 

    Program: Visualization Toolkit 
    Module: vtkglPolyDataFSNoLighting.glsl 

    Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 
    All rights reserved. 
    See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 

    This software is distributed WITHOUT ANY WARRANTY; without even 
    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
    PURPOSE. See the above copyright notice for more information. 

=========================================================================*/ 

// The following line handle system declarations such a 
// default precisions, or defining precisions to null 
//VTK::System::Dec 

varying vec4 fcolor; 

// Texture coordinates 
//VTK::TCoord::Dec 

// material property values 
uniform float opacityUniform; // the fragment opacity 
uniform vec3 ambientColorUniform; // intensity weighted color 
uniform vec3 diffuseColorUniform; // intensity weighted color 

//VTK::Color::Dec 

// picking support 
//VTK::Picking::Dec 

// Depth Peeling Support 
//VTK::DepthPeeling::Dec 

void main() 
{ 
    vec3 ambientColor = ambientColorUniform; 
vec3 diffuseColor = diffuseColorUniform; 
float opacity = opacityUniform; 
    // Note that the above will always define vec3 ambientColor, vec3 diffuseColor and float opacity 

    gl_FragColor = vec4(ambientColor + diffuseColor, opacity); 
    //VTK::TCoord::Impl 

    if (gl_FragColor.a <= 0.0) 
    { 
    discard; 
    } 

    //VTK::DepthPeeling::Impl 

    //VTK::Picking::Impl 

} 

를 사용하고 그리고 그

................ 
    glLineStipple(2, 0x00FF); 
    glEnable(GL_LINE_STIPPLE); 
     glMultiDrawElements(GL_LINE_STRIP, 
         (GLsizei *)(&this->Lines.elementsArray[0]), 
         GL_UNSIGNED_INT, 
         reinterpret_cast<const GLvoid **>(&(this->Lines.offsetArray[0])), 
         (GLsizei)this->Lines.offsetArray.size()); 

    glDisable(GL_LINE_STIPPLE); 
................ 
+0

작성한 코드를 볼 수 있습니까? –

+0

@LeeJacobs –

답변

2

클래식 라인 점각처럼 그리기있어이의 비트로 점각 패턴을 처리하여 래스터 동안 이루어집니다 마스크 및 래스터 좌표와의 비트 단위 AND 연산. 이것이 화면상의 윈도우 이동이나 카메라 시점 등으로 반짝이는 이유입니다.

현대 하드웨어의 더 나은 접근법은 GL_TEXTURE_WRAP_S를 GL_REPEAT로 설정하고 알파 마스크로 1 차원 텍스처를 사용하여 스티 립을 구현하는 것입니다. 그 세그먼트의 길이 당 라인상의 각 포인트에서 텍스처 좌표를 설정한다. 밉맵 경계에서 여전히 잠재적 인 불연속성을 얻을 수는 있지만 거의 그렇게 나쁘지는 않습니다. 버텍스와 프래그먼트 쉐이더 사이에서 수행되는 투시 보정 보간법은 클래식 스티 퓰링보다 훨씬 잘 작동해야합니다.

+0

안녕하세요, 내가 초보자는 OpenGL 거기에 어떤 방법을 구현하는 것입니다 추가했습니다? –

+0

안녕하세요. OpenGL.org 포럼에서 다음과 같은 토론을 찾았습니다. https://www.opengl.org/discussion_boards/showthread.php/184862-How-to-draw-a-line-stipple-with-ES- 2-0 –

+0

드류 기능을 사용하기 전에 드류에게 감사드립니다. GL_TEXTURE_WRAP_S와 GL_REPEAT에 대해 gl 함수를 설정합니까? u_sampler도 0x00FF와 같은 패턴이 아닙니까? –