UPDATE: Partial success!
So, while I had tried using outWorldPosition - cameraPos before, I always failed to compile then, but just by tweaking my existing code to use it, it worked.... BUT cameraPos is actually just always 0,0,0 and therefore 100% useless. if I could get the real cameraPos, I think I would be done with coloring : /
Attachment:
cameraTroubles.jpg [ 85.41 KiB | Viewed 3568 times ]
(notice how it just stops... the colors also don't change with distance from the camera now, they are just static, because cameraPosition is returning the null vector)
Ogre Program:
Code:
vertex_program PickerVP cg
{
source Picker.cg
entry_point PickerVP
profiles vs_3_0 vs_2_x vs_2_0 vs_1_1 vp40 vp30 vp20 arbvp1
default_params
{
param_named_auto world world_matrix
param_named_auto viewProj viewproj_matrix
param_named auto cameraPos camera_position
}
}
fragment_program PickerFP cg
{
source Picker.cg
entry_point PickerFP
profiles ps_3_x ps_3_0 ps_2_x ps_2_0 ps_1_4 ps_1_3 ps_1_2 ps_1_1 fp40 fp30 fp20 arbfp1
default_params
{
}
}
CG programs:
Code:
void PickerVP(
float4 inPosition : POSITION,
out float4 outClipPosition : POSITION,
out float4 outWorldPosition : TEXCOORD0,
out float4 crfp : TEXCOORD1, //camera relative fragment position
uniform float4x4 world,
uniform float4x4 viewProj,
uniform float4 cameraPos
)
{
//Compute the world space position
outWorldPosition = mul(world, inPosition);
//Compute the clip space position
outClipPosition = mul(viewProj, outWorldPosition);
//Pass through the material
crfp = outWorldPosition - cameraPos;
}
void PickerFP(
float4 inPosition : POSITION,
float4 inWorldPosition : TEXCOORD0,
float4 crfp : TEXCOORD1,
out float4 result : COLOR)
{
float3 worldNormal = cross(ddy(inWorldPosition.xyz), ddx(inWorldPosition.xyz));
worldNormal = normalize(worldNormal);
crfp = crfp / 16;
result = float4(0,0,0,1);
//result = float4(crfp.x/32, crfp.y/32, crfp.z/32,1);
if ((crfp.x < 32)&&(crfp.y < 32)&&(crfp.z < 32)){
if(worldNormal.x > 0.5){
result = float4((crfp.x - .5)/32, round(crfp.y)/32, round(crfp.z)/32,1);
}
if(worldNormal.x < -0.5){
result = float4((crfp.x + .5)/32, round(crfp.y)/32, round(crfp.z)/32,1);
}
if(worldNormal.y > 0.5){
result = float4(round(crfp.x)/32, (crfp.y - .5)/32, round(crfp.z)/32,1);
}
if(worldNormal.y < -0.5){
result = float4(round(crfp.x)/32, (crfp.y + .5)/32, round(crfp.z)/32,1);
}
if(worldNormal.z > 0.5){
result = float4(round(crfp.x)/32, round(crfp.y)/32, (crfp.z - .5)/32,1);
}
if(worldNormal.z < -0.5){
result = float4(round(crfp.x)/32, round(crfp.y)/32, (crfp.z + .5)/32,1);
}
}
}
EDIT: @David
Quote:
You already have the world space position in 'inWorldPosition.xyz'. You're using it when you compute the normals for example. Or am I misunderstanding your question?
the problem is that I need to be able to recolor voxels based on their distance in x,y,z from the camera, because I'm going to need to extract that color information to add to the index of the voxel the camera is at. Right now I have a few things I need to work out -
1) how do I get the world - camera difference. I now have world working correctly, but not camera, so it is taunting me (so close and yet so far)
2) my next thing I need to figure out is how to do face detection. I was thinking about adding a constant to the normal face, but upon thinking about it more, I don't think that will work at all. (no way to reverse that process) my second (and better I think) idea was to try and use the alpha channel to save which face is clicked on. the problem here is that I need to have the alpha channel have no effect on which color goes in the buffer (I cant have colors getting added from behind), but at the same time stay in the buffer so I can retrieve them. This may be something that people on the ogre forums can help me with, although they have been noticeably crappy at responding to my cg help questions (I don't think many people know anything about them - I certainly didn't till this project). Or it may just result in hours and hours of trial and error met with either success or defeat : /
Problem 1 is more pressing because I can't really do anything until I can get the color generation working for basic picking (if the voxel is all 1 color, then I will know which one it is (good enough for deletion) but I won't know which face was selected until I can figure out problem 2