/// <summary> /// This constructor is used when you're trying to put a wrapper around /// an already existing shader object. You have the context, and you have /// the shaderID. This is enough information to do useful things with /// the shader. /// </summary> /// <param name="gi"></param> /// <param name="shaderID"></param> public GLSLShader(GLSLShaderProgram prg, int shaderID) { fShaderID = shaderID; fProgram = prg; if (null != prg) fGI = prg.GI; }
public GLSLUniformVariable(GLSLShaderProgram program, UniformType uType, int size, string name) { fShaderProgram = program; fName = name; fUniformType = uType; fSize = size; fComponents = GetComponentCountForType(fUniformType); fLocation = program.GetUniformLocation(name); InitializeSpace(); }
public DissolveProcessor(GraphicsInterface gi, int width, int height, float noiseScale) { fGI = gi; fWidth = width; fHeight = height; fNoiseScale = noiseScale; // Create the texture objects that will receive the output fOutputTexture = new GLTexture2D(GI, width, height, TextureInternalFormat.Rgba, TexturePixelFormat.Bgr, PixelComponentType.Byte, IntPtr.Zero, false); // Setup the render target that has 3 color channels for Multi Render Target // output in a shader using gl_FragData[n] fOutputTarget = new GLRenderTarget(GI); fOutputTarget.AttachColorBuffer(fOutputTexture, ColorBufferAttachPoint.Position0); fOutputTarget.Unbind(); // Create the shader program that does the actual separation fDissolveShader = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, FixedVert, Dissolve_Frag); }
protected override void OnSetContext() { fSepiaProgram = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, null, Shaders.ShaderStrings.sepia_fs); int numSources = VideoCaptureDevice.GetNumberOfInputDevices(); if (numSources > 0) { fVideoTexture1 = VideoTexture.CreateFromDeviceIndex(GI, 0, true); } else fVideoTexture1 = TextureHelper.CreateCheckerboardTexture(GI, 320, 240, 8); fVideoTexture1.Unbind(); if (numSources > 1) { fVideoTexture2 = VideoTexture.CreateFromDeviceIndex(GI, 1, true); } else fVideoTexture2 = TextureHelper.CreateCheckerboardTexture(GI, 320, 240, 16); fVideoTexture2.Unbind(); //if (numSources > 2) //{ // fVideoTexture2 = VideoTexture.CreateFromDeviceIndex(GI, 2, true); //} fCheckerboard = new TexturedCheckerboard(new Size(fViewportWidth, fViewportHeight), new Size(fHowManySplits, fHowManySplits), fVideoTexture1, fVideoTexture2); // Turn off features that we don't need // they just slow down video processing GI.Features.AlphaTest.Disable(); GI.Features.Blend.Disable(); GI.Features.DepthTest.Disable(); GI.Features.Dither.Disable(); GI.Features.Fog.Disable(); GI.Features.Lighting.Disable(); }
public YCrCbProcessor(GraphicsInterface gi, int width, int height) { fGI = gi; fWidth = width; fHeight = height; // Create the texture objects that will receive the output fYTexture = new GLTexture2D(GI, width, height, TextureInternalFormat.Luminance, TexturePixelFormat.Luminance, PixelType.Byte, IntPtr.Zero, false); fCrTexture = new GLTexture2D(GI, width, height, TextureInternalFormat.Luminance, TexturePixelFormat.Luminance, PixelType.Byte, IntPtr.Zero, false); fCbTexture = new GLTexture2D(GI, width, height, TextureInternalFormat.Luminance, TexturePixelFormat.Luminance, PixelType.Byte, IntPtr.Zero, false); // Setup the render target that has 3 color channels for Multi Render Target // output in a shader using gl_FragData[n] fYCrCbTarget = new GLRenderTarget(GI); fYCrCbTarget.AttachColorBuffer(fYTexture, ColorBufferAttachPoint.Position0); fYCrCbTarget.AttachColorBuffer(fCrTexture, ColorBufferAttachPoint.Position1); fYCrCbTarget.AttachColorBuffer(fCbTexture, ColorBufferAttachPoint.Position2); fYCrCbTarget.Unbind(); // Create the shader program that does the actual separation fYCrCbChannelSep = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, FixedVert, YCrCb_Frag); }
protected override void OnSetContext() { // When debugging, it's nice to turn on the following check. // If you do, whenever there is an error while calling one of the // underlying OpenGL functions, a GLException will be thrown. // If this flag is not set, then errors will be silently passed by and // rendering will continue. //GraphicsInterface.gCheckErrors = true; // Enable a couple of features for nice rendering. // For this program, Texturing, and DepthTest are essential. // The hint for perspective correction is optional GI.Features.Texturing2D.Enable(); GI.Features.DepthTest.Enable(); GI.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); // Set an overall color buffer background color of Invisible, // so when we clear the color buffer, it starts out blank. GI.Buffers.ColorBuffer.Color = ColorRGBA.Invisible; // Create the offscreen render target fRenderTarget = new GLRenderTarget(GI, fOffscreenWidth, fOffscreenHeight); // Create the texture object that we will be using to do normal rendering. // aTexture = TextureHelper.CreateTextureFromFile(GI, "tex.png", false); // Create the shader programs using the easy static method that // takes vertex and fragment shader strings. fFixedPipeline = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, ShaderStrings.FixedVert, ShaderStrings.FixedFrag); fImageProcProgram = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, ShaderStrings.FixedVert, ShaderStrings.ConvolutionFrag); // This is an alternate method of creating the shader programs. // You get absolute control of the individual pieces as they // are created, at the cost of brevity //GLSLVertexShader fixedVertexShader = new GLSLVertexShader(GI, ShaderStrings.FixedVert); //GLSLFragmentShader fixedFragmentShader = new GLSLFragmentShader(GI, ShaderStrings.FixedFrag); //GLSLFragmentShader convolutionFragmentShader = new GLSLFragmentShader(GI, ShaderStrings.ConvolutionFrag); //// Create the pipeline shader program //fFixedPipeline = new GLSLShaderProgram(GI); //fFixedPipeline.AttachShader(fixedVertexShader); //fFixedPipeline.AttachShader(fixedFragmentShader); //fFixedPipeline.Link(); //// Create the convolution shader program //fImageProcProgram = new GLSLShaderProgram(GI); //fImageProcProgram.AttachShader(fixedVertexShader); //fImageProcProgram.AttachShader(convolutionFragmentShader); //fImageProcProgram.Link(); }
/// <summary> /// Once we have a context, we are able to peform various setup routines /// that require us to connect to OpenGL. /// </summary> protected override void OnSetContext() { // find out how many video cameras there are. int numSources = VideoCaptureDevice.GetNumberOfInputDevices(); // If there's more than one, then connect to the one that is // at position '0' in the index. To change which camera to use, // simply change the index number. if (numSources > 4) { fVideoTexture = VideoTexture.CreateFromDeviceIndex(GI, 4, true); } else if (numSources > 0) { fVideoTexture = VideoTexture.CreateFromDeviceIndex(GI, 0, true); } // Enable texture support as we'll be using that. GI.Features.Texturing2D.Enable(); GI.TexEnv(TextureEnvModeParam.Replace); // Turn off features that we don't need, and they // just slow down video processing GI.Features.AlphaTest.Disable(); GI.Features.Blend.Disable(); GI.Features.DepthTest.Disable(); GI.Features.Dither.Disable(); GI.Features.Fog.Disable(); GI.Features.Lighting.Disable(); // Create the FaceMesh that will receive the gray texture so we // can break it up into 8x8 squares fFaceSize = new Vector3D(fVideoTexture.Width, fVideoTexture.Height, 0); fYCrCbProcessor = new YCrCbProcessor(GI, fVideoTexture.Width, fVideoTexture.Height); // Create the shader programs that will perform the colorization so we can see our results. //fRedColorizer = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, Shaders.ShaderStrings.FixedVert, Shaders.ShaderStrings.redcolorizer_fs); //fGreenColorizer = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, Shaders.ShaderStrings.FixedVert, Shaders.ShaderStrings.greencolorizer_fs); //fBlueColorizer = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, Shaders.ShaderStrings.FixedVert, Shaders.ShaderStrings.bluecolorizer_fs); fIntensityColorizer = GLSLShaderProgram.CreateUsingVertexAndFragmentStrings(GI, Shaders.ShaderStrings.FixedVert, Shaders.ShaderStrings.graycolorizer_fs); }