public Smaa() { this.area_tex_unit = GLTextureUnit.Create() .SetTexture(GLTexture.Create().SetFormat(TextureFormat.RG).SetSize(AREATEX_WIDTH, AREATEX_HEIGHT) .SetData(SMAA_AREA_RAW)).SetWrap(GLWrap.ClampToEdge).SetFiltering(GLScaleFilter.Linear); this.search_tex_unit = GLTextureUnit.Create() .SetTexture(GLTexture.Create().SetFormat(TextureFormat.R).SetSize(SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT) .SetData(SMAA_SEARCH_RAW)).SetWrap(GLWrap.ClampToEdge).SetFiltering(GLScaleFilter.Nearest); CommonHeader = @" #version 410 compatibility #define SMAA_PIXEL_SIZE u_pixelSize.xy #define SMAA_PRESET_ULTRA 1 #define SMAA_GLSL_4 1 //#define SMAA_PREDICATION 0 #define SMAA_PREDICATION 1 #define attribute in " ; VertexHeader = CommonHeader + "\n" + "#define SMAA_ONLY_COMPILE_VS 1" + "\n" + @" uniform vec4 u_pixelSize; attribute vec4 a_position; attribute vec4 a_texcoords; " + SMAA_H + "\n"; FragmentHeader = CommonHeader + "\n" + "#define SMAA_ONLY_COMPILE_PS 1" + "\n" + @" uniform vec4 u_pixelSize; " + "\n" + SMAA_H; }
public override void PrimStart(GlobalGpuState globalGpuState, GpuStateStruct *gpuState, GuPrimitiveType primitiveType) { GpuState = gpuState; _primitiveType = primitiveType; _doPrimStart = true; ResetVertex(); if (_shader != null) { _shader.GetUniform("lopEnabled").Set(gpuState->LogicalOperationState.Enabled); if (gpuState->LogicalOperationState.Enabled) { if (_logicOpsRenderTarget == null) { _logicOpsRenderTarget = GLRenderTarget.Create(512, 272, RenderTargetLayers.Color); } GLRenderTarget.CopyFromTo(GLRenderTarget.Current, _logicOpsRenderTarget); _shader.GetUniform("backtex").Set(GLTextureUnit.CreateAtIndex(1).SetFiltering(GLScaleFilter.Linear) .SetWrap(GLWrap.ClampToEdge).SetTexture(_logicOpsRenderTarget.TextureColor)); _shader.GetUniform("lop").Set((int)gpuState->LogicalOperationState.Operation); //new Bitmap(512, 272).SetChannelsDataInterleaved(LogicOpsRenderTarget.ReadPixels(), BitmapChannelList.RGBA).Save(@"c:\temp\test.png"); } } }
public GLTexture Process(GLTexture Input) { Filter.SetSize(Input.Width * 2, Input.Height * 2); return(Filter.Process((_Shader) => { _Shader.GetUniform("OGL2Texture").Set(GLTextureUnit.CreateAtIndex(0).SetWrap(GLWrap.ClampToEdge) .SetFiltering(GLScaleFilter.Nearest).SetTexture(Input)); })); }
public BinaryTextureProcessor(GraphicsInterface gi, int width, int height, string fragmentString) : base(gi) { fWidth = width; fHeight = height; fFragmentShaderString = fragmentString; fBaseTextureUnit = GLTextureUnit.GetTextureUnit(gi, TextureUnitID.Unit1); fBlendTextureUnit = GLTextureUnit.GetTextureUnit(gi, TextureUnitID.Unit0); }
public void ActiveTexture(GLTextureUnit texture) { try { this.BeginFunc(); this._gl.ActiveTexture(texture); } finally { this.EndFunc(); } }
private GLTexture edge_pass(GLTexture albedo_tex, GLTexture depthTex) { if (edge_shader == null) { edge_shader = GLShaderFilter.Create(Width, Height, new GLShader( VertexHeader + @" out vec2 texcoord; out vec4 offset[3]; out vec4 dummy2; void main() { texcoord = a_texcoords.xy; vec4 dummy1 = vec4(0); SMAAEdgeDetectionVS(dummy1, dummy2, texcoord, offset); gl_Position = a_position; } " , FragmentHeader + @" uniform sampler2D albedo_tex; uniform sampler2D depthTex; in vec2 texcoord; in vec4 offset[3]; in vec4 dummy2; void main() { #if SMAA_PREDICATION == 1 gl_FragColor = SMAAColorEdgeDetectionPS(texcoord, offset, albedo_tex, depthTex); #else gl_FragColor = SMAAColorEdgeDetectionPS(texcoord, offset, albedo_tex); #endif } " )); } return(edge_shader.Process((Shader) => { Shader.GetUniform("albedo_tex").Set(GLTextureUnit.CreateAtIndex(0).SetWrap(GLWrap.ClampToEdge) .SetFiltering(GLScaleFilter.Linear).SetTexture(albedo_tex)); Shader.GetUniform("depthTex").NoWarning().Set(GLTextureUnit.CreateAtIndex(1).SetWrap(GLWrap.ClampToEdge) .SetFiltering(GLScaleFilter.Linear).SetTexture(depthTex)); })); }
private GLTexture pass_blend(GLTexture edge_tex) { if (blend_shader == null) { blend_shader = GLShaderFilter.Create(Width, Height, new GLShader( VertexHeader + @" out vec2 texcoord; out vec2 pixcoord; out vec4 offset[3]; out vec4 dummy2; void main() { texcoord = a_texcoords.xy; vec4 dummy1 = vec4(0); SMAABlendingWeightCalculationVS(dummy1, dummy2, texcoord, pixcoord, offset); gl_Position = a_position; } " , FragmentHeader + @" uniform sampler2D edge_tex; uniform sampler2D area_tex; uniform sampler2D search_tex; in vec2 texcoord; in vec2 pixcoord; in vec4 offset[3]; in vec4 dummy2; void main() { gl_FragColor = SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edge_tex, area_tex, search_tex, ivec4(1, 1, 1, 0)); //gl_FragColor = SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edge_tex, area_tex, search_tex, ivec4(0)); } " )); } return(blend_shader.Process((Shader) => { Shader.GetUniform("edge_tex").Set(GLTextureUnit.CreateAtIndex(0).SetWrap(GLWrap.ClampToEdge) .SetFiltering(GLScaleFilter.Linear).SetTexture(edge_tex)); Shader.GetUniform("area_tex").Set(area_tex_unit.SetIndex(1)); Shader.GetUniform("search_tex").Set(search_tex_unit.SetIndex(2)); })); }
private GLTexture pass_neighborhood(GLTexture albedo_tex, GLTexture blend_tex) { if (neighborhood_shader == null) { neighborhood_shader = GLShaderFilter.Create(Width, Height, new GLShader( VertexHeader + @" out vec2 texcoord; out vec4 offset[2]; out vec4 dummy2; void main() { texcoord = a_texcoords.xy; vec4 dummy1 = vec4(0); SMAANeighborhoodBlendingVS(dummy1, dummy2, texcoord, offset); gl_Position = a_position; } " , FragmentHeader + @" uniform sampler2D albedo_tex; uniform sampler2D blend_tex; in vec2 texcoord; in vec4 offset[2]; in vec4 dummy2; void main() { gl_FragColor = SMAANeighborhoodBlendingPS(texcoord, offset, albedo_tex, blend_tex); } " )); } return(neighborhood_shader.Process((Shader) => { Shader.GetUniform("albedo_tex").Set(GLTextureUnit.CreateAtIndex(0).SetWrap(GLWrap.ClampToEdge) .SetFiltering(GLScaleFilter.Linear).SetTexture(albedo_tex)); Shader.GetUniform("blend_tex").Set(GLTextureUnit.CreateAtIndex(1).SetWrap(GLWrap.ClampToEdge) .SetFiltering(GLScaleFilter.Linear).SetTexture(blend_tex)); })); }
//GLTexture TestTexture; public void DrawVram(bool EnableSmaa) { if (Shader == null) { Initialize(); } //int RectWidth = 512; //int RectHeight = 272; var Rectangle = IGuiWindowInfo.ClientRectangle; GL.glClearColor(0, 0, 0, 1); GL.glClear(GL.GL_COLOR_BUFFER_BIT); //IGuiWindowInfo.SwapBuffers(); //return; if ( (PspDisplay.CurrentInfo.Enabled || PspDisplay.CurrentInfo.PlayingVideo) ) { GetTex((Tex) => { //Console.Out.WriteLineColored(ConsoleColor.Red, "{0}", Tex.Texture); if (Tex != null && Tex.Color.Texture != 0) { var TexColor = Tex.Color; var TexDepth = Tex.Depth; if (EnableSmaa) { if (TexDepth.Texture != 0) { TexColor = Smaa.Process(TexColor, TexDepth); } } GL.glViewport(Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height); Shader.Draw(GLGeometry.GL_TRIANGLE_STRIP, 4, () => { var TextureRect = CSharpPlatform.RectangleF.FromCoords(0, 0, (float)PspDisplay.CurrentInfo.Width / 512f, (float)PspDisplay.CurrentInfo.Height / 272f); if (TextureVerticalFlip) { TextureRect = TextureRect.VFlip(); } TexCoordsBuffer = GLBuffer.Create().SetData(TextureRect.GetFloat2TriangleStripCoords()); ShaderInfo.texture.Set(GLTextureUnit.CreateAtIndex(0).SetFiltering(GLScaleFilter.Nearest) .SetWrap(GLWrap.ClampToEdge).SetTexture(TexColor)); //ShaderInfo.texture.Set(GLTextureUnit.CreateAtIndex(0).SetFiltering(GLScaleFilter.Nearest).SetWrap(GLWrap.ClampToEdge).SetTexture(TexDepth)); ShaderInfo.position.SetData <float>(VertexBuffer, 2); ShaderInfo.texCoords.SetData <float>(TexCoordsBuffer, 2); }); } }); } IGuiWindowInfo.SwapBuffers(); }
protected virtual void BindTexture(GLTextureUnit aUnit, GLTexture aTexture) { // We want to turn off filtering. We do that by using 'nearest' // we also clamp the coordinates instead of replicating at the edges aUnit.Bind(); aTexture.Bind(); GI.TexParameter(TextureParameterTarget.Texture2d, TextureParameterName.TextureMinFilter, TextureMinFilter.Nearest); GI.TexParameter(TextureParameterTarget.Texture2d, TextureParameterName.TextureMagFilter, TextureMagFilter.Nearest); GI.TexParameter(TextureParameterTarget.Texture2d, TextureParameterName.TextureWrapS, TextureWrapMode.Clamp); GI.TexParameter(TextureParameterTarget.Texture2d, TextureParameterName.TextureWrapT, TextureWrapMode.Clamp); }
public void ActiveTexture(GLTextureUnit texture) { TKGL.ActiveTexture((TextureUnit)texture); }
private void PrepareDrawStateFirst() { if (_shader == null) { DrawInitVertices(); } ShaderInfo.matrixWorldViewProjection.Set(_worldViewProjectionMatrix); ShaderInfo.matrixTexture.Set(_textureMatrix); ShaderInfo.uniformColor.Set(GpuState->LightingState.AmbientModelColor.ToVector4F()); ShaderInfo.hasPerVertexColor.Set(VertexType.HasColor); ShaderInfo.clearingMode.Set(GpuState->ClearingMode); ShaderInfo.hasTexture.Set(GpuState->TextureMappingState.Enabled); ShaderInfo.weightCount.Set(VertexType.RealSkinningWeightCount); //ShaderInfo.weightCount.Set(0); if (VertexType.HasWeight) { ShaderInfo.matrixBones.Set(new[] { GpuState->SkinningState.BoneMatrix0.Matrix4, GpuState->SkinningState.BoneMatrix1.Matrix4, GpuState->SkinningState.BoneMatrix2.Matrix4, GpuState->SkinningState.BoneMatrix3.Matrix4, GpuState->SkinningState.BoneMatrix4.Matrix4, GpuState->SkinningState.BoneMatrix5.Matrix4, GpuState->SkinningState.BoneMatrix6.Matrix4, GpuState->SkinningState.BoneMatrix7.Matrix4, }); } if (VertexType.HasTexture && GpuState->TextureMappingState.Enabled) { var textureState = &GpuState->TextureMappingState.TextureState; ShaderInfo.tfx.Set((int)textureState->Effect); ShaderInfo.tcc.Set((int)textureState->ColorComponent); ShaderInfo.colorTest.NoWarning().Set(GpuState->ColorTestState.Enabled); ShaderInfo.alphaTest.Set(GpuState->AlphaTestState.Enabled); ShaderInfo.alphaFunction.Set((int)GpuState->AlphaTestState.Function); ShaderInfo.alphaMask.NoWarning().Set(GpuState->AlphaTestState.Mask); ShaderInfo.alphaValue.Set(GpuState->AlphaTestState.Value); //Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", TextureState->Effect, TextureState->ColorComponent, GpuState->BlendingState.Enabled, GpuState->BlendingState.FunctionSource, GpuState->BlendingState.FunctionDestination, GpuState->ColorTestState.Enabled); ShaderInfo.texture0.Set(GLTextureUnit.CreateAtIndex(0) .SetWrap( (GLWrap)((textureState->WrapU == WrapMode.Repeat) ? GL.GL_REPEAT : GL.GL_CLAMP_TO_EDGE), (GLWrap)((textureState->WrapV == WrapMode.Repeat) ? GL.GL_REPEAT : GL.GL_CLAMP_TO_EDGE) ) .SetFiltering( (GLScaleFilter)((textureState->FilterMinification == TextureFilter.Linear) ? GL.GL_LINEAR : GL.GL_NEAREST), (GLScaleFilter)((textureState->FilterMagnification == TextureFilter.Linear) ? GL.GL_LINEAR : GL.GL_NEAREST) ) .SetTexture(RenderbufferManager.TextureCacheGetAndBind(GpuState)) ); } }
public static void ActiveTexture(GLTextureUnit texture) { GL._gl.ActiveTexture(texture); }
public void ActiveTexture(GLTextureUnit texture) { }