Commit 87166c01 authored by Christopher Tenter's avatar Christopher Tenter

optimized picking in meshnode

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18531 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7dc09585
// transcode from 32 bit integer to float4 color (quantized to byte4 color)
vec4 IntToColor(in int i)
{
// A8B8G8R8?
i = i + 1;
int r = (i >> 16) & 0xff;
int g = (i >> 8) & 0xff;
int b = i & 0xff;
int a = (i >> 24) & 0xff;
return vec4( float(r) / 255.0, float(g) / 255.0, float(b) / 255.0, float(a) / 255.0 );
}
// maybe write test for random colors and compare with ColorTranslator.cc
/*
ColorTranslator::index2color(int _idx):
blue_shift = green_shift = red_shift = alpha_shift = 0
blue_round = green_round = red_round = alpha_round = 0x80000000
blue_mask = green_mask = red_mask = alpha_mask = 0xff
blue_bits = green_bits = red_bits = alpha_bits = 8
idx = _idx + 1;
b = idx & 0xff
g = (idx >> 8) & 0xff
r = (idx >> 16) & 0xff
a = (idx >> 24) & 0xff
*/
\ No newline at end of file
// returns picking ids of faces in a n-poly mesh
#version 150
#include "colortranslator.glsl"
uniform int pickFaceOffset;
uniform isamplerBuffer triToFaceMap; // maps: triangle id in draw buffer -> face id in input buffer
out vec4 outPickID;
void main()
{
int faceID = texelFetch(triToFaceMap, gl_PrimitiveID).x;
// faceID = gl_PrimitiveID; // debug mode: skip reading from texture-buffer
int pickID = pickFaceOffset + faceID;
outPickID = IntToColor(pickID);
}
\ No newline at end of file
// returns picking ids of vertices
#version 150
in vec4 vertexPickID;
out vec4 outPickID;
void main()
{
outPickID = vertexPickID;
}
// returns picking ids of vertices
#version 150
#include "colortranslator.glsl"
uniform int pickVertexOffset;
out vec4 outPickID;
void main()
{
int vertexID = gl_PrimitiveID + pickVertexOffset;
outPickID = IntToColor(vertexID);
}
// returns picking ids of vertices
#version 150
#include "colortranslator.glsl"
uniform mat4 mWVP;
uniform int pickVertexOffset;
//uniform isamplerBuffer vboToInputMap; // maps: vertex id in draw buffer -> vertex id in input buffer
in vec4 inPosition;
out vec4 vertexPickID;
void main()
{
// transform
gl_Position = mWVP * vec4(inPosition.xyz, 1);
// compute picking id
// int vertexID = texelFetch(vboToInputMap, gl_VertexID).x;
int vertexID = gl_VertexID;
vertexPickID = IntToColor(pickVertexOffset + vertexID);
}
#version 150
uniform mat4 mWVP;
in vec4 inPosition;
void main()
{
gl_Position = mWVP * vec4(inPosition.xyz, 1);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment