Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
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 Offline OP
Senior Expert
PHeMoX  Offline 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


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
Re: Function to read pixel colors from model's ski [Re: PHeMoX] #189658
03/21/08 13:45
03/21/08 13:45
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
?hist recall?
?
*example of model ambiance change by terrain pixel sampling offered
--most likely applies to terrain, not model
--ref user: Guitar(sp) / Disciple(sp) / Loopix
*pixel sampling: perhaps issues with models, but not terrain
*uv of terrain may be simpler (obvious)
--ref user: Ventilator (model uv info)
?

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 Offline OP
Senior Expert
PHeMoX  Offline 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


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
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
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

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: testDummy] #189661
03/21/08 15:46
03/21/08 15:46
Joined: Sep 2002
Posts: 8,177
Netherlands
PHeMoX Offline OP
Senior Expert
PHeMoX  Offline OP
Senior Expert

Joined: Sep 2002
Posts: 8,177
Netherlands
VERY much appreciated. A quick glance at the code makes me think this should be all I need. Thanks!


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
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 Offline
Expert
xXxGuitar511  Offline
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 Offline OP
Senior Expert
PHeMoX  Offline 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


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
Re: Function to read pixel colors from model's ski [Re: PHeMoX] #189664
03/24/08 04:44
03/24/08 04:44
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Quoting PHeMoX.
Quote:

Do you happen to have a project in which the code is running and working successfully?



That question is asked of which party?
current stance: In some contexts, I prefer to try and avoid terms such as 'working successfully'.
The code sample three posts back should be a copy of the entire shadowMapAmbient.wdl file from an archive here.

/*
?additional specs?
?
*compiles / runs: yes 6.40.5
*terrain (hmp) not mdl
*terrain has black n white checker test texture
*linked with old template6 (Loopix goal related)
--function ScanFloor() was inserted at end of BipedPhy01_Move_Ground
*player ent moves with input (template6) across terrain
--ambiance seems to change accordingly
?
*/

particle functions:
*Sample implementation is not tied to particle functions.
*As is, the sample implementation is probably not particle function friendly.

?manual ref: Particle functions should be fast.?

"return(ScanDist)" is not mandatory

Re: Function to read pixel colors from model's ski [Re: testDummy] #189665
03/25/08 12:58
03/25/08 12:58
Joined: Sep 2002
Posts: 8,177
Netherlands
PHeMoX Offline OP
Senior Expert
PHeMoX  Offline OP
Senior Expert

Joined: Sep 2002
Posts: 8,177
Netherlands
Thanks, yeah, actually removing return(ScanDist) seems to solve the issue for the most part.

However I've found a much better solution to my problem in the mean time. Instead of looking at pixels, I just take heights into account, certain textures (and thus pixel colors) are only found on lower areas,

Cheers


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
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 Offline
Expert
xXxGuitar511  Offline
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
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1