I have been trying to figure this out already for four hours and I was not able to make it work.
I am trying to create an entity (like a fog), which when you get closer with the camera, it changes its opacity (alpha channel).
Basically, what I want is to pass global position to a pixel shader. This is what I have, but it doesn't work
Code: Select all
fragment_program fog_ps_cg cg
{
source fog.cg
entry_point main
profiles ps_2_0 arbfp1
}
vertex_program fog_vs_cg cg
{
source fog.cg
entry_point mainVS
profiles vs_1_1 arbvp1
default_params
{
param_named_auto worldViewProj_m worldviewproj_matrix
param_named_auto cameraPos camera_position
}
}
Code: Select all
struct vertexIn
{
float4 position : POSITION;
float2 texCoord0 : TEXCOORD0;
};
struct vertexOut
{
float4 position : POSITION;
float2 texCoord0 : TEXCOORD0;
float4 cameraPosition : TEXCOORD1;
};
vertexOut mainVS(vertexIn input,
uniform float4x4 worldViewProj_m,
uniform float4 cameraPos)
{
vertexOut output = (vertexOut)0;
output.texCoord0 = input.texCoord0;
output.position = mul(worldViewProj_m, input.position);
output.cameraPosition = cameraPos;
return output;
}
float4 main(
vertexOut vertex_output,
uniform sampler2D fog : register(s0)
) : COLOR
{
float4 result = tex2D(fog, vertex_output.texCoord0);
result.a = vertex_output.cameraPos / 10;
return result;
}
Code: Select all
result.a = vertex_output.cameraPos / 10;
Thank you for help