void SetUp() { tri = GetComponent <TriangleBuffer>(); vert = GetComponent <VertBuffer>(); values = new float[dimensions * dimensions * dimensions * 8]; for (int i = 0; i < dimensions * dimensions * dimensions; i++) { values[i * 8 + 0] = 1000; values[i * 8 + 1] = 1000; values[i * 8 + 2] = 1000; values[i * 8 + 3] = 1000; values[i * 8 + 4] = 1000; values[i * 8 + 5] = 1000; values[i * 8 + 6] = 1000; values[i * 8 + 7] = 1000; } vertCount = dimensions * dimensions * dimensions; numGroups = (vertCount + (numThreads - 1)) / numThreads; k_depth = calcShader.FindKernel("GetDepth"); k_normal = calcShader.FindKernel("GetNormal"); k_finalDepth = calcShader.FindKernel("GetFinalDist"); calculated = false; normalsCalculated = false; }
// Use this for initialization void Start() { if (vertBuffer == null) { vertBuffer = gameObject.GetComponent <VertBuffer>(); } if (triBuffer == null) { triBuffer = gameObject.GetComponent <TriangleBuffer>(); } print(distBetweenHairs); fullVertCount = totalHairs * numVertsPerHair; material = new Material(material); numGroups = (fullVertCount + (numThreads - 1)) / numThreads; _kernelCollision = collisionShader.FindKernel("CSMain"); _kernelConstraint = constraintShader.FindKernel("CSMain"); CreateBuffers(); Reset(); }
// Use this for initialization void Start() { if (vertBuffer == null) { vertBuffer = gameObject.GetComponent <VertBuffer>(); } if (triBuffer == null) { triBuffer = gameObject.GetComponent <TriangleBuffer>(); } if (cloneVertBuffer == null) { cloneVertBuffer = toClone.GetComponent <VertBuffer>(); } if (cloneTriBuffer == null) { cloneTriBuffer = toClone.GetComponent <TriangleBuffer>(); } material = new Material(material); numGroups = (numberMeshes + (numThreads - 1)) / numThreads; _kernel = physics.FindKernel("CSMain"); CreateBuffers(); }
// Use this for initialization void Start() { if (vertBuffer == null) { vertBuffer = gameObject.GetComponent <VertBuffer>(); } if (triBuffer == null) { triBuffer = gameObject.GetComponent <TriangleBuffer>(); } print(distBetweenHairs); transformValues = new float[16]; fullVertCount = totalHairs * numVertsPerHair; material = new Material(material); numGroups = (fullVertCount + (numThreads - 1)) / numThreads; outBuffer = new ComputeBuffer(numThreads, 4 * sizeof(float)); outFloats = new float[numThreads * 4]; finalBuffer = new ComputeBuffer(1, 4 * sizeof(float)); finalFloats = new float[4]; _kernelCollision = collisionShader.FindKernel("CSMain"); _kernelConstraint = constraintShader.FindKernel("CSMain"); CreateBuffers(); Reset(); }
/// \exception Ogre::InvalidParametersException Input triangle buffer must not be null public SpherifyModifier setInputTriangleBuffer(TriangleBuffer inputTriangleBuffer) { if (inputTriangleBuffer == null) OGRE_EXCEPT("Ogre::Exception::ERR_INVALIDPARAMS", "Input triangle buffer must not be null", "Procedural::SpherifyModifier::setInputTriangleBuffer(Procedural::TriangleBuffer*)"); ; mInputTriangleBuffer = inputTriangleBuffer; return this; }
private void DrawBlockBottom(TriangleBuffer buffer, WorldTextureAtlas.TextureEntry textureEntry, float x, float y, float z, float highlight) { buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x - 0.5f, y - 0.5f, z + 0.5f); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex(); buffer.VertexFloat(x - 0.5f, y - 0.5f, z - 0.5f); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex(); buffer.VertexFloat(x + 0.5f, y - 0.5f, z - 0.5f); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex(); buffer.VertexFloat(x + 0.5f, y - 0.5f, z + 0.5f); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex(); }
private void RenderChunk(TriangleBuffer buffer, Chunk chunk) { var offset = chunk.Pos - new BlockPos(0, 0, 0); float xOffset = offset.X + 0.5f; float yOffset = offset.Y + 0.5f; float zOffset = offset.Z + 0.5f; for (int y = GeometryConstants.ChunkSize - 1; y >= 0; --y) { for (int x = 0; x < GeometryConstants.ChunkSize; ++x) { for (int z = 0; z < GeometryConstants.ChunkSize; ++z) { ushort material = chunk[x, y, z]; if (material != 0) { var textureEntry = _textureAtlas.GetTextureEntry(material); float x1 = x + xOffset, y1 = y + yOffset, z1 = z + zOffset; if (x == 0 || chunk[x - 1, y, z] == 0) { DrawBlockLeft(buffer, textureEntry, x1, y1, z1, 0); } if (x == GeometryConstants.ChunkSize - 1 || chunk[x + 1, y, z] == 0) { DrawBlockRight(buffer, textureEntry, x1, y1, z1, 0); } if (y == 0 || chunk[x, y - 1, z] == 0) { DrawBlockBottom(buffer, textureEntry, x1, y1, z1, 0); } if (y == GeometryConstants.ChunkSize - 1 || chunk[x, y + 1, z] == 0) { DrawBlockTop(buffer, textureEntry, x1, y1, z1, 0); } if (z == 0 || chunk[x, y, z - 1] == 0) { DrawBlockBack(buffer, textureEntry, x1, y1, z1, 0); } if (z == GeometryConstants.ChunkSize - 1 || chunk[x, y, z + 1] == 0) { DrawBlockFront(buffer, textureEntry, x1, y1, z1, 0); } } } } } }
public override float AddSingleResult(LocalRayResult rayResult, bool normalInWorldSpace) { var meshObject = rayResult.CollisionObject.CollisionShape as BvhTriangleMeshShape; if (meshObject == null) { return(base.AddSingleResult(rayResult, normalInWorldSpace)); } ; var triangleBuffer = new TriangleBuffer( ); meshObject.PerformRaycast(triangleBuffer, RayFromWorld, RayToWorld); var rayFromWorld = RayFromWorld; var rayTarget = RayToWorld - rayFromWorld; float closestFrontFace = 1f; for (int i = 0; i < triangleBuffer.NumTriangles; i++) { var triangle = triangleBuffer.GetTriangle(i); var edge1 = triangle.vertex1 - triangle.vertex0; var edge2 = triangle.vertex2 - triangle.vertex0; var normal = Vector3.Cross(edge1, edge2); var dot = _ccw ? Vector3.Dot(rayTarget, normal) : -Vector3.Dot(normal, rayTarget); if (dot > 0) { continue; } float t; if (TriangleRayIntersection.Test(triangle.vertex0, triangle.vertex1, triangle.vertex2, rayFromWorld, rayTarget, out t)) { closestFrontFace = closestFrontFace < t ? closestFrontFace : t; } } rayResult.HitFraction = closestFrontFace; if (closestFrontFace < ClosestHitFraction) { base.AddSingleResult(rayResult, normalInWorldSpace); } return(closestFrontFace); }
private void DrawEntity(TriangleBuffer buffer, float x, float y, float z, float xRadius, float height) { var textureEntry = _textureAtlas.GetTextureEntry(0); buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x - xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex(); buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x + xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x + xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x - xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x - xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex(); buffer.Triangle(0, 1, 3); buffer.Triangle(3, 1, 2); buffer.VertexFloat(x - xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex(); buffer.VertexFloat(x + xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex(); buffer.VertexFloat(x - xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex(); }
// Use this for initialization public override void BeforeCreateBuffer() { structSize = 1 + 16 + 2 + 3 + 3 + 3; if (vertBuffer == null) { vertBuffer = gameObject.GetComponent <VertBuffer>(); } if (triBuffer == null) { triBuffer = gameObject.GetComponent <TriangleBuffer>(); } if (cloneVertBuffer == null) { cloneVertBuffer = toClone.GetComponent <VertBuffer>(); } if (cloneTriBuffer == null) { cloneTriBuffer = toClone.GetComponent <TriangleBuffer>(); } }
private void RenderBlocks(GameClient gameClient) { GL.UseProgram(_cubeShader.Value.Id); GL.UniformMatrix4(0, false, ref _projectionMatrix); GL.UniformMatrix4(4, false, ref _modelViewMatrix); var cameraChunkPos = (ChunkPos)gameClient.PositionData.Placement.Pos; var offset = (gameClient.PositionData.Placement.Pos - EntityPos.Origin) + new EntityOffset(0, gameClient.PhysicsValues.PlayerEyeHeight, 0); int chunkUpdates = 0; ChunkPos.IterateOutwards( cameraChunkPos, ChunkViewRadiusXZ, ChunkViewRadiusY, chunkPos => { ChunkBufferEntry entry; _chunkBuffers.TryGetValue(chunkPos, out entry); /* Don't let nearby entries expire. */ if (entry != null) { entry.LastAccess = _currentFrameTime; } if (!IsInViewingFrustum(gameClient, offset, chunkPos)) { return; } var chunk = gameClient.World.PeekChunk(chunkPos); if (chunk != null && chunk.HasData) { if (entry == null) { entry = new ChunkBufferEntry { LastAccess = _currentFrameTime }; _chunkBuffers[chunkPos] = entry; } if (entry.ContentHash != chunk.ContentHash) { if (chunkUpdates < 5 && entry.TriangleTask != null && entry.TriangleTask.IsCompleted) { var triangles = entry.TriangleTask.Result; if (entry.TriangleTaskContentHash == chunk.ContentHash) { ++chunkUpdates; if (entry.VertexArray == null) { entry.VertexArray = new VertexArray(_cubeVertexSpecification); } entry.VertexArray.SetData(triangles, BufferUsageHint.StaticDraw); entry.ContentHash = chunk.ContentHash; } triangles.Dispose(); entry.TriangleTask = null; entry.TriangleTaskContentHash = 0; } if (entry.ContentHash != chunk.ContentHash && entry.TriangleTask == null) { var triangleBuffer = new TriangleBuffer(_cubeVertexSpecification); var localChunk = chunk; entry.TriangleTask = Task.Run(() => { RenderChunk(triangleBuffer, localChunk); return(triangleBuffer); }); entry.TriangleTaskContentHash = chunk.ContentHash; } } entry.VertexArray?.Draw(); } }); GL.UseProgram(0); RemoveExpiredChunks(); }
public BoxUVModifier setInputTriangleBuffer(TriangleBuffer inputTriangleBuffer) { mInputTriangleBuffer = inputTriangleBuffer; return this; }
public static void VertexColorBytes(this TriangleBuffer buffer, float r, float g, float b, float a) { buffer.VertexByte(GetColorByte(r), GetColorByte(g), GetColorByte(b), GetColorByte(a)); }
public override float AddSingleResult(LocalRayResult rayResult, bool normalInWorldSpace) { var collisionObject = rayResult.CollisionObject; if (collisionObject == null) { return(base.AddSingleResult(rayResult, normalInWorldSpace)); } var meshShape = collisionObject.CollisionShape as BvhTriangleMeshShape; if (meshShape == null) { return(base.AddSingleResult(rayResult, normalInWorldSpace)); } var meshObject = rayResult.CollisionObject.CollisionShape as BvhTriangleMeshShape; if (meshObject == null) { return(base.AddSingleResult(rayResult, normalInWorldSpace)); } var rayFromWorld = RayFromWorld; var rayDirection = RayToWorld - rayFromWorld; var triangleBuffer = new TriangleBuffer( ); meshShape.PerformRaycast(triangleBuffer, RayFromWorld, RayToWorld); float closestFrontFace = 1000f; for (int i = 0; i < triangleBuffer.NumTriangles; i++) { var triangle = triangleBuffer.GetTriangle(i); var triangleIndex = triangle.triangleIndex * 3; var info = meshShape.MeshInterface as InfoTriangleIndexVertexArray; var part = info?.IndexedMeshArray[triangle.partId]; if (part == null) { continue; } var edge1 = triangle.vertex1 - triangle.vertex0; var edge2 = triangle.vertex2 - triangle.vertex0; var normal = Vector3.Cross(edge1, edge2); var dot = Vector3.Dot(normal, rayDirection); if (dot > 0) { continue; } float t; if (TriangleRayIntersection.Test(triangle.vertex0, triangle.vertex1, triangle.vertex2, rayFromWorld, rayDirection, out t)) { if (!(closestFrontFace < t)) { GLDebug.QueueTriangleDraw(ref triangle.vertex0, ref triangle.vertex1, ref triangle.vertex2); closestFrontFace = t; } } else { continue; } var bitangent = info.SurfaceInfo[triangle.partId].Bitangents[ part.TriangleIndices[triangleIndex]]; var tangent = Vector3.Cross(bitangent, normal); HitSurfaceTangent = tangent.Normalized(); HitSurfaceNormal = normal.Normalized(); HitSurfaceBitangent = bitangent.Normalized(); } rayResult.HitFraction = closestFrontFace; if (closestFrontFace < ClosestHitFraction) { base.AddSingleResult(rayResult, normalInWorldSpace); } return(closestFrontFace); }
public BoxUVModifier() { mInputTriangleBuffer = null; mMappingType = MappingType.MT_FULL; mBoxSize = Vector3.UNIT_SCALE; mBoxCenter = Vector3.ZERO; }
public SpherifyModifier() { mInputTriangleBuffer = null; mCenter = Vector3.ZERO; mRadius = 1f; }
public CalculateNormalsModifier setInputTriangleBuffer(TriangleBuffer inputTriangleBuffer) { mInputTriangleBuffer = inputTriangleBuffer; return this; }
/// Sets the input Triangle Buffer public ShowNormalsGenerator setTriangleBuffer(TriangleBuffer triangleBuffer) { mTriangleBuffer = triangleBuffer; return this; }
public HemisphereUVModifier setInputTriangleBuffer(TriangleBuffer inputTriangleBuffer) { mInputTriangleBuffer = inputTriangleBuffer; return this; }
internal RenderTriangleBuffer(TriangleBuffer triangleBuffer) { _triangleBuffer = triangleBuffer; }
public PlaneUVModifier() { mPlaneNormal = Vector3.UNIT_Y; mPlaneCenter = Vector3.ZERO; mPlaneSize = Vector2.UNIT_SCALE; mInputTriangleBuffer = null; }
public UnweldVerticesModifier setInputTriangleBuffer(TriangleBuffer inputTriangleBuffer) { mInputTriangleBuffer = inputTriangleBuffer; return this; }
public ReloadTriangleBuffer(TriangleBuffer triangleBuffer) { _triangleBuffer = triangleBuffer; }
public CylinderUVModifier() { mInputTriangleBuffer = null; mRadius = 1.0f; mHeight = 1.0f; }
public SphereUVModifier() { mInputTriangleBuffer = null; }
private void WriteVector(TriangleBuffer buffer, float x, float y) { buffer.VertexFloat(x * _xScale + _xOffset, y * _yScale + _yOffset); }
public HemisphereUVModifier() { mInputTriangleBuffer = null; mTextureRectangleTop = new Mogre.RealRect(0, 0, 1, 1); mTextureRectangleBottom = new Mogre.RealRect(0, 0, 1, 1); }
public ShowNormalsGenerator() { mTriangleBuffer = null; mSize = 1.0f; mVisualStyle = VisualStyle.VS_LINE; }