daily update on 20240513 by nitload youmu, instancing render added
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#version 460 core
|
||||
|
||||
out vec3 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
fragColor = vec3( 0.5f,0.336f,0.9961f );
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#version 460 core
|
||||
|
||||
|
||||
layout(location = 0) in vec3 singleCoord;
|
||||
layout(location = 1) in vec3 locations;
|
||||
layout(location = 2) in float rotation;
|
||||
layout(location = 3) in float scale;
|
||||
|
||||
uniform mat4x4 Camera;
|
||||
|
||||
void main()
|
||||
{
|
||||
/**/
|
||||
mat4x4 scalingMat = mat4x4
|
||||
(
|
||||
scale,0,0,0,
|
||||
0,scale,0,0,
|
||||
0,0,scale,0,
|
||||
0,0,0,1
|
||||
);
|
||||
/**/
|
||||
/**/
|
||||
|
||||
mat4x4 rotationMat = mat4x4
|
||||
(
|
||||
cos(rotation),-sin(rotation),0,0,
|
||||
sin(rotation),cos(rotation),0,0,
|
||||
0,0,1,0,
|
||||
0,0,0,1
|
||||
);
|
||||
|
||||
/**/
|
||||
|
||||
gl_Position = Camera * ( rotationMat * scalingMat * vec4( singleCoord.xyz , 1) + vec4( locations.xyz , 0));
|
||||
|
||||
}
|
||||
@@ -104,6 +104,12 @@
|
||||
<None Update="Shader\Image1.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Shader\particle.vert">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Shader\particle.frag">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Shader\vertex.vert">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -82,8 +82,8 @@ namespace StgSharp
|
||||
(IntPtr id, uint width, uint height) => GL.Viewport(0, 0, width, height);
|
||||
|
||||
shader = CreateShaderProgram();
|
||||
var vertex = CreateShaderSegment(ShaderType.Vertex, 1);
|
||||
var fragment = CreateShaderSegment(ShaderType.Fragment, 1);
|
||||
Shader vertex = CreateShaderSegment(ShaderType.Vertex, 1);
|
||||
Shader fragment = CreateShaderSegment(ShaderType.Fragment, 1);
|
||||
vertex.Compile(0, File.ReadAllText("Shader\\vertex.vert"));
|
||||
vertex.AttachTo(0, shader);
|
||||
fragment.Compile(0, File.ReadAllText("Shader\\fragment.frag"));
|
||||
@@ -116,14 +116,19 @@ namespace StgSharp
|
||||
1.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f };
|
||||
GL.BindVertexArray(vao[0]);
|
||||
|
||||
vao.Bind(0);
|
||||
|
||||
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
|
||||
vbo.SetValue(0, rec.VertexBuffer, BufferUsage.STATIC_DRAW);
|
||||
GL.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vbo.SetValueArray(1, texCoord, BufferUsage.STATIC_DRAW);
|
||||
GL.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0);
|
||||
|
||||
vbo.WriteMatrixData(0, rec.VertexBuffer, BufferUsage.STATIC_DRAW);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
vbo.WriteScalerData(1, texCoord, BufferUsage.STATIC_DRAW);
|
||||
vao.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0);
|
||||
|
||||
/**/
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
|
||||
vbo.Unbind();
|
||||
vao.BindNull();
|
||||
/**/
|
||||
texture.Bind2D(0);
|
||||
@@ -191,34 +196,37 @@ namespace StgSharp
|
||||
|
||||
//Console.WriteLine(NativeCamera.Projection);
|
||||
|
||||
GL.DrawElements(GepmetryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
|
||||
vao.BindNull();
|
||||
/**/
|
||||
BlueprintPipeline.SkipAll(output);
|
||||
|
||||
PollEvents();
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
protected override void ProcessInput()
|
||||
{
|
||||
float movement = 0.005f;
|
||||
|
||||
|
||||
if (InternalIO.glfwGetKey(CanvasHandle, (int)KeyboardKey.ESCAPE)
|
||||
== KeyStatus.PRESS)
|
||||
{
|
||||
InternalIO.glfwSetWindowShouldClose(CanvasHandle, 1);
|
||||
return;
|
||||
}
|
||||
if (InternalIO.glfwGetKey(CanvasHandle, (int)KeyboardKey.LEFT_SHIFT)
|
||||
if (InternalIO.glfwGetKey(CanvasHandle, (int)KeyboardKey.LeftShift)
|
||||
== KeyStatus.PRESS)
|
||||
{
|
||||
movement = 0.002f;
|
||||
}
|
||||
if (InternalIO.glfwGetKey(this.CanvasHandle, GLconst.GLFW_KEY_UP) == KeyStatus.PRESS)
|
||||
if (InternalIO.glfwGetKey(this.CanvasHandle, (int)KeyboardKey.UP) == KeyStatus.PRESS)
|
||||
{
|
||||
//Console.WriteLine(8);
|
||||
NativeCamera.Pitch(new Radius(movement));
|
||||
}
|
||||
else if (InternalIO.glfwGetKey(this.CanvasHandle, GLconst.GLFW_KEY_DOWN) == KeyStatus.PRESS)
|
||||
else if (InternalIO.glfwGetKey(this.CanvasHandle, (int)KeyboardKey.DOWN) == KeyStatus.PRESS)
|
||||
{
|
||||
//Console.WriteLine(2);
|
||||
NativeCamera.Pitch(new Radius(-movement));
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ParticleStream : glRenderStream
|
||||
{
|
||||
public ParticleStream(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override string[] InputPortsName => ["input_1"];
|
||||
|
||||
protected override string[] OutputPortsName => ["output_1"];
|
||||
|
||||
protected override void Deinit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ShaderProgram s;
|
||||
PlainInstancingBuffer<ParticleOnPlain> buffer;
|
||||
VertexBuffer vbo;
|
||||
VertexArray vao;
|
||||
ElementBuffer ebo;
|
||||
|
||||
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
ParticleOnPlain p = new ParticleOnPlain(buffer);
|
||||
((IInstancing<ParticleOnPlain>)p).Coord = new vec3d(
|
||||
(-5 + i) * 0.2f + 0.1f, (-5 + t) * 0.2f + 0.1f, 0);
|
||||
((IInstancing<ParticleOnPlain>)p).Scale = Scaler.MinOf(i,t) * 0.2f;
|
||||
((IInstancing<ParticleOnPlain>)p).Motion = GeometryMotion.DefaultMotion;
|
||||
}
|
||||
}
|
||||
|
||||
SetSizeLimit(800, 800, 800, 800);
|
||||
|
||||
FrameSizeCallback =
|
||||
(IntPtr id, uint width, uint height) => GL.Viewport(0, 0, width, height);
|
||||
|
||||
s = CreateShaderProgram();
|
||||
Shader pvs = CreateShaderSegment(ShaderType.Vertex ,1);
|
||||
Shader pfs = CreateShaderSegment(ShaderType.Fragment ,1);
|
||||
|
||||
pvs.Compile(0, Shader.FromCodeFile("Shader\\particle.vert"));
|
||||
pvs.AttachTo(0,s);
|
||||
pfs.Compile(0, Shader.FromCodeFile("Shader\\particle.frag"));
|
||||
pfs.AttachTo(0,s);
|
||||
s.Link();
|
||||
|
||||
vbo = CreateVertexBuffer(3);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
vbo.Bind(0);
|
||||
|
||||
Rectangle rec = new Rectangle
|
||||
(
|
||||
0.05f,0.05f,0.0f,
|
||||
0.05f,-0.05f,0.0f,
|
||||
-0.05f,-0.05f,0.0f,
|
||||
-0.05f,0.05f,0.0f
|
||||
);
|
||||
|
||||
vao.Bind(0);
|
||||
vbo.WriteMatrixData(0, rec.vertexMat, BufferUsage.STATIC_DRAW);
|
||||
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float),0);
|
||||
|
||||
vbo.WriteVectorData(1, buffer.CoordSpan,BufferUsage.STATIC_DRAW);
|
||||
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
|
||||
|
||||
GL.VertexAttributeDivisor(1, 1);
|
||||
GL.VertexAttributeDivisor(2, 1);
|
||||
|
||||
vbo.WriteScalerData(2, buffer.ScalingSpan, BufferUsage.STATIC_DRAW);
|
||||
vao.SetVertexAttribute(3,1,TypeCode.Single,false,sizeof(float),0);
|
||||
|
||||
GL.VertexAttributeDivisor(3, 1);
|
||||
|
||||
vbo.Unbind();
|
||||
vao.BindNull();
|
||||
|
||||
NativeCameraViewTarget
|
||||
(
|
||||
(0,0,-100),
|
||||
(0,0,0),
|
||||
(0,1,0)
|
||||
);
|
||||
NativeCameraViewRange(new Degree(1.7f),Vec2d.Zero,(50,50));
|
||||
NativeCameraUniform(s,"Camera");
|
||||
}
|
||||
|
||||
protected override void Main(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output)
|
||||
{
|
||||
|
||||
GL.ClearColor(0.6f,0.1f,0.3f,1);
|
||||
GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
|
||||
|
||||
vao.Bind(0);
|
||||
s.Use();
|
||||
|
||||
NativeCamera.SetAllUniforms();
|
||||
|
||||
GL.DrawElementsInstanced(
|
||||
GeometryType.TRIANGLES, 6, TypeCode.UInt32,IntPtr.Zero,100
|
||||
);
|
||||
|
||||
vao.BindNull();
|
||||
|
||||
BlueprintPipeline.SkipAll(output);
|
||||
|
||||
SwapBuffers();
|
||||
PollEvents();
|
||||
|
||||
}
|
||||
|
||||
protected override void ProcessInput()
|
||||
{
|
||||
if (CheckKey(KeyboardKey.ESCAPE) == KeyStatus.PRESS)
|
||||
{
|
||||
InternalIO.glfwSetWindowShouldClose(CanvasHandle, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,6 @@ namespace StgSharp
|
||||
{
|
||||
try
|
||||
{
|
||||
InternalIO.InternalWriteLog($"Program Started",LogType.Info);
|
||||
|
||||
//StgSharp.TryCreatWindow();
|
||||
|
||||
/**/
|
||||
@@ -47,8 +45,10 @@ namespace StgSharp
|
||||
demoForm.Size = (800, 800);
|
||||
demoForm.name = "Hello, Stg#!";
|
||||
|
||||
MainRenderStream stream = glRenderStream.AsMainStreamOf
|
||||
<MainRenderStream>(demoForm,(1,1,1));
|
||||
var stream = glRenderStream.AsMainStreamOf
|
||||
//<MainRenderStream>
|
||||
<ParticleStream>
|
||||
(demoForm,(1,1,1));
|
||||
|
||||
Blueprint blueprint = new Blueprint();
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fc19ab32989e5a60c1061ad8ebea16cd5a3c6ff0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+56459deec57aa5078d6bb5991dbf32f29c06e826")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -26,3 +26,5 @@ D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.xml
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.pdb
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.genruntimeconfig.cache
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\Shader\particle.frag
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\Shader\particle.vert
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/fc19ab32989e5a60c1061ad8ebea16cd5a3c6ff0/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/56459deec57aa5078d6bb5991dbf32f29c06e826/*"}}
|
||||
Reference in New Issue
Block a user