+1
Under vurdering

ComputeShader Output Rendering with SF

Zach Simmons 9 år siden opdateret af Jamie Shelley 9 år siden 5
This is a very complex problem but I'm hoping my team and I can get some help with it.

We are working with a computeShader that generates tons of stars in 3 dimensions from a texture we read for voxel density values. We are looking for some way to use ShaderForge to make our companion shader which actually renders the stars more artist friendly.

Here's the HLSL code for the output shader that we'd like to somehow get into shaderforge. We were hoping to be able to reference our structured buffers and cginc files in a code node. Is this feasible in SF?


Shader "Custom/StarShaderTemp" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color(" Color", Color) = (1, 0.5, 0.5, 1)
}
SubShader
{
Pass
{
Tags { "RenderType"="Transparent"}
ZTest Off
ZWrite Off
Cull Off
Blend SrcAlpha One

CGPROGRAM
#pragma target 5.0

#pragma vertex star_vertex
#pragma fragment frag
#pragma exclude_renderers gles
#include "UnityCG.cginc"
#include "StarStructInc.cginc"

StructuredBuffer<Star> stars;
StructuredBuffer<float3> quadPoints;

sampler2D _MainTex;

float4 _Color;

struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};

// vertex shader with no inputs
// uses the system values SV_VertexID and SV_InstanceID to read from compute buffers
v2f star_vertex(uint id : SV_VertexID, uint inst : SV_InstanceID)
{
v2f o;

float3 worldPosition = stars[inst].position;
float3 Qpoint = quadPoints[id];

o.pos = mul (UNITY_MATRIX_P, mul (UNITY_MATRIX_V, float4(worldPosition, 1.0f)) + float4(Qpoint, 0.0f));

o.uv = quadPoints[id]+ 0.5f; //setting UV texture coord center
return o;
}

float4 frag (v2f i) : COLOR
{
float4 texCol = tex2D (_MainTex, i.uv);
//float4 partCol = i.color;

//return float4 (1.0f - (1.0f - texCol.rgb) * (1.0f - partCol.rgb), texCol.a);
return texCol * _Color;
}
ENDCG
+1
Under vurdering
I'm not sure if it's really something SF can or should have. It seems very case specific from what I can tell, and probably a bit out of scope. But maybe at some point in the future! Though I doubt it
+1
Thanks Joachim!

How does your code node work though? Do you think it's possible to access our buffers using your code node? Or is it more limited?
+1
The code node doesn't allow code outside the local scope of the fragment or vertex shader, so I'm afraid that's not an option either :(
+1
I was worried about that. Thanks for clearing that up. We may just have to start with shaderforge standard stuff and let the artists tweak a standard particle system until it looks right and then manually modify the code ourselves.

Thanks for the information and help.
Well looks like more work for me xD

Kundesupport af UserEcho