------------------------------------------------------------------------------
| 2006 | |
| 2007 | //------------------------------------------------------------------------------ |
| 2008 | void vtkOpenGLPolyDataMapper::ReplaceShaderNormal( |
| 2009 | std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer*, vtkActor* actor) |
| 2010 | { |
| 2011 | std::string FSSource = shaders[vtkShader::Fragment]->GetSource(); |
| 2012 | |
| 2013 | // Render points as spheres if so requested |
| 2014 | // To get the correct zbuffer values we have to |
| 2015 | // adjust the incoming z value based on the shape |
| 2016 | // of the sphere, See the document |
| 2017 | // PixelsToZBufferConversion in this directory for |
| 2018 | // the derivation of the equations used. |
| 2019 | if (this->DrawingSpheres(*this->LastBoundBO, actor)) |
| 2020 | { |
| 2021 | vtkShaderProgram::Substitute(FSSource, "//VTK::Normal::Dec", |
| 2022 | "uniform float ZCalcS;\n" |
| 2023 | "uniform float ZCalcR;\n"); |
| 2024 | |
| 2025 | // when point picking always move fragments to the closest point |
| 2026 | // to the camera. |
| 2027 | if (this->PointPicking) |
| 2028 | { |
| 2029 | vtkShaderProgram::Substitute(FSSource, "//VTK::Depth::Impl", |
| 2030 | " vec3 normalVCVSOutput = vec3(0.0,0.0,1.0);\n" |
| 2031 | " gl_FragDepth = gl_FragCoord.z + ZCalcS*ZCalcR;\n" |
| 2032 | " if (cameraParallel == 0)\n" |
| 2033 | " {\n" |
| 2034 | " float ZCalcQ = (ZCalcR - 1.0);\n" |
| 2035 | " gl_FragDepth = (ZCalcS - gl_FragCoord.z) / ZCalcQ + ZCalcS;\n" |
| 2036 | " }\n" |
| 2037 | "//VTK::Depth::Impl"); |
| 2038 | } |
| 2039 | else |
| 2040 | { |
| 2041 | vtkShaderProgram::Substitute(FSSource, "//VTK::Depth::Impl", |
| 2042 | "float xpos = 2.0*gl_PointCoord.x - 1.0;\n" |
| 2043 | " float ypos = 1.0 - 2.0*gl_PointCoord.y;\n" |
| 2044 | " float len2 = xpos*xpos+ ypos*ypos;\n" |
| 2045 | " if (len2 > 1.0) { discard; }\n" |
| 2046 | " vec3 normalVCVSOutput = normalize(\n" |
| 2047 | " vec3(2.0*gl_PointCoord.x - 1.0, 1.0 - 2.0*gl_PointCoord.y, sqrt(1.0 - len2)));\n" |
| 2048 | " gl_FragDepth = gl_FragCoord.z + normalVCVSOutput.z*ZCalcS*ZCalcR;\n" |
| 2049 | " if (cameraParallel == 0)\n" |
| 2050 | " {\n" |
| 2051 | " float ZCalcQ = (normalVCVSOutput.z*ZCalcR - 1.0);\n" |
| 2052 | " gl_FragDepth = (ZCalcS - gl_FragCoord.z) / ZCalcQ + ZCalcS;\n" |
| 2053 | " }\n" |
| 2054 | "//VTK::Depth::Impl"); |
| 2055 | } |
| 2056 | |
| 2057 | vtkShaderProgram::Substitute( |
| 2058 | FSSource, "//VTK::Normal::Impl", "//Normal computed in Depth::Impl"); |
| 2059 | |
| 2060 | shaders[vtkShader::Fragment]->SetSource(FSSource); |
| 2061 | return; |
| 2062 | } |
| 2063 | |
| 2064 | // Render lines as tubes if so requested |
| 2065 | // To get the correct zbuffer values we have to |
no test coverage detected