je suis nouveau sur ce forum donc je me présente brièvement :
à la base graphiste 3d, je suis plus orienté 3d technical artist depuis quelques années
et développe des trucs sur Vvvv, touch designer et Max/msp... ( visual programming en somme)
j'ai quelques connaissances empiriques en c++ et c# mais suis plutôt mauvais..
présentation faite, je vous expose mon problème :
Je souhaite modifier une variable dans un shader appliqué à un gameobject instancié,
et ce, depuis un script C#...
En gros j'ai une FFT en array de 512 qui doit modifier une variable sur chaque instance de mon objet.
j'arrive bien à l'appliquer a la taille (localScale) mais suis bien incapable de l'appliquer à une variable du shader.
Le Shader :
Code : Tout sélectionner
Shader "Flat/Sin Wave" {
Properties{
_ForegroundColor("Foreground Color", Color) = (1,1,1,0)
_BackgroundColor("Background Color", Color) = (0,0,0,0)
_ForegroundMask("Foreground Mask", 2D) = "white" {}
_ForegroundCutoff("Foreground Cutoff", Range(0,1)) = 0.5
_BackgroundCutoff("Background Cutoff", Range(0,1)) = 0.5
_Radius("Radius", Range(0.0,1.0)) = 0.5
}
SubShader{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Standard
#pragma target 3.0
sampler2D _ForegroundMask;
struct Input {
float2 uv_ForegroundMask;
};
fixed4 _ForegroundColor;
fixed4 _BackgroundColor;
half _ForegroundCutoff;
half _BackgroundCutoff;
half _Radius;
void surf(Input IN, inout SurfaceOutputStandard color) {
fixed x = (-0.5 + IN.uv_ForegroundMask.x) * 2;
fixed y = (-0.5 + IN.uv_ForegroundMask.y) * 2;
fixed radius = 0.5 + sin(x * 3.1415926535) * _Radius;
radius -= (0.5 * y + 0.5);
clip(radius - _BackgroundCutoff);
clip(_ForegroundCutoff - radius);
color.Albedo = _BackgroundColor;
color.Albedo.r = sin(x * 3.14) * 0.5 + 0.5;
}
ENDCG
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Instanciate512Circles : MonoBehaviour
{
public GameObject _sampleCirclePrefab;
GameObject[] _sampleCircle = new GameObject[512];
public float _maxScale;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 512; i++)
{
GameObject _instanceSampleCircle = (GameObject)Instantiate(_sampleCirclePrefab);
_instanceSampleCircle.transform.position = this.transform.position;
_instanceSampleCircle.transform.parent = this.transform;
_instanceSampleCircle.name = "SampleCircle" + i;
_sampleCircle[i] = _instanceSampleCircle;
}
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < 512; i++)
{
if (_sampleCircle != null)
{
_sampleCircle[i].transform.localScale = new Vector3((AudioCraft._samples[i] * _maxScale) + 2, (AudioCraft._samples[i] * _maxScale) + 2, 1);
_sampleCircle[i].transform.localEulerAngles = new Vector3(0, 0, (AudioCraft._samples[i] * 360 * i));
}
}
}
}
Code : Tout sélectionner
AudioCraft._samples[i]
Code : Tout sélectionner
_Radius
je sais que je suis sensé utiliser "setFloat" mais j'y arrive pas
voila merci d'avance pour votre aide !
@+