LoginSignup
0
0

More than 1 year has passed since last update.

UnityカスタムシェーダでPOINTSIZEを変更する。

Last updated at Posted at 2021-08-01

UnityカスタムシェーダでPOINTSIZEを変更する。

DirectからOpenGL系に変更をする。
image.png


Shader "Custom/VertexColor"
{
    Properties{
      _Size("ShaderSize", Float) = 1.000000
      _PointSize("PointSize", Float) = 5.0

    }
    SubShader{
    Pass {
        LOD 200

        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag

        uniform float _PointSize;


        struct VertexInput {
            float4 v : POSITION;
            float4 color: COLOR;
        };

        struct VertexOutput {
            float4 pos : SV_POSITION;
            float4 col : COLOR;
            float psize : PSIZE;

        };

        VertexOutput vert(VertexInput v) {

            VertexOutput o;
            o.pos = UnityObjectToClipPos(v.v);
            o.col = v.color;
            o.psize = _PointSize;

            return o;
        }

        float4 frag(VertexOutput o) : COLOR {
            return o.col;
        }

        ENDCG
        }
    }
}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class PointCloud : MonoBehaviour
{

    private Mesh mesh;
    int numPoints = 600000;

    // Use this for initialization
    void Start()
    {
        mesh = new Mesh();

        GetComponent<MeshFilter>().mesh = mesh;
        CreateMesh();
    }

    void CreateMesh()
    {
        Vector3[] points = new Vector3[numPoints];
        int[] indecies = new int[numPoints];
        Color[] colors = new Color[numPoints];
        for (int i = 0; i < points.Length; ++i)
        {
            points[i] = new Vector3(Random.Range(-10, 10), Random.Range(-10, 10), Random.Range(-10, 10));
            indecies[i] = i;
            colors[i] = new Color(0,0,1,  1.0f);
        }

        mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
        mesh.vertices = points;
        mesh.colors = colors;
        mesh.SetIndices(indecies, MeshTopology.Points, 0);

    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0