public QuadRenderer(Renderer renderer, IShader shader) { this.renderer = renderer; this.shader = shader; vertices = new Vertex[renderer.TempBufferSize]; renderAction = () => renderer.DrawBatch(vertices, nv, PrimitiveType.QuadList); }
/// <summary> /// This can only be created after an opengl context has been created. /// </summary> public GL33Renderable() { GL.GenVertexArrays(1, out VertexArrayObject); GL.BindVertexArray(VertexArrayObject); if(!GL.IsVertexArray(VertexArrayObject)) throw new OpenGLException("Vertex array object could not be created!"); VertexBufferObject = new int[3]; GL.GenBuffers(3, VertexBufferObject); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject[0]); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject[1]); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject[2]); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindVertexArray(0); if (!GL.IsBuffer(VertexBufferObject[0]) || !GL.IsBuffer(VertexBufferObject[1]) || !GL.IsBuffer(VertexBufferObject[2])) throw new OpenGLException("Vertex buffer object was not created!"); Textures = new List<ITexture>(); Uniform_To_Texture = new Dictionary<int, ITexture>(); Position = new Vector3(0.0f, 0.0f, 0.0f); Rotation = new Quaternion(); Scale = new Vector3(1.0f, 1.0f, 1.0f); TransformationMatrix = Matrix4.Identity; ModelViewMatrix = Matrix4.Identity; ProjectionMatrix = Matrix4.Identity; Shader = null; }
public void Stop() { _shakeShader = null; setActiveShader(_previousShader); var tcs = _taskCompletionSource; if (tcs != null) tcs.TrySetResult(null); }
/// <summary> /// Initializes a new instance of the <see cref="ForwardMaterial"/> class. /// </summary> /// <param name="shader">The shader.</param> public ForwardMaterial(IShader shader) { System.Diagnostics.Debug.Assert(shader.MaterialType == Material.MaterialType.FORWARD); this.Shader = shader; CanAppearOfReflectionRefraction = true; CanCreateShadow = true; IsVisible = true; }
public void Start() { _previousShader = getActiveShader(); _taskCompletionSource = new TaskCompletionSource<object> (null); _shakeShader = GLShader.FromText(VERTEX_SHADER_SHAKE, FRAGMENT_SHADER_STANDARD, _graphics); AGSGame.Game.Events.OnBeforeRender.Subscribe(onBeforeRender); setActiveShader(_shakeShader); }
public SpriteRenderer(Renderer renderer, bool allowAlpha, IShader shader) { this.renderer = renderer; this.shader = shader; vertexBuffer = renderer.Device.CreateVertexBuffer( vertices.Length ); indexBuffer = renderer.Device.CreateIndexBuffer( indices.Length ); }
/// <summary> /// Initializes a new instance of the <see cref="ForwardMaterial"/> class. /// </summary> /// <param name="shader">The shader.</param> public DeferredMaterial(IShader shader) { System.Diagnostics.Debug.Assert(shader != null); System.Diagnostics.Debug.Assert(shader.MaterialType == Material.MaterialType.DEFERRED); this.Shader = shader; CanAppearOfReflectionRefraction = true; CanCreateShadow = true; IsVisible = true; }
public VoxelRenderer(Renderer renderer, IShader shader) { this.renderer = renderer; this.shader = shader; mappedBuffers = new Dictionary<Sheet, IFrameBuffer>(); unmappedBuffers = new Stack<KeyValuePair<Sheet, IFrameBuffer>>(); doRender = new List<Pair<Sheet, Action>>(); }
/// <summary> /// Creates an environment object. /// </summary> public Environment() { fogStartDistance = -1; fogEndDistance = -1; fogEnabled = false; fogColor = Color.White.ToVector4(); tmpMat1 = Matrix.Identity; shader = new SimpleEffectShader(); }
/// <summary> /// Initializes a new instance of the <see cref="ForwardMaterial"/> class. /// </summary> /// <param name="shader">The shader.</param> public ClothMaterial(IShader shader) { this.Shader = shader; CanAppearOfReflectionRefraction = true; CanCreateShadow = true; IsVisible = true; rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; }
public LineRenderer(Renderer renderer, IShader shader) { this.renderer = renderer; this.shader = shader; vertices = new Vertex[renderer.TempBufferSize]; renderAction = () => { renderer.SetLineWidth(LineWidth); renderer.DrawBatch(vertices, nv, PrimitiveType.LineList); }; }
/// <summary> /// Initializes a new instance of the <see cref="ForwardMaterial"/> class. /// </summary> /// <param name="shader">The shader.</param> public FluidMaterial(IShader shader, int maxParticles, Microsoft.Xna.Framework.Vector2 scale) { this.Shader = shader; CanAppearOfReflectionRefraction = false; CanCreateShadow = false; IsVisible = true; BilboardInstance = new BilboardInstance[maxParticles]; for (int i = 0; i < maxParticles; i++) { BilboardInstance[i] = new BilboardInstance(); BilboardInstance[i].Scale = scale; } }
public IResultSet Compile(IShader shader, IBackendOptions options) { if ( !(shader is GLSLShader ) ) return null; GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; if (glOpts.OptimizerOptions == null) return null; GLSLOptimizer.IOptimizer optimizer = m_Optimizers[glOpts.OptimizerTarget]; return new GLSLOptimizerResultSet( optimizer.Optimize(sh.Code, glOpts.OptimizerOptions) ); }
public IResultSet Compile(IShader shaderObj, IBackendOptions options) { if ( !(shaderObj is HLSLShader ) ) return null; HLSLShader shaderHLSL = shaderObj as HLSLShader; IHLSLOptions hlslOpts = shaderHLSL.CompileOptions; AMDDriverBackendOptions backendOptions = options as AMDDriverBackendOptions; string shader = shaderObj.Code; if (shaderHLSL.WasCompiledWithErrors) return null; try { // compile here if we must. Recycle existing blob if we can IDXShaderBlob blob = shaderHLSL.CompiledBlob; if ( blob == null ) { if (!shaderHLSL.Compile(m_FXC)) return null; blob = shaderHLSL.CompiledBlob; } IDXShaderReflection reflect = blob.Reflect(); IDXShaderBlob exe = blob.GetExecutableBlob(); if (exe == null) return null; byte[] bytes = exe.ReadBytes(); AMDDriverResultSet rs = new AMDDriverResultSet(reflect ); foreach (IAMDAsic a in m_Driver.Asics) { if (CompileForAsic(backendOptions.Asics, a.Name)) { IAMDShader sh = m_Driver.CompileDXBlob(a, bytes, reflect); rs.Add(sh); } } return rs; } catch( System.Exception ex ) { MessageBox.Show(ex.Message); return null; } }
public void Add(IShader shader) { /*if (_shaders.Any()) { shader.Content = _shaders.Last(); } else { shader.Content = this; }*/ _shaders.Add(shader); shader.Load(); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is GLSLShader) ) return null; GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; GLSlangOptions slangOpts = new GLSlangOptions(); slangOpts.ShaderType = glOpts.ShaderType; slangOpts.Config = m_Config; GLSlang.IShader result = m_Compiler.Compile(sh.Code, slangOpts); return new GLSLangResultSet(result); }
public static Instance createTemporary(PrimitiveList primitives, Matrix4 transform, IShader shader) { Instance i = new Instance(); i.o2w = new MovingMatrix4(transform); i.w2o = i.o2w.inverse(); if (i.w2o == null) { UI.printError(UI.Module.GEOM, "Unable to compute transform inverse"); return null; } i.geometry = new Geometry(primitives); i.shaders = new IShader[] { shader }; i.updateBounds(); return i; }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is HLSLShader ) ) return null; HLSLShader hlsl = (HLSLShader)shader; IHLSLOptions hlslOpts = hlsl.CompileOptions; string text = hlsl.Code; if (!hlsl.WasCompiled) hlsl.Compile(m_Compiler); return new FXCResultSet(hlsl.Messages, hlsl.CompiledBlob); }
public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc) : base(parent) { video = parent.FindParentOrSelfWithException<Video>(); this.shader = (Shader)shader; enabledStreamIndices = new bool[2]; streamBytesSizes = desc.StreamBytesSizes; layout = ((BufferLayoutDesc)desc).desc; attribLocations = new int[layout.Length]; for (int i = 0; i != layout.Length; ++i) { attribLocations[i] = GL.GetAttribLocation(this.shader.program, layout[i].Name); Video.checkForError(); } }
public LightServer(Scene scene) { this.scene = scene; lights = new LightSource[0]; causticPhotonMap = null; shaderOverride = null; shaderOverridePhotons = false; maxDiffuseDepth = 1; maxReflectionDepth = 4; maxRefractionDepth = 4; causticPhotonMap = null; giEngine = null; }
public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc) : base(parent) { try { var video = parent.FindParentOrSelfWithException<Video>(); com = new BufferLayoutCom(); var error = com.Init(video.com, ((Shader)shader).vertex.com, ((BufferLayoutDesc)desc).com); if (error == BufferLayoutErrors.InputLayout) Debug.ThrowError("BufferLayout", "Failed to create InputLayout"); } catch (Exception e) { Dispose(); throw e; } }
/// <summary> /// Initializes the render object</summary> /// <returns>true, iff initialization was successful</returns> public override bool Init(SceneNode node) { IMesh mesh = TryGetMesh(); if (mesh != null) { m_bindingCount = m_primitives.BindingCount; // determine primitive type if (m_primitives.PrimitiveType == "POLYGONS") { m_drawMode = Gl.GL_POLYGON; } else if (m_primitives.PrimitiveType == "TRIANGLES") { m_drawMode = Gl.GL_TRIANGLES; } else if (m_primitives.PrimitiveType == "TRISTRIPS") { m_drawMode = Gl.GL_TRIANGLE_STRIP; } // add draw commands AddCommand(NormalsTag, Function.glNormal3fv); AddCommand(TextureCoordinatesTag, Function.glTexCoord2fv); AddCommand(ColorsTag, Function.glColor3fv); AddCommand(VerticesTag, Function.glVertex3fv); // get the shader IShader shader = m_primitives.Shader; IRenderStateCreator renderStateCreator = null; if (shader != null) { renderStateCreator = shader.As <IRenderStateCreator>(); } if (renderStateCreator != null) { RenderState renderState = renderStateCreator.CreateRenderState(); node.StateStack.Push(renderState); } } return(true); }
public static IShader New(VideoTypes videoType, IDisposableResource parent, string filename, ShaderVersions shaderVersion, ShaderFloatingPointQuality vsQuality, ShaderFloatingPointQuality psQuality, Loader.LoadedCallbackMethod loadedCallback) { IShader api = null; #if WIN32 if (videoType == VideoTypes.D3D9) { api = new D3D9.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback); } #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) { api = new D3D11.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback); } #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) { api = new OpenGL.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback); } #endif #if XNA if (videoType == VideoTypes.XNA) { api = new XNA.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback); } #endif #if VITA if (videoType == VideoTypes.Vita) { api = new Vita.Shader(parent, filename, shaderVersion, vsQuality, psQuality, loadedCallback); } #endif if (api == null) { Debug.ThrowError("ShaderAPI", "Unsuported InputType: " + videoType); } return(api); }
public TerrainShader(IOpenGL33 gl) { vertexShader = new VertexShader(gl, GetEmbeddedResourceAsString("VertexShader.vs")); fragmentShader = new FragmentShader(gl, GetEmbeddedResourceAsString("FragmentShader.fs")); var p = new ModGL.ObjectModel.Shaders.Program(gl, vertexShader, fragmentShader); p.BindVertexAttributeLocations(PositionNormalTexCoord.Descriptor); // Bind output fragment to the specified nme gl.BindFragDataLocation(p.Handle, 0, "Color"); // Compile program and shaders p.Compile(); program = p; // Get the uniforms used by the shader program. diffuseUniform = p.GetUniform<Vector4fUniform, Vector4f>("DiffuseColor"); modelViewProjection = p.GetUniform<MatrixUniform, Matrix4f>("ModelViewProjection"); viewProjection = p.GetUniform<MatrixUniform, Matrix4f>("ViewProjection"); textureUnitUniform = p.GetUniform<IntUniform, int>("Texture"); }
GLSlang.IShader CompileShader(IShader shader) { if (shader is HLSLShader) { // pass the shader through GLSLang's hlsl front end HLSLShader hlsl = shader as HLSLShader; return(m_GLSLang.CompileHLSL(shader.Code, hlsl.CompileOptions, m_GLSLangConfig, shader.SourceFilePath)); } else if (shader is GLSLShader) { GLSLShader glsl = shader as GLSLShader; return(m_GLSLang.Compile(shader.Code, glsl.CompileOptions.ShaderType, m_GLSLangConfig, glsl.SourceFilePath)); } else { throw new System.Exception("Bad shader type?!?"); } }
int iShaderCache.tryLoadShader(ref Guid guid, out IShader shader) { shader = null; try { Payload p = lookupInCache(guid); if (null == p) { return(1); // S_FALSE } shader = loadShader(ref guid, p); return(0); // S_OK } catch (Exception ex) { return(ex.HResult); } }
public Font(IDisposableResource parent, IShader shader, ITexture2D texture, string metricsFileName, Loader.LoadedCallbackMethod loadedCallback) : base(parent) { new StreamLoader(metricsFileName, delegate(object sender, bool succeeded) { if (succeeded) { init(shader, texture, ((StreamLoader)sender).LoadedStream, metricsFileName, loadedCallback); } else { FailedToLoad = true; Dispose(); if (loadedCallback != null) loadedCallback(this, false); } }); }
private void onBeforeRender() { var shader = _shader; if (shader != null) { shader = shader.Compile(); } if (shader == null || shader != getActiveShader()) { _shader = null; AGSGame.Game.Events.OnBeforeRender.Unsubscribe(onBeforeRender); return; } shader.Bind(); shader.SetVariable("adjustment", Saturation); shader.Unbind(); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is HLSLShader)) { return(null); } HLSLShader hlsl = (HLSLShader)shader; IHLSLOptions hlslOpts = hlsl.CompileOptions; string text = hlsl.Code; if (!hlsl.WasCompiled) { hlsl.Compile(m_Compiler); } return(new FXCResultSet(hlsl.Messages, hlsl.CompiledBlob)); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is GLSLShader)) { return(null); } GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; if (glOpts.OptimizerOptions == null) { return(null); } GLSLOptimizer.IOptimizer optimizer = m_Optimizers[glOpts.OptimizerTarget]; return(new GLSLOptimizerResultSet(optimizer.Optimize(sh.Code, glOpts.OptimizerOptions))); }
public LightServer(Scene scene) { this.scene = scene; lights = new LightSource[0]; causticPhotonMap = null; shaderOverride = null; shaderOverridePhotons = false; maxDiffuseDepth = 1; maxReflectionDepth = 4; maxRefractionDepth = 4; causticPhotonMap = null; giEngine = null; shadingCache(0); }
private void load(ShaderManager shaders, IBindable <WorkingBeatmap> beatmap, SentakkiRulesetConfigManager settings) { this.beatmap.BindTo(beatmap); shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED); settings?.BindWith(SentakkiRulesetSettings.KiaiEffects, kiaiEffect); kiaiEffect.BindValueChanged(k => { if (k.NewValue) { this.FadeIn(200); } else { this.FadeOut(500); } }); }
public override void ApplyState() { base.ApplyState(); screenSpaceDrawRectangle = Source.ScreenSpaceDrawQuad.AABBFloat; filteringMode = Source.PixelSnapping ? All.Nearest : All.Linear; updateVersion = Source.updateVersion; backgroundColour = Source.BackgroundColour; BlendingParameters localEffectBlending = Source.EffectBlending; if (localEffectBlending.Mode == BlendingMode.Inherit) { localEffectBlending.Mode = Source.Blending.Mode; } if (localEffectBlending.RGBEquation == BlendingEquation.Inherit) { localEffectBlending.RGBEquation = Source.Blending.RGBEquation; } if (localEffectBlending.AlphaEquation == BlendingEquation.Inherit) { localEffectBlending.AlphaEquation = Source.Blending.AlphaEquation; } effectColour = Source.EffectColour; effectBlending = localEffectBlending; effectPlacement = Source.EffectPlacement; drawOriginal = Source.DrawOriginal; blurSigma = Source.BlurSigma; blurRadius = new Vector2I(Blur.KernelSize(blurSigma.X), Blur.KernelSize(blurSigma.Y)); blurRotation = Source.BlurRotation; formats.Clear(); formats.AddRange(Source.attachedFormats); blurShader = Source.blurShader; // BufferedContainer overrides DrawColourInfo for children, but needs to be reset to draw ourselves DrawColourInfo = Source.baseDrawColourInfo; }
public override void Draw(Action <TexturedVertex2D> vertexAction) { base.Draw(vertexAction); if (Texture?.Available != true) { return; } IShader shader = needsRoundedShader ? RoundedTextureShader : TextureShader; shader.Bind(); Texture.TextureGL.WrapMode = WrapTexture ? TextureWrapMode.Repeat : TextureWrapMode.ClampToEdge; Blit(vertexAction); shader.Unbind(); }
public override void SetupShader(IShader shader) { base.SetupShader(shader); if (shader is ISourceRectShader sourceRectShader) { sourceRectShader.SourceRect.SetValue(Texture.SourceRectangle.ToVector()); } if (shader is ITextureShader textureShader) { textureShader.Texture.SetValue(Texture.GLTexture); } if (shader is IOffsetShader offsetShader) { offsetShader.Offset.SetValue(Offset); } }
public void SetSampler(IShader shader, string name, ISampler sampler) { if (name == null) { throw new ArgumentNullException("name"); } if (sampler == null) { throw new ArgumentNullException("sampler"); } if (shader == null) { throw new ArgumentNullException("shader"); } var internalShader = graphicsDevice.Cast <Shader>(shader, "shader"); graphicsDevice.BindManager.SetSampler(sampler, internalShader.GetTextureUnit(name)); }
private void addShadingCache(ShadingState state, IShader shader, Color c) { lock (lockObj) { // don't cache samples with null normals if (state.getNormal() == null) { return; } cacheEntryAdditions++; int cx = (int)(state.getRasterX() * shadingCacheResolution); int cy = (int)(state.getRasterY() * shadingCacheResolution); int h = hashfunc(cx, cy) & (_shadingCache.Length - 1); CacheEntry e = _shadingCache[h]; // new entry ? if (e == null) { e = _shadingCache[h] = new CacheEntry(); } Sample s = new Sample(); s.i = state.getInstance(); // s.prim = state.getPrimitiveID(); s.s = shader; s.c = c; s.nx = state.getNormal().x; s.ny = state.getNormal().y; s.nz = state.getNormal().z; if (e.cx == cx && e.cy == cy) { // same pixel - just add to the front of the list s.next = e.first; e.first = s; } else { // different pixel - new list e.cx = cx; e.cy = cy; s.next = null; e.first = s; } } }
public void SetTexture(IShader shader, string name, ITexture2DArray texture) { if (name == null) { throw new ArgumentNullException("name"); } if (texture == null) { throw new ArgumentNullException("texture"); } if (shader == null) { throw new ArgumentNullException("shader"); } var internalShader = graphicsDevice.Cast <Shader>(shader, "shader"); graphicsDevice.BindManager.SetTexture(texture, internalShader.GetTextureUnit(name)); }
private void SetTexture(IShader shader, string name, ShaderResourceView view) { if (shader != currentState.Shader) { throw new ArgumentException("Shader does not match current set shader.", "shader"); } var dxShader = graphicsDevice.Cast <Shader>(shader, "shader"); int slot; if (dxShader.TryGetSlotVertex(name, out slot)) { SetTexture(Context.VertexShader, vertexCache, slot, view); } if (dxShader.TryGetSlotPixel(name, out slot)) { SetTexture(Context.PixelShader, pixelCache, slot, view); } }
public override void SetupShader(IShader shader) { base.SetupShader(shader); if (shader is ITextureIndexShader textureIndexShader) { textureIndexShader.TextureIndex.Setup(VertexBuffer, TextVertex.TextureIndexOffset); } if (shader is IPosition2Shader positionShader) { positionShader.Position.Setup(VertexBuffer, TextVertex.PositionOffset); } if (shader is ITexCoordShader texCoordShader) { texCoordShader.TexCoord.Setup(VertexBuffer, TextVertex.TexCoordOffset); } }
private void activateShader() { var shader = AGSGame.Shader; if (shader != null) { shader = shader.Compile(); } if (shader == null) { if (_lastShaderUsed != null) { _lastShaderUsed.Unbind(); } return; } _lastShaderUsed = shader; shader.Bind(); }
protected virtual void Initialize() { textureName = null; duration = TimeSpan.FromSeconds(1); durationRandomness = 0; emitterVelocitySensitivity = 1; minHorizontalVelocity = 0; maxHorizontalVelocity = 0; minVerticalVelocity = 0; maxVerticalVelocity = 0; gravity = new Vector3(); endVelocity = 1; minColor = Color.White; maxColor = Color.White; minRotateSpeed = 0; maxRotateSpeed = 0; minStartSize = 100; maxStartSize = 100; minEndSize = 100; maxEndSize = 100; blendState = BlendState.NonPremultiplied; currentTime = 0; drawOrder = 0; up = Vector3.UnitY; right = Vector3.UnitX; forward = Vector3.UnitZ; // Allocate the particle array, and fill in the corner fields (which never change). particles = new ParticleVertex[maxParticles * 4]; for (int i = 0; i < maxParticles; i++) { particles[i * 4 + 0].Corner = new Short2(-1, -1); particles[i * 4 + 1].Corner = new Short2(1, -1); particles[i * 4 + 2].Corner = new Short2(1, 1); particles[i * 4 + 3].Corner = new Short2(-1, 1); } shader = new ParticleShader(); shaderTechnique = "Particles"; enabled = true; }
public static void Triangle(Image image, Vec4f [] pts, IShader shader, float [] zbuffer) { Vec2i pMin, pMax; Box(pts, out pMin, out pMax); Color color; for (int x = pMin.x; x <= pMax.x; x++) { for (int y = pMin.y; y <= pMax.y; y++) { var pixelCenter = new Vec2f { x = x + 0.5f, y = y + 0.5f }; var bc = Barycentric(Project2D(pts [0] / pts [0].h), Project2D(pts [1] / pts [1].h), Project2D(pts [2] / pts [2].h), pixelCenter); var z = pts [0].z * bc.x + pts [1].z * bc.y + pts [2].z * bc.z; // z [0..255] var w = pts [0].h * bc.x + pts [1].h * bc.y + pts [2].h * bc.z; var frag_depth = z / w; var idx = x + y * image.Width; if (bc.x < 0 || bc.y < 0 || bc.z < 0 || zbuffer[idx] > frag_depth) { continue; } var discard = shader.Fragment(new Vec3f { x = x, y = y, z = frag_depth }, bc, out color); if (!discard) { zbuffer [idx] = frag_depth; image [x, y] = color; } } } }
public CubeShader(IOpenGL30 gl) { // Create the vertex shader vertexShader = new VertexShader(gl, GetEmbeddedResourceAsString("cube.vs")); // Create the fragmet shader fragmentShader = new FragmentShader(gl, GetEmbeddedResourceAsString("cube.fs")); // Create the program for both shaders var p = new ModGL.ObjectModel.Shaders.Program(gl, vertexShader, fragmentShader); // Tell the shader what field names to use (taken from the vertex Descriptor) p.BindVertexAttributeLocations(PositionNormalTexCoord.Descriptor); // Bind output fragment to the specified nme gl.BindFragDataLocation(p.Handle, 0, "Color"); // Compile program and shaders p.Compile(); program = p; // Get the uniforms used by the shader program. modelViewProjection = p.GetUniform<MatrixUniform, Matrix4f>("ModelViewProjection"); viewProjection = p.GetUniform<MatrixUniform, Matrix4f>("ViewProjection"); diffuseUniform = p.GetUniform<Vector4fUniform, Vector4f>("DiffuseColor"); }
public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc) : base(parent) { try { var video = parent.FindParentOrSelfWithException <Video>(); com = new BufferLayoutCom(); var error = com.Init(video.com, ((Shader)shader).vertex.com, ((BufferLayoutDesc)desc).com); if (error == BufferLayoutErrors.InputLayout) { Debug.ThrowError("BufferLayout", "Failed to create InputLayout"); } } catch (Exception e) { Dispose(); throw e; } }
static RenderResult Render(Model model, IShader shader) { var image = new Image(width, height, Format.BGR); var zbuffer = InitZBuffer(image); var screen_coords = new Vec4f [3]; foreach (var face in model.Faces) { for (int i = 0; i < 3; i++) { screen_coords [i] = shader.Vertex(face, i); } Triangle(image, screen_coords, shader, zbuffer); } return(new RenderResult { Image = image, ZBuffer = zbuffer }); }
public override void ApplyState() { base.ApplyState(); shader = Source.shader; texture = Source.texture; drawSize = Source.DrawSize; points = Source.ResampledWaveform?.GetPoints(); channels = Source.ResampledWaveform?.GetChannels() ?? 0; lowColour = Source.lowColour ?? DrawColourInfo.Colour; midColour = Source.midColour ?? DrawColourInfo.Colour; highColour = Source.highColour ?? DrawColourInfo.Colour; if (points?.Any() == true) { highMax = points.Max(p => p.HighIntensity); midMax = points.Max(p => p.MidIntensity); lowMax = points.Max(p => p.LowIntensity); } }
/// <summary> /// Initializes the 2D rendering system /// </summary> internal static void Init() { ProfilerTimer.Profile(() => { rendererData = new Renderer2DStorage { QuadVertexArray = IVertexArray.Create() }; float[] squareVertices = { -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f }; IVertexBuffer squareVertexBuffer = IVertexBuffer.Create(squareVertices, squareVertices.GetBytes()); BufferLayout squareBufferLayout = new BufferLayout(new[] { new BufferElement("a_Position", ShaderDataType.Float3), new BufferElement("a_TexCoord", ShaderDataType.Float2) }); squareVertexBuffer.SetLayout(squareBufferLayout); rendererData.QuadVertexArray.AddVertexBuffer(squareVertexBuffer); uint[] squareIndices = { 0, 1, 2, 2, 3, 0 }; IIndexBuffer squareIndexBuffer = IIndexBuffer.Create(squareIndices, squareIndices.GetBytes() / sizeof(uint)); rendererData.QuadVertexArray.SetIndexBuffer(squareIndexBuffer); rendererData.WhiteTexture = I2DTexture.Create(1, 1); uint whiteTextureData = 0xffffffff; rendererData.WhiteTexture.SetData(whiteTextureData, sizeof(uint)); rendererData.TextureShader = IShader.Create("Shaders/Texture.glsl"); rendererData.TextureShader.Bind(); rendererData.TextureShader.SetInt("u_Texture", 0); }); }
public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc) : base(parent) { try { var video = parent.FindParentOrSelfWithException<Video>(); com = new BufferLayoutCom(); var error = com.Init(video.com, ((BufferLayoutDesc)desc).com); switch (error) { case BufferLayoutErrors.VertexDeclaration: Debug.ThrowError("BufferLayout", "Failed to create vertex declaration"); break; } } catch (Exception e) { Dispose(); throw e; } }
private void onBeforeRender() { var shader = _shakeShader; if (shader != null) { shader = shader.Compile(); } if (shader == null || shader != getActiveShader()) { _shakeShader = null; AGSGame.Game.Events.OnBeforeRender.Unsubscribe(onBeforeRender); return; } shader.Bind(); shader.SetVariable("time", (float)Repeat.Do("ShakeEffect")); var currentStrength = _strength + MathUtils.Random().Next(1000) / 1000000f; //Adding a little jerkiness shader.SetVariable("strength", currentStrength); _strength = _strength * _decay; }
/// <summary>Construct the object and create the required GPU resources</summary> public CursorRenderer(Context context, IRenderDevice device) { this.context = context; vertexBuffer = createVertexBuffer(device); iShaderFactory shaderFactory = device.GetShaderFactory(); iStorageFolder assets = StorageFolder.embeddedResources(Assembly.GetExecutingAssembly(), resourceFolder); IShader vs = shaderFactory.compileHlslFile(assets, "CursorVS.hlsl", ShaderType.Vertex); using (iPipelineStateFactory stateFactory = device.CreatePipelineStateFactory()) { staticCursor = new StaticCursor(context, device, stateFactory, shaderFactory, assets, vs); animatedCursor = new AnimatedCursor(context, device, stateFactory, shaderFactory, assets); monochromeCursor = new MonoCursor(context, device, stateFactory, shaderFactory, assets, vs); } cursorPosition.setWindowSize(context.swapChainSize); // Subscribe to the resized event context.swapChainResized.add(this, onSwapChainResized); }
public void LoadContent(ContentState state) { this.texture = state.Load<Texture2D>("skydome/cloudMap"); this.model.ModelData = state.Load<ModelData>("skydome/dome"); MaterialShader material = new MaterialShader(); material.SpecularColour = new Vector3(1, 1, 1); material.DiffuseColour = new Vector3(0.6f, 0.6f, 0.6f); material.SpecularPower = 64; MaterialTextures textures = new MaterialTextures(); textures.TextureMap = state.Load<Texture2D>("skydome/cloudMap"); textures.TextureMapSampler = TextureSamplerState.AnisotropicHighFiltering; textures.EmissiveTextureMapSampler = TextureSamplerState.AnisotropicHighFiltering; textures.NormalMapSampler = TextureSamplerState.AnisotropicHighFiltering; material.Textures = textures; this.shader = material; }
public void set(ShadingState state) { if (state == null) { c = Color.BLACK; } else { c = state.getResult(); checkNanInf(); shader = state.getShader(); instance = state.getInstance(); if (state.getNormal() != null) { nx = state.getNormal().x; ny = state.getNormal().y; nz = state.getNormal().z; } } n = 1; }
public BufferLayout(IDisposableResource parent, IShader shader, IBufferLayoutDesc desc) : base(parent) { try { var video = parent.FindParentOrSelfWithException <Video>(); com = new BufferLayoutCom(); var error = com.Init(video.com, ((BufferLayoutDesc)desc).com); switch (error) { case BufferLayoutErrors.VertexDeclaration: Debug.ThrowError("BufferLayout", "Failed to create vertex declaration"); break; } } catch (Exception e) { Dispose(); throw e; } }
public Font(IDisposableResource parent, IShader shader, ITexture2D texture, string metricsFileName, Loader.LoadedCallbackMethod loadedCallback) : base(parent) { new StreamLoader(metricsFileName, delegate(object sender, bool succeeded) { if (succeeded) { init(shader, texture, ((StreamLoader)sender).LoadedStream, metricsFileName, loadedCallback); } else { FailedToLoad = true; Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } } }); }
public void add(ShadingState state, IShader shader, Color c) { if (state.getNormal() == null) { return; } depth++; Sample s = new Sample(); s.i = state.getInstance(); s.s = shader; s.c = c; s.dx = state.getRay().dx; s.dy = state.getRay().dy; s.dz = state.getRay().dz; s.nx = state.getNormal().x; s.ny = state.getNormal().y; s.nz = state.getNormal().z; s.next = first; first = s; }
public LineRenderer( Renderer renderer, IShader shader ) { this.renderer = renderer; this.shader = shader; }
public void Create() { _vertexShader = _openGlResourceFactory.CreateShader(ShaderType.VertexShader); _vertexShader.SetSource(VertexShaderSource); _vertexShader.Compile(); _fragmentShader = _openGlResourceFactory.CreateShader(ShaderType.FragmentShader); _fragmentShader.SetSource(FragmentShaderSource); _fragmentShader.Compile(); _geometryShader = _openGlResourceFactory.CreateShader(ShaderType.GeometryShader); _geometryShader.SetSource(GeometryShaderSource); _geometryShader.Compile(); Program = _openGlResourceFactory.CreateProgram(); Program.Create(); Program.AttachShader(_vertexShader); Program.AttachShader(_geometryShader); Program.AttachShader(_fragmentShader); Program.Link(); ProjectionMatrix = Program.GetUniform<Matrix4>("ProjectionMatrix"); ViewMatrix = Program.GetUniform<Matrix4>("ViewMatrix"); ModelMatrix = Program.GetUniform<Matrix4>("ModelMatrix"); Color = Program.GetUniform<Vector4>("Color"); WindowScale = Program.GetUniform<Vector2>("WindowScale"); }
public QuadRenderer(Renderer renderer, IShader shader) { this.renderer = renderer; this.shader = shader; }
public void setShaderOverride(IShader shader, bool photonOverride) { shaderOverride = shader; shaderOverridePhotons = photonOverride; }