|
Function to read pixel colors from model's skin?
#189657
03/20/08 15:49
03/20/08 15:49
|
Joined: Sep 2002
Posts: 8,177 Netherlands
PHeMoX
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2002
Posts: 8,177
Netherlands
|
Hi there, I know the function c_trace and SCAN_TEXTURE can output tex_color, but this only works on levelblocks not models and only gives the color of the light source, not the pixel color of the model's skin. I would like to adjust a particle function depending on the pixel color on the terrain below it. I take it I should use; Code:
pixel_for_bmap(skinpointer, coords_x, coords_y);
and use the entity's skin intead, but I'm stuck on converting the 3D position of my player to the correct 2D positions in the texture. Anyone got any hints or ideas? Cheers
|
|
|
Re: Function to read pixel colors from model's ski
[Re: testDummy]
#189659
03/21/08 13:58
03/21/08 13:58
|
Joined: Sep 2002
Posts: 8,177 Netherlands
PHeMoX
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2002
Posts: 8,177
Netherlands
|
Thanks for your suggestions, I appreciate it! The model ambiance example I know of uses tex_color and 'SCAN_TEXTURE' or are you talking about a certain shader? I need to know the color of the (pixels of the) terrain underneath a model for a certain particle trail effect. I think I can handle the reading of the pixels through pixel_for_bitmap on the UV of the terrain, but getting the coordinates right is a bit tricky. I'll look into the Loopix projects, perhaps there's valuable info I've overlooked indeed! Cheers
|
|
|
Re: Function to read pixel colors from model's ski
[Re: PHeMoX]
#189660
03/21/08 14:52
03/21/08 14:52
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
You are probably already familiar with the following example or something similar. However, given the rate that historical data seems to deteriorate in these parts, I'll dump it anyway: (note: I am not the author. Modifications might have been made from original.) Code:
var terrain_chunk = 0; // won't work in 6.40.5 unless you do this
// (Loopix-ShadowmapAmbient0) // Terrain Brightness // Credit appreciated... // src author: Josh Miller (xXxGuitar511) // tD arc date: 2006-06-09 // tD mod possible // ver: 6.60, 6.40.5?
define TraceDist, 100; // Distance to scan down... define FloorOffs, 10; // Height above entities feet to trace from define IsTerrain, flag5; // Set this flag for all terrain entities //define SkinNumber, 3; // Skin to scan for brightness (red channel) define SkinNumber, 2; define BrightScale,100; // Percentage (0 - 100) of brightness define BrightOffs, 0; // Offset of brightness (from 0)
var ScanFrom[3]; var ScanTo[3]; var ScanDist; var TargetX; var TargetY; var TargetPixel; var PixelColor[3]; var BMapFormat; bmap* TerrainSkin;
var scanFloorEnable = 0;
action terrain0 { my.skin = SkinNumber; my.IsTerrain = on; }
function ScanFloor(); // *** Prototype function...
function ScanFloor() { vec_set(ScanFrom, my.x); ScanFrom[2] += my.min_z + FloorOffs; vec_set(ScanTo, ScanFrom); ScanTo[2] -= TraceDist; ScanDist = c_trace(ScanFrom, ScanTo, ignore_me | ignore_passable | ignore_passents); //trace_mode = ignore_me + ignore_passable + ignore_passents; //ScanDist = trace(ScanFrom, ScanTo); if (ScanDist == 0) {ScanDist = TraceDist;} if (you != null) { if (you.IsTerrain == on) { // Is a terrain TerrainSkin = bmap_for_entity(you, SkinNumber); BMapFormat = bmap_lock(TerrainSkin, 0); if (TerrainSkin == 0) { goto(NoTerrain); } vec_for_vertex(ScanFrom, you, 1); vec_for_vertex(ScanTo, you, ent_vertices(you)); TargetX = (my.x - ScanFrom.x) / (ScanTo.x - ScanFrom.x) * bmap_width(TerrainSkin); TargetY = (my.y - ScanFrom.y) / (ScanTo.y - ScanFrom.y) * bmap_height(TerrainSkin); TargetX = clamp(int(TargetX), 0, bmap_width(TerrainSkin)); TargetY = clamp(int(TargetY), 0, bmap_height(TerrainSkin)); TargetPixel = pixel_for_bmap(TerrainSkin, TargetX, TargetY); if (TargetPixel == -1) {goto(NoTerrain);} pixel_to_vec(PixelColor, null, BMapFormat, TargetPixel); bmap_unlock(TerrainSkin); my.ambient = clamp((PixelColor.blue / 255 * BrightScale) + BrightOffs, 0, 100); //my.ambient = (PixelColor.red + PixelColor.green + PixelColor.blue) / 765 * 100; } } // NoTerrain: // return(ScanDist); }
|
|
|
Re: Function to read pixel colors from model's ski
[Re: PHeMoX]
#189662
03/21/08 16:49
03/21/08 16:49
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
TestDummy was exactly right. I wrote this code for loopix, which will work with reading the pixel from a terrains skin. However, if you need to do this with a model, you will have to refer to Ventilators super trace plugin
xXxGuitar511 - Programmer
|
|
|
Re: Function to read pixel colors from model's ski
[Re: xXxGuitar511]
#189663
03/24/08 02:20
03/24/08 02:20
|
Joined: Sep 2002
Posts: 8,177 Netherlands
PHeMoX
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2002
Posts: 8,177
Netherlands
|
Hmmm, I see. Do you happen to have a project in which the code is running and working successfully? It's not that I've got the feeling this isn't working, it probably is working fine as is, but I'm getting a weird glitch every once in a while. Most likely the glitch is the result of the 'return(ScanDist);' part which causes the sprite that's moving to come to a full stop. Unfortunately that's a complication that I can't afford to have, I'll look into that plug-in though, thanks, Cheers
|
|
|
Re: Function to read pixel colors from model's ski
[Re: PHeMoX]
#189666
03/25/08 17:20
03/25/08 17:20
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
The code above was my script, but slightly modified. I had it set the models ".ambient" to the average of the rgb color of the pixel. Now it reads the brightness from the blue channel.
It only returns the height if a terrain is found...
xXxGuitar511 - Programmer
|
|
|
|