FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • Creating nose snot/cough splashed effect on cameramosharaf13
    I want to create a nose snot/cough/vomit splash effect on camera. The idea is that during gameplay NPC is gonna perform those actions on my first person view player. I was trying to modify below shader to have desired effect but I am struggling to change the color and position of droplets. https://github.com/yumayanagisawa/Unity-Raindrops https://github.com/yumayanagisawa/Unity-Raindrops/blob/master/Raindrop/Assets/Raindrop.shader Here's what I am trying to achieve Change position of droplets
     

Creating nose snot/cough splashed effect on camera

I want to create a nose snot/cough/vomit splash effect on camera. The idea is that during gameplay NPC is gonna perform those actions on my first person view player. I was trying to modify below shader to have desired effect but I am struggling to change the color and position of droplets.

https://github.com/yumayanagisawa/Unity-Raindrops

https://github.com/yumayanagisawa/Unity-Raindrops/blob/master/Raindrop/Assets/Raindrop.shader

Current state of the shader

Here's what I am trying to achieve

  1. Change position of droplets so that there is one or two blob in the middle and other droplets are splashing from it.
  2. Change color of the droplets to have beige tone.
  3. Remove vertical lines (Those are only appearing when I am using lerp at the end of the frag. Guessing it's a performance issue)
  • ✇Recent Questions - Game Development Stack Exchange
  • Marching cube terrain generated by compute shader gives strange errorLeo
    I'm creating my own terrain terrain system for Unity using marching cubes but I've run into a problem I'm stumped on. First I'll explain how it works: A compute shader creates an array of points placed in a 3D grid of sorts based on a given individual cube size, number of cubes per axis, and a number of chunks per axis in the terrain (right now it's working with only one chunk for simplicity). Each vertex also has a value property between 0 and 1, this is for the mesh generation next step and is
     

Marching cube terrain generated by compute shader gives strange error

I'm creating my own terrain terrain system for Unity using marching cubes but I've run into a problem I'm stumped on. First I'll explain how it works:

A compute shader creates an array of points placed in a 3D grid of sorts based on a given individual cube size, number of cubes per axis, and a number of chunks per axis in the terrain (right now it's working with only one chunk for simplicity). Each vertex also has a value property between 0 and 1, this is for the mesh generation next step and is set manually with an editor tool. This part works flawlessly.

Next, the mesh is generated one triangle at a time using the marching cube algorithm outlined here, and based a little on the project that's linked in the description here.

The code for the compute shader looks like this:

#pragma kernel CSMain
#include "MarchingTable.compute"

struct Vertex
{
    float3 position;
    float value;
};

struct Triangle
{
    float3 vertexC;
    float3 vertexB;
    float3 vertexA;
};

float surfaceLevel;
float3 chunkSize;

RWStructuredBuffer<Vertex> totalVertices;
AppendStructuredBuffer<Triangle> tBuffer;

float3 LerpVertex(float3 pointA, float3 pointB, float valueA, float valueB)
{
    float t = (surfaceLevel - valueA) / (valueB - valueA);
    return pointA + t * (pointB - pointA);
}

[numthreads(8, 1, 1)]
void CSMain(uint3 id : SV_DispatchThreadID, uint3 threadID: SV_DispatchThreadID)
{
  if (id.x >= chunkSize.y)
      return;

  uint chunkPower = (uint) ((chunkSize.x + 1) * (chunkSize.z + 1));
    
  uint componentY = threadID.x * (((uint) chunkSize.x + 1) * ((uint) chunkSize.z + 1));
    
  for (uint i = 0; i < chunkSize.x * chunkSize.z; i++)
  {   
      uint componentX = round(i % (uint) chunkSize.x);
      uint componentZ = round((i / (uint) chunkSize.x) * ((uint) chunkSize.x + 1));

      uint startPoint = componentX + componentZ + componentY;

      uint corners[8];

      corners[0] = startPoint;
      corners[1] = startPoint + 1;
      corners[2] = (uint) (startPoint + chunkSize.x + 2);
      corners[3] = (uint) (startPoint + chunkSize.x + 1);

      corners[4] = startPoint + chunkPower;
      corners[5] = startPoint + chunkPower + 1;
      corners[6] = (uint) (startPoint + chunkPower + chunkSize.x + 2);
      corners[7] = (uint) (startPoint + chunkPower + chunkSize.x + 1);

      int cubeIndex = 0;

      for (uint j = 0; j < 8; j++)
      {
          if (totalVertices[corners[j]].value < surfaceLevel)
              cubeIndex |= 1 << j;
      }
        
      int triangulation[16] = triangles[cubeIndex];
      
      for (uint k = 0; triangulation[k] != -1; k += 3)
      {
          int indexA1 = cornerIndexFromEdge[triangulation[k]][0];
          int indexB1 = cornerIndexFromEdge[triangulation[k]][1];

          int indexA2 = cornerIndexFromEdge[triangulation[k + 1]][0];
          int indexB2 = cornerIndexFromEdge[triangulation[k + 1]][1];
            
          int indexA3 = cornerIndexFromEdge[triangulation[k + 2]][0];
          int indexB3 = cornerIndexFromEdge[triangulation[k + 2]][1];
            
          float valueA1 = totalVertices[corners[indexA1]].value;
          float valueB1 = totalVertices[corners[indexB1]].value;

          float valueA2 = totalVertices[corners[indexA2]].value;
          float valueB2 = totalVertices[corners[indexB2]].value;
          float valueA3 = totalVertices[corners[indexA3]].value;
          float valueB3 = totalVertices[corners[indexB3]].value;
            
          Triangle tri;
            
          tri.vertexA = LerpVertex(totalVertices[corners[indexA1]].position, totalVertices[corners[indexB1]].position, valueA1, valueB1);
          tri.vertexB = LerpVertex(totalVertices[corners[indexA2]].position, totalVertices[corners[indexB2]].position, valueA2, valueB2);
          tri.vertexC = LerpVertex(totalVertices[corners[indexA3]].position, totalVertices[corners[indexB3]].position, valueA3, valueB3);
            
       tBuffer.Append(tri);
      }
   }
}

The C# code that dispatches it looks like this

void ConstructCube(ref TerrainDataObject.Chunk chunk, uint cIndex, uint chunkIndex)
{
    byte totalSize = sizeof(float) * 3 + sizeof(float);

    ComputeBuffer vertexBuffer = new ComputeBuffer(dataObject.vertices.Length, totalSize);
    vertexBuffer.SetData(dataObject.vertices);

    ComputeBuffer tBuffer = new ComputeBuffer((chunkSize.x * chunkSize.y * chunkSize.z) * 5, sizeof(float) * 3 * 3, ComputeBufferType.Append);
    ComputeBuffer tCountBuffer = new ComputeBuffer(1, sizeof(int), ComputeBufferType.Raw);

    vertexBuffer.SetCounterValue(0);
    meshGenerationShader.SetBuffer(0, "totalVertices", vertexBuffer);
    meshGenerationShader.SetBuffer(0, "tBuffer", tBuffer);
    meshGenerationShader.SetFloats("chunkSize", new float[3] { chunkSize.x, chunkSize.y, chunkSize.z });
    meshGenerationShader.SetFloat("surfaceLevel", surfaceLevel);

    meshGenerationShader.Dispatch(0, Mathf.CeilToInt(chunkSize.y/8f), 1, 1);

    ComputeBuffer.CopyCount(tBuffer, tCountBuffer, 0);
    int[] tCountArray = { 0 };
    tCountBuffer.GetData(tCountArray);
    int numTri = tCountArray[0];

    // Get tri data from shader
    Triangle[] tris = new Triangle[numTri];
    tBuffer.GetData(tris, 0, 0, tris.Length);

    vertexBuffer.Release();

    tBuffer.Release();
    tCountBuffer.Release();

    Vector3[] verts = new Vector3[numTri * 3];
    var meshTriangles = new int[numTri * 3];

    for (int i = 0; i < numTri; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            meshTriangles[i * 3 + j] = i * 3 + j;
            verts[i * 3 + j] = tris[i][j];
        }
    }

    chunk.vertices = verts;
    chunk.triangles = meshTriangles;
}

At first it appeared to work pretty well

But then at larger amounts of cubes, this happens

The triangles at the front of the chunk are not being generated and the triangles at the back are... well I'm not sure what they're doing.

Anyone know how to fix this? I figure it has something to do with the threads or thread groups but I'm not sure how. I'm also pretty new to compute shaders in general if that helps.

  • ✇Recent Questions - Game Development Stack Exchange
  • Getting the material name or index from a Blender FBX model in MonoGameLAK132
    I've imported Blender FBX models in to UE4 before, so I'm aware that some of the material information is saved in the model. How do I go about accessing this in MonoGame? To be clear, I don't specifically mean textures. I mean the materials that then refer to a given set of textures (colour, normal, etc). I'm currently parsing the same texture to the HLSL shader for the entire model, however I want to be able to change which texture is parsed based on the material information (or parse all tex
     

Getting the material name or index from a Blender FBX model in MonoGame

I've imported Blender FBX models in to UE4 before, so I'm aware that some of the material information is saved in the model. How do I go about accessing this in MonoGame?

To be clear, I don't specifically mean textures. I mean the materials that then refer to a given set of textures (colour, normal, etc).

I'm currently parsing the same texture to the HLSL shader for the entire model, however I want to be able to change which texture is parsed based on the material information (or parse all textures to the shader and have it choose, I'm not sure)

EDIT: it would seem this information is saved in the FBX as "LayerElementMaterial"

LayerElementMaterial: 0 {
        Version: 101
        Name: ""
        MappingInformationType: "ByPolygon"
        ReferenceInformationType: "IndexToDirect"
        Materials: 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,
                   3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,1,1,1,1,

The question still stands, is this information accessible at runtime?

  • ✇Recent Questions - Game Development Stack Exchange
  • Incorrect Screen Space Reflection helpuser179368
    I'm leaving a question because I ran into a problem while implementing screen space reflection. The way I do it is by sampling the position and normal map saved with deferred rendering, changing it to the view point, using the reflect function to obtain the reflection vector, adding it little by little to the view position of the current pixel, and then using the ray marching method to determine the view position of the corresponding texture. We use a method of extracting color by comparing it w
     

Incorrect Screen Space Reflection help

I'm leaving a question because I ran into a problem while implementing screen space reflection. The way I do it is by sampling the position and normal map saved with deferred rendering, changing it to the view point, using the reflect function to obtain the reflection vector, adding it little by little to the view position of the current pixel, and then using the ray marching method to determine the view position of the corresponding texture. We use a method of extracting color by comparing it with the depth value. However, reflections do not appear properly, colors appear in strange places, or are drawn overlapping multiple times. Even if you try both normal and world and view, it doesn't come out well, but world comes out more convincingly. Even if I try changing all the numbers, I don't get a good result. What's the problem?

enter image description here

enter image description here

screen shot 1 : normal view enter image description here

screnn shot 2 : normal world

enter image description here

another best reflection screen shot

enter image description here

❌
❌