Page 1 of 1
[Question] Depth Cueing fog + texture
Posted: September 26th, 2019, 4:44 am
by NITROYUASH
Hi PSXDEV :>
Using something like DpqColor (or GTE variations like gte_dpcs), i can make a interesting effects like fog.
Thanks to SetBackColor and SetFarColor i can change front/back colors. It's looks good when i uses the non-textured objects/geometry.
But it's works differently with the textured objects.
I can change the color, but as you can see, i just can't hide the texture. It always visible when I try to use something other than black.
Is it possible to do something for this WITHOUT change actual texture or CLUT?
Thanks for the answers :>
Re: [Question] Depth Cueing fog + texture
Posted: September 26th, 2019, 10:59 pm
by LameGuy64
To get proper color modulation for textures, you'll have to use a method called CLUT fog, where you have multiple CLUT entries stacked vertically of the CLUT transitioning from its original colors down to a solid color of your fog. The CLUT selected is based on the depth of the polygon primitive.
Currently, there are no tools that can generate a CLUT fog, but you can procedurally generate it on the fly. I'll need a bit of time to figure this one out first before I can post a code snippet.
Re: [Question] Depth Cueing fog + texture
Posted: September 27th, 2019, 12:13 am
by NITROYUASH
Yes i saw some samples from Psy-Q. I found this example and play with it right now:
Code: Select all
/* Sony Computer Entertainment CLUT-FOG maker
rtim: CLUT position (RECT)
ctim: insert CLUT here
num: Depth size to save in VRAM */
void sce_make_fog_clut(RECT *rtim, u_short *ctim, long num) {
long i,j;
long stp;
long p;
u_short newclut[256];
CVECTOR orgc, newc;
RECT rect;
rect.x = rtim->x;
rect.w = rtim->w;
rect.h = rtim->h;
for (i = 0; i < num; i++) {
p = i * ONE / num; // p = depth queue parameter
for (j = 0; j < rtim->w; j++) {
if (ctim[j] == 0) { // no interpolation when transparent
newclut[j] = ctim[j];
} else {
// decompose the clut into RGB
orgc.r = (ctim[j] & 0x1f) << 3;
orgc.g = ((ctim[j] >> 5) & 0x1f) << 3;
orgc.b = ((ctim[j] >> 10) & 0x1f) << 3;
stp = ctim[j] & 0x8000;
// interpolate each RGB and BG color
gte_DpqColor(&orgc, p, &newc);
// reconstruct CLUT with FOG
newclut[j] = stp | (newc.r >> 3)
| (((u_long)(newc.g & 0xf8)) << 2)
| (((u_long)(newc.b & 0xf8)) << 7);
}
}
/* next Y axis */
rect.y = rtim->y + i;
/* load to VRAM */
LoadImage(&rect,(u_long *)newclut);
}
}
For some reasons it will make incorrect CLUT from AGsIMAGE struct so i need to solve this problem before i am actually can test it on my 3d objects.
Re: [Question] Depth Cueing fog + texture
Posted: September 28th, 2019, 6:52 am
by NITROYUASH
I made it :>
Tested on 4b textures
Code: Select all
// DPQ FOG CLUT
typedef struct {
u_long *timaddr;
CVECTOR fog_clr;
u_short cdpq;
} DPQCLUT;
int clut_dpq_fog(DPQCLUT *dclut) {
long stp;
long p,i,j;
TIM_IMAGE timinfo;
CVECTOR ccout;
RECT rect;
u_short *clut;
u_short newclut[256];
// Open TIM file
if (OpenTIM(dclut->timaddr) != 0)
return (-1);
// Read TIM file data
ReadTIM(&timinfo);
// Load CLUT to VRAM
LoadImage(timinfo.crect, timinfo.caddr);
DrawSync(0);
// Transfer CLUT data to out RECT
rect.x = timinfo.crect->x;
rect.y = timinfo.crect->y;
rect.w = timinfo.crect->w;
rect.h = timinfo.crect->h;
clut = (u_short*)timinfo.caddr;
for (i = 0; i < dclut->cdpq; i++) {
// p = depth queue parameter
p = i * ONE / dclut->cdpq;
for (j = 0; j < rect.w; j++) {
if (clut[j] == 0) { // No interpolation when transparent
newclut[j] = clut[j];
} else {
// Decompose original CLUT into RGB
dclut->fog_clr.r = (clut[j] & 0x1f) << 3;
dclut->fog_clr.g = ((clut[j] >> 5) & 0x1f) << 3;
dclut->fog_clr.b = ((clut[j] >> 10) & 0x1f) << 3;
stp = clut[j] & 0x8000;
// Interpolate each RGB and BG color
gte_DpqColor(&dclut->fog_clr, p, &ccout);
// Reconstruct CLUT with FOG
newclut[j] = stp | (ccout.r >> 3)
| (((u_long)(ccout.g & 0xf8)) << 2)
| (((u_long)(ccout.b & 0xf8)) << 7);
}
}
rect.y = timinfo.crect->y + i;
// load to VRAM
LoadImage(&rect,(u_long *)newclut);
DrawSync(0);
}
return (0);
}
So this is why CLUT in VRAM from some games contains so many copies with different colors...
Re: [Question] Depth Cueing fog + texture
Posted: September 29th, 2019, 3:20 am
by rama3
NITROYUASH and LameGuy64,
I'm terribly sorry for asking this here, but you guys seem to know your PSX dev! :p
Do you know what the maximum active video area of the console is?
It doesn't matter what the image data source is, so a CPU generated chequerboard pattern for example would work.
I just need it to occupy as much of the available display width as possible.
Any GPU dotclock is fine.
Thanks
Re: [Question] Depth Cueing fog + texture
Posted: September 29th, 2019, 10:55 pm
by NITROYUASH
You mean the biggest video resolution?
If i understand you correctly:
640x480 NTSC and 640x512 PAL
Re: [Question] Depth Cueing fog + texture
Posted: September 30th, 2019, 8:42 am
by rama3
And is there no way to draw outside these boundaries?
This might not be documented in any SDK.
Re: [Question] Depth Cueing fog + texture
Posted: September 30th, 2019, 10:15 am
by NITROYUASH
The only thing than you can draw outside screen resolution is the textures, UI elements (fonts, interface graphics...), CLUT (4b/8b palette) and something like this. I never saw a game that actually uses the screen more than the 640x480/512. But you can change the resolution on the fly. I mainly use 320x240 resolution. This is the most common resolution for this system, but this is the not the perfect, i read a lot about a games that runs under the non-common resolution like Wip3out (512x240).
Re: [Question] Depth Cueing fog + texture
Posted: September 30th, 2019, 1:44 pm
by LameGuy64
You can use a DR_ENV primitive to change the active drawing area to some place outside your display/draw areas for off-screen rendering. This can be used as a way to accomplish render to texture based effects.
Re: [Question] Depth Cueing fog + texture
Posted: October 1st, 2019, 4:01 am
by rama3
Perfect, thanks for letting me know. So basically "something is/may be possible" :p
The reason I'm asking is that I love the PSX as a very clean source of retro / 15kHz video.
I'd like to extend the PSX port of the 240p test suite to include such a drawing area test.
This is to help develop my open source upscaler project.
https://github.com/filipalac/240pTestSuite-PS1
https://github.com/ramapcsx2/gbs-control