代码之家  ›  专栏  ›  技术社区  ›  Yippie-Ki-Yay

C++着色器问题

  •  1
  • Yippie-Ki-Yay  · 技术社区  · 15 年前

    (例如,通过设置一些适当的模式,例如 D3DFILL_WIREFRAME 在DirectX中)。

    但我感兴趣的是如果这能实现 (可能是合并的)。

    有人有这个样品吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Chris Dennett    15 年前

    也许有点像 http://wn.com/DirectX_C++__Geometry_with_Wireframe_Effect ?

    试试这个: http://cgg-journal.com/2008-2/06/index.html

    // ------------------ Vertex Shader --------------------------------
    #version 120
    #extension GL_EXT_gpu_shader4 : enable
    void main(void)
    {
       gl_Position =  ftransform();
    }
    
    
    // ------------------ Geometry Shader --------------------------------
    #version 120
    #extension GL_EXT_gpu_shader4 : enable
    
    uniform vec2 WIN_SCALE;
    noperspective varying vec3 dist;
    void main(void)
    {
      vec2 p0 = WIN_SCALE * gl_PositionIn[0].xy/gl_PositionIn[0].w;
      vec2 p1 = WIN_SCALE * gl_PositionIn[1].xy/gl_PositionIn[1].w;
      vec2 p2 = WIN_SCALE * gl_PositionIn[2].xy/gl_PositionIn[2].w;
    
      vec2 v0 = p2-p1;
      vec2 v1 = p2-p0;
      vec2 v2 = p1-p0;
      float area = abs(v1.x*v2.y - v1.y * v2.x);
    
      dist = vec3(area/length(v0),0,0);
      gl_Position = gl_PositionIn[0];
      EmitVertex();
    
      dist = vec3(0,area/length(v1),0);
      gl_Position = gl_PositionIn[1];
      EmitVertex();
    
      dist = vec3(0,0,area/length(v2));
      gl_Position = gl_PositionIn[2];
      EmitVertex();
    
      EndPrimitive();
    }
    
    
    // ------------------ Fragment Shader --------------------------------
    #version 120
    #extension GL_EXT_gpu_shader4 : enable
    
    noperspective varying vec3 dist;
    const vec4 WIRE_COL = vec4(1.0,0.0,0.0,1);
    const vec4 FILL_COL = vec4(1,1,1,1);
    
    void main(void)
    {
        float d = min(dist[0],min(dist[1],dist[2]));
        float I = exp2(-2*d*d);
        gl_FragColor = I*WIRE_COL + (1.0 - I)*FILL_COL;
    }