Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (OptimusPrime, AndrewAMD), 14,580 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: [free]TextureTools [Re: msl_manni] #148645
08/20/07 06:49
08/20/07 06:49
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline OP
User
bstudio  Offline OP
User

Joined: Aug 2006
Posts: 652
Netherlands
I'm working on options for the normal map and a realtime viewer with a shader, I just have to integrate the 3dgs window within my C# application. So I need to write a wrapper :|


BASIC programmers never die, they GOSUB and don't RETURN.
Re: [free]TextureTools [Re: bstudio] #148646
08/20/07 11:18
08/20/07 11:18
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline
User
RedPhoenix  Offline
User
R

Joined: Jan 2007
Posts: 651
Germany
Would you like to share the code of your normalmapping calculations?
I need a code for creating normalmaps in an editorlike project of mine, but have no idea of how this should look like

Re: [free]TextureTools [Re: RedPhoenix] #148647
08/20/07 11:21
08/20/07 11:21
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline OP
User
bstudio  Offline OP
User

Joined: Aug 2006
Posts: 652
Netherlands
Happy to share my source but it's all C#, so if you need it in another language better convert it. I'll comment it for you too just wait a minute

Edit:
Here you go
Code:

class SobelFilter
{
public float scale = 1.0f;

Bitmap b, b1;
public Image apply(Image im)
{
float dx; //Current x pixel
float dy; //Current y pixel
int[] pix = { 0, 0, 0 }; //Color of the pixel
float nx; //normal X
float ny; //normal Y
float nz; //normal Z
float length; //length

b = (Bitmap)im; //Source bitmap
Bitmap b1 = new Bitmap(im); //Target bitmap
for (int y = 1; y < b.Height - 1; y++) // loop for the image pixels height
{
for (int x = 1; x < b.Width - 1; x++) // loop for image pixels width
{
pix[0] = b.GetPixel((x - 1 + b.Width) % b.Width, (y + 1) % b.Height).R; //Get R value
pix[1] = b.GetPixel((x - 1 + b.Width) % b.Width, (y + 1) % b.Height).G; //Get G value
pix[2] = b.GetPixel((x - 1 + b.Width) % b.Width, (y + 1) % b.Height).B; //Get B value
dy = pix[0] / 225.0f * -1.0f; //Calculate value of R color
//Same here for other pixels
pix[0] = b.GetPixel(x % b.Width, (y + 1) % b.Height).R;
pix[1] = b.GetPixel(x % b.Width, (y + 1) % b.Height).G;
pix[2] = b.GetPixel(x % b.Width, (y + 1) % b.Height).B;
dy += pix[0] / 225.0f * -2.0f;

pix[0] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).R;
pix[1] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).G;
pix[2] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).B;
dy += pix[0] / 225.0f * -1.0f;

pix[0] = b.GetPixel((x - 1 + b.Width) % b.Width, (y - 1 + b.Height) % b.Height).R;
pix[1] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).G;
pix[2] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).B;
dy += pix[0] / 225.0f * 1.0f;

pix[0] = b.GetPixel(x % b.Width, (y - 1 + b.Height) % b.Height).R;
pix[1] = b.GetPixel(x % b.Width, (y - 1 + b.Height) % b.Height).G;
pix[2] = b.GetPixel(x % b.Width, (y - 1 + b.Height) % b.Height).B;
dy += pix[0] / 225.0f * 2.0f;

pix[0] = b.GetPixel((x + 1) % b.Width, (y - 1 + b.Height) % b.Height).R;
pix[1] = b.GetPixel(x % b.Width, (y - 1 + b.Height) % b.Height).G;
pix[2] = b.GetPixel(x % b.Width, (y - 1 + b.Height) % b.Height).B;
dy += pix[0] / 225.0f * 1.0f;

//x filter
pix[0] = b.GetPixel((x - 1 + b.Height) % b.Width, (y - 1 + b.Height) % b.Height).R;
pix[1] = b.GetPixel((x - 1 + b.Height) % b.Width, (y - 1 + b.Height) % b.Height).G;
pix[2] = b.GetPixel((x - 1 + b.Height) % b.Width, (y - 1 + b.Height) % b.Height).B;
dx = pix[0] / 225.0f * -1.0f;

pix[0] = b.GetPixel((x - 1 + b.Width) % b.Width, y % b.Width).R;
pix[1] = b.GetPixel((x - 1 + b.Width) % b.Width, y % b.Width).G;
pix[2] = b.GetPixel((x - 1 + b.Width) % b.Width, y % b.Width).B;
dx += pix[0] / 225.0f * -2.0f;

pix[0] = b.GetPixel((x - 1 + b.Width) % b.Width, (y + 1) % b.Height).R;
pix[1] = b.GetPixel((x - 1 + b.Width) % b.Width, (y + 1) % b.Height).G;
pix[2] = b.GetPixel((x - 1 + b.Width) % b.Width, (y + 1) % b.Height).B;
dx += pix[0] / 225.0f * -1.0f;

pix[0] = b.GetPixel((x + 1) % b.Width, (y - 1 + b.Height) % b.Height).R;
pix[1] = b.GetPixel((x + 1) % b.Width, (y - 1 + b.Height) % b.Height).G;
pix[2] = b.GetPixel((x + 1) % b.Width, (y - 1 + b.Height) % b.Height).B;
dx += pix[0] / 225.0f * 1.0f;

pix[0] = b.GetPixel((x + 1) % b.Width, y % b.Height).R;
pix[1] = b.GetPixel((x + 1) % b.Width, y % b.Height).G;
pix[2] = b.GetPixel((x + 1) % b.Width, y % b.Height).B;
dx += pix[0] / 225.0f * 2.0f;

pix[0] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).R;
pix[1] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).G;
pix[2] = b.GetPixel((x + 1) % b.Width, (y + 1) % b.Height).B;
dx += pix[0] / 225.0f * 1.0f;

//Cross product of values
nx = dx;
ny = dy;
nz = 1 / this.scale;

//Normalize
length = 1.0f;
nx *= length;
ny *= length;
nz *= length;

//convert to float
pix[0] = floatToByte(nx);
pix[1] = floatToByte(ny);
pix[2] = floatToByte(nz);

//make sure we have no negative values or values above 255
if (pix[0] > 255)
pix[0] = 255;
if (pix[1] > 255)
pix[1] = 255;
if (pix[2] > 255)
pix[2] = 255;

if (pix[0] < 0)
pix[0] = 0;
if (pix[1] < 0)
pix[1] = 0;
if (pix[2] < 0)
pix[2] = 0;

//create the color for the pixel
Color c = Color.FromArgb(pix[0],pix[1],pix[2]);

//write the color for the pixel
b1.SetPixel(x,y,c);
}
}
return (Image)b1; //return generated image

}

private int floatToByte(float inValue) {
return (int)((inValue + 1.0f) / 2.0f * 255.0f);
}
}



Last edited by bstudio; 08/20/07 11:41.

BASIC programmers never die, they GOSUB and don't RETURN.
Re: [free]TextureTools [Re: bstudio] #148648
08/20/07 13:19
08/20/07 13:19
Joined: Dec 2005
Posts: 478
India
M
msl_manni Offline
Senior Member
msl_manni  Offline
Senior Member
M

Joined: Dec 2005
Posts: 478
India
I thought you were using bmap_to_normals for creating the normalmap.

bmap_to_normals(BMAP* bmap,var factor)

if (pix[0] > 255)
pix[0] = 255;

I see that you are truncating the color components of nornalmap, wouldn't it make the normal calc of those pixels incorrect. Though I doubt that there would be any need for alteration if done correctly.


My Specialities Limited.
Re: [free]TextureTools [Re: msl_manni] #148649
08/20/07 13:30
08/20/07 13:30
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline OP
User
bstudio  Offline OP
User

Joined: Aug 2006
Posts: 652
Netherlands
This was indeed a little quick fix, for some reason my pixel colors do seem to get a value of -14 and 256, still need to find out why


BASIC programmers never die, they GOSUB and don't RETURN.
Re: [free]TextureTools [Re: bstudio] #148650
08/20/07 13:54
08/20/07 13:54
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline
User
RedPhoenix  Offline
User
R

Joined: Jan 2007
Posts: 651
Germany
Nice thank you very much! If I ever get something finished I'll mention you

Page 2 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | 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