Why can't i access vertex output?

Hi. I’m trying to import a projected grid technique (for water/ocaen) made with Unity into Flax. There is no problem in the code part, but in the shader part, I need to assign the relevant matrix to the Vertex Output. Why can’t I do this?

Here is the relevant part:

v2f vert(appdata_base v)
{

	float2 uv = v.texcoord.xy;

	//Interpolate between frustums world space projection points. p is in world space.
	float4 p = lerp(lerp(_Interpolation[0], _Interpolation[1], uv.x), lerp(_Interpolation[3], _Interpolation[2], uv.x), uv.y);
	p = p / p.w;

	v2f OUT;
	OUT.pos = mul(UNITY_MATRIX_VP, p);
	OUT.worldPos = p;
	
	return OUT;
}

Is there a workaround on this? I’m trying to output position offset using custom code but no success no matter what I do.

Things I’ve tried;

// CUSTOM CODE BOX
float2 uv=input.TexCoord.xy;

float4x4 Interpolation;
Interpolation[0]=Input0;
Interpolation[1]=Input1;
Interpolation[2]=Input2;
Interpolation[3]=Input3;

float4 worldpos=float4(input.WorldPosition.xyz,1);

float4  p =lerp(lerp(Interpolation[0],Interpolation[1], uv.x),lerp(Interpolation[3],Interpolation[2], uv.x),uv.y);
p = p / p.w;

//none of them work
float4 final=mul(worldpos,p);
float4 final2=mul(mul(worldpos,WorldMatrix),p);
float4 final3=mul(input.SvPosition,p);
float4 final4=mul(mul(input.SvPosition,WorldMatrix),p);
float4 final5=mul(WorldMatrix,p);


Output0 =final;
//Output0 =p;

I think if you get the destination position p and subtract the current position (input.WorldPosition.xyz) then you can plug it into World Position Offset input. Do it work?

1 Like

Unfortunately it doesn’t. Maybe I’m doing something wrong in the code part. There must be something I overlooked. Thank you for your help.

Maybe custom geometry with custom shader might help in that case: Custom Geometry Drawing | Flax Documentation

In future it would be cool to have ability to easily create material shader in Flax that accepts the mesh geometry and outputs to Gbuffer via custom code.

1 Like