Vertex displacement shader

Materials, textures, lighting, postfx
8 posts Page 1 of 1
Jmac
Posts: 11
Joined: Wed Mar 22, 2017 10:20 pm
by Jmac » Thu Jun 01, 2017 4:52 pm
I'm moving vertices in a very simple shader but for some reason the normals dont move with the vertices and I'm left with an odd effect. Any ideas what is causing this?

Vertex Shader

Code: Select all

#include "shaders/common/torque.hlsl"

struct Appdata
{
  float3 position        : POSITION;
  float tangentW        : TEXCOORD3;
  float3 normal          : NORMAL;
  float3 T               : TANGENT;
  float2 texCoord        : TEXCOORD0;
};

struct Conn
{
  float4 hpos            : SV_Position;
  float2 texCoord  : TEXCOORD0;
};

Conn main( Appdata In,
                  uniform float4x4 modelview       : register(C0) )
{
  Conn Out;
  In.position.z += 20;
  Out.hpos = mul(modelview, float4(In.position, 1.0));
  Out.texCoord = In.texCoord;
  return Out;
}


Pixel Shader

Code: Select all

#include "shaders/common/torque.hlsl"

struct Conn
{
   float4 hpos            : SV_Position;
   float2 texCoord  : TEXCOORD0;
};

struct Fragout
{
   float4 col : SV_Target0;
};

Fragout main(Conn IN)
{
   Fragout OUT;
   OUT.col = (255,255,255,1);
   return OUT;
}


What it looks like in game
Image
Timmy
Posts: 308
Joined: Thu Feb 05, 2015 3:20 am
by Timmy » Fri Jun 02, 2017 3:00 am
I am not 100% sure i am understanding the question, normals are a direction vector and don't have a position. In your shader you are not even using the normals so kinda hard to gather exactly what it is you are trying to do. Going to need more info.
Jmac
Posts: 11
Joined: Wed Mar 22, 2017 10:20 pm
by Jmac » Fri Jun 02, 2017 3:22 am
I'm trying to move the mesh vertices from the vertex shader in the z axis, I want to try to do the vertex translation on the gpu because of the amount I will need to move in a frame. The white color appears in the proper position but its somewhat transparent and there is that tan plane that appears at the original location that I'm assuming is another set of vertices with the normals for the object where. I don't exactly know why there are two planes or what they are to be honest.

For instance when I put in object between the white and tan I can see it when I shouldn't but when it's under the tan portion I can't see it so im assuming the tan plane has some lighting attributes.

Also when I view the white from an angle that the tan is not below it, it doesn't appear.
Imagepost images

I haven't been able to find much info on torques rendering system so if anyone could point me in the right direction it would be appreciated.
Timmy
Posts: 308
Joined: Thu Feb 05, 2015 3:20 am
by Timmy » Fri Jun 02, 2017 4:54 am
Unfortunately what you are seeing is a short coming of the t3d custom material system. In short what you want to do with the vertices can't be done how it works now. What happens is the object is rendered twice, once through the deferred bin (using a shadergen shader you can't change) and than it renders it again after the deferred pass using your custom material, this is why you see the object twice because you are obviously changing the vertex position only in that second pass.

Just a couple of small things in ya pixel shader

Code: Select all

OUT.col = (255,255,255,1);

should read

Code: Select all

OUT.col = float4(1.0,1.0,1.0,1.0);


ya firstly need the type(float4) and the shaders use a float range for the color, although 255 is a perfectly valid number with HDR i'm guessing you really meant 255 as in 0-255 unsigned byte range so the value should be 1.0

Hopefully that clears it up for you.
JeffR
Steering Committee
Steering Committee
Posts: 764
Joined: Tue Feb 03, 2015 9:49 pm
 
by JeffR » Fri Jun 02, 2017 4:58 pm
Hm, I'll take an eyeball on how the current water stuff does it, because being able to permute the vert positions is definitely something that should be possible in a custom mat. So if it's choking that hard, it needs a-looking.
Jmac
Posts: 11
Joined: Wed Mar 22, 2017 10:20 pm
by Jmac » Fri Jun 02, 2017 7:22 pm
Thanks Timmy that helped alot. I figured it had something to do with it being rendered twice but didnt exactly know how it worked.
Jmac
Posts: 11
Joined: Wed Mar 22, 2017 10:20 pm
by Jmac » Tue Jun 06, 2017 7:13 pm
Can anyone point me to where the deferred bin creates the shader for the first pass?
8 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests