04-10-2019, 06:59 AM
(03-10-2019, 09:24 PM)MasterGeneralB Wrote: So I'm trying to use a simple 2d fluid with the LW rendering pipeline and nothing I try is working...
I'm trying to get the basic obi particle renderer to work and show the fluid particles so I can at least see what I am doing. I found a previous thread about changing the tags in the shader.. but that didn't seem to do the trick.
The simpleparticleshader.shader file looks something like this at the moment:
Code:Shader "Obi/Simple Particles" {
Properties {
_Color ("Particle color", Color) = (1,1,1,1)
}
SubShader {
Pass {
Name "ParticleFwdBase"
Tags {"LightMode" = "LightweightForward" "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"}
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fwdbase nolightmap
#include "ObiParticles.cginc"
fixed4 _Color;
fixed4 _LightColor0;
struct vin{
float4 vertex : POSITION;
float3 corner : NORMAL;
fixed4 color : COLOR;
float4 t0 : TEXCOORD0; // ellipsoid t1 vector
};
struct v2f
{
float4 pos : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float3 lightDir : TEXCOORD1;
LIGHTING_COORDS(3,4)
};
v2f vert(vin v)
{
v2f o;
// particle positions are passed in world space, no need to use modelview matrix, just view.
float radius = v.t0.w * _RadiusScale;
float4 viewpos = mul(UNITY_MATRIX_V, v.vertex) + float4(v.corner.x, v.corner.y, 0, 0) * radius; // multiply by size.
o.pos = mul(UNITY_MATRIX_P, viewpos);
o.texcoord = float3(v.corner.x*0.5+0.5, v.corner.y*0.5+0.5, radius);
o.color = v.color * _Color;
o.lightDir = UnityObjectToViewPos(ObjSpaceLightDir(v.vertex));
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// generate sphere normals:
float3 n = BillboardSphereNormals(i.texcoord);
// simple lighting: diffuse
float ndotl = saturate( dot( n, normalize(i.lightDir) ) );
// final lit color:
return fixed4(i.color.rgb * (_LightColor0 * ndotl + UNITY_LIGHTMODEL_AMBIENT),i.color.a);
}
ENDCG
}
Pass {
Name "ShadowCaster"
Tags { "LightMode" = "LightweightForward" }
Offset 1, 1
Fog {Mode Off}
ZWrite On ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster nolightmap
#include "ObiParticles.cginc"
struct vin{
float4 vertex : POSITION;
float3 corner : NORMAL;
float4 t0 : TEXCOORD0; // ellipsoid t1 vector
};
struct v2f {
float4 pos : POSITION;
float3 texcoord : TEXCOORD0;
};
v2f vert( vin v )
{
v2f o;
float radius = v.t0.w * _RadiusScale;
float4 viewpos = mul(UNITY_MATRIX_V, v.vertex) + float4(v.corner.x, v.corner.y, 0, 0) * radius;
o.pos = mul(UNITY_MATRIX_P, viewpos);
o.texcoord = float3(v.corner.x*0.5+0.5, v.corner.y*0.5+0.5, radius);
return o;
}
fixed4 frag( v2f i ) : SV_Target
{
float3 n = BillboardSphereNormals(i.texcoord);
return fixed4(0,0,0,0);
}
ENDCG
}
}
FallBack "Diffuse"
}
I believe I added the right tags to both passes.. and changed the line
Code:o.lightDir = UnityObjectToViewPos(ObjSpaceLightDir(v.vertex));
as Unity was screaming a warning log at me about using Matrix_MV. I'm not entirely sure if that's how it should look as I am a newb with shaders... But I can definitely tell you that it still does not work. I don't see anything on my camera screen. That said, the simulation DOES work, but for me to see the particles (and only with the editor camera during playmode) I need to press the edit particles button on the obi emitter component.
Also, I am getting a log "Material Property is found in another cbuffer than 'UnityPerMaterial' (_Color)". Googling about, I found that to get it working with the SRP Batcher it needs to be in a CBUFFER_START(UnityPerMaterial) CBUFFER_END block... but I don't know how to implement that either... if anyone knows how, that would be great.
Hi there,
The included renderer does not support SRPs. Quote from the FAQ:
http://obi.virtualmethodstudio.com/tutorials/
Quote:Does it support SRP (Scriptable Render Pipeline)?
Cloth, Rope and Softbodies support SRP out of the box, since they do not perform any custom rendering. Obi Fluid does include a custom rendering pipeline based on screen-space ellipsoid splatting, that is not currently compatible with SRP.
Next update (scheduled for release during October) will add SRP compatibility.