返回列表 發帖

OpenGL GLSL 如何依序使用多個shade

目前想使用兩個不同的vertex shader和兩個不同的fragment shader去做影像得處理
但在實作上,兩個shade會平行處理,不會依據第一個shade(S1)執行完後,在執行第二個shade(S2)
有參考過GPUImage的寫法,研究了一個月,還是完全不知為何能做到shade依序處理的效果

初始shade程碼
  1. -(void)initGLSL{
  2.    
  3.     grayTest = BuildProgram(@"vertexHARRIS", @"fragmentGray");
  4.     glUseProgram(grayTest);
  5.     grayPositionAttribute  = glGetAttribLocation(grayTest, "position");
  6.     grayTextureCoordinateAttribute = glGetAttribLocation(grayTest, "inputTextureCoordinate");
  7.     grayInputImageTextureUniform = glGetUniformLocation(grayTest, "inputImageTexture");
  8.     graySensitivityUniform = glGetUniformLocation(grayTest, "sensitivity");
  9.     glEnableVertexAttribArray(grayPositionAttribute);
  10.     glEnableVertexAttribArray(grayTextureCoordinateAttribute);
  11.    
  12.     glVertexAttribPointer( grayPositionAttribute, 2, GL_FLOAT, 0, 0, imageVertices);
  13.     glVertexAttribPointer( grayTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, noRotationTextureCoordinates);
  14.    
  15.    
  16.     filterXYTest = BuildProgram(@"vertexNearbyTexelSampling", @"fragmentXYDerivativeFilter");
  17.     glUseProgram(filterXYTest);
  18.     filterXYPositionAttribute = glGetAttribLocation(filterXYTest, "position");
  19.     filterXYTextureCoordinateAttribute = glGetAttribLocation(filterXYTest, "inputTextureCoordinate");
  20.     filterXYInputImageTextureUniform = glGetUniformLocation(filterXYTest, "inputImageTexture");
  21.     filterXYEdgeStrength = glGetUniformLocation(filterXYTest, "edgeStrength");
  22.     filterXYTexelWidth = glGetUniformLocation(filterXYTest,  "texelWidth");
  23.     filterXYTexelHeight = glGetUniformLocation(filterXYTest, "texelHeight");
  24.     glEnableVertexAttribArray(filterXYPositionAttribute);
  25.     glEnableVertexAttribArray(filterXYTextureCoordinateAttribute);
  26.    
  27.     glVertexAttribPointer( positionAttribute, 2, GL_FLOAT, 0, 0, imageVertices);
  28.     glVertexAttribPointer( textureCoordinateAttribute, 2, GL_FLOAT, 0, 0, noRotationTextureCoordinates);
  29. }
複製代碼
調用shade的程碼
  1. -(void)detectGLSL{
  2.    
  3.     glViewport(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  4.     glUseProgram(grayTest);
  5.     glActiveTexture(GL_TEXTURE0);
  6.     glBindTexture(GL_TEXTURE_2D, self.backdropModel.textureId);
  7.     glUniform1i(grayInputImageTextureUniform, 0);
  8.     glUniform1f(graySensitivityUniform, 5.0);
  9.     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  10.    
  11.     glViewport(self.view.frame.size.width, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
  12.     glUseProgram(filterXYTest);
  13.     glActiveTexture(GL_TEXTURE0);
  14.     glBindTexture(GL_TEXTURE_2D, self.backdropModel.textureId);
  15.     glUniform1i(filterXYInputImageTextureUniform, 0);
  16.     glUniform1f(filterXYEdgeStrength, 0.9);
  17.     glUniform1f(filterXYTexelHeight, self.view.frame.size.height);
  18.     glUniform1f(filterXYTexelWidth, self.view.frame.size.width);
  19.     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  20. }
複製代碼
不知有無參考網站有討論這問題過?
以下為我的github  https://github.com/Bamboowand/CVOpenGLESCamera
供大家參考
返回列表