Gamestudio Links
Zorro Links
Newest Posts
Loging off automatically ?
by old_bill. 03/30/20 22:07
Need help to log in my broker into ZORRO
by buttcorgi. 03/30/20 19:52
textureLod into HLSL
by 3run. 03/30/20 18:01
Running banchmark test with FxPro on MT4
by Cobus. 03/30/20 14:55
Read Z12.fac while running Z2
by AndrewAMD. 03/29/20 22:32
Comment Out
by danatrader. 03/29/20 22:03
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
5 registered members (Seymour, AndrewAMD, jj02520024, jbhunter, alibaba), 675 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
gonzalez21, Cobus, HF_Psy, jj02520024, heitorfr
18409 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
PS1 texturing bubbling ? #479155
02/25/20 15:22
02/25/20 15:22
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
Hey!

I wonder if it's possible to get ps1 styled texture bubbling ? If I understood correctly from googling, it requires to have 'affine texture mapping' instead of default perspective correct texturing.
Here on this video, you can see what I mean:
Godot engine - Affine texture mapping (PS1-style)

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479161
02/25/20 21:36
02/25/20 21:36
Joined: Oct 2007
Posts: 5,176
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,176
İstanbul, Turkey
Code
const float4x4 matWorldViewProj;
const float4x4 matWorld; 
texture entSkin1; 

// Color map sampler
sampler ColorMapSampler = sampler_state 
{ 
   Texture = <entSkin1>; 

}; 
    
// Vertex Shader: 
void DiffuseVS( 
   in float4 InPos: POSITION, 
   in float3 InNormal: NORMAL, 
   in float2 InTex: TEXCOORD0, 
   out float4 OutPos: POSITION, 
   out float2 OutTex: TEXCOORD0, 
   out float3 OutNormal: TEXCOORD1) 
{ 
   OutPos = mul(InPos, matWorldViewProj); 
   OutPos /= OutPos.w;
   OutNormal = normalize(mul(InNormal, matWorld));
   OutTex = InTex; 
} 
    
// Pixel Shader: 
float4 DiffusePS( 
   in float2 InTex: TEXCOORD0, 
   in float3 InNormal: TEXCOORD1): COLOR 
{ 
   return tex2D(ColorMapSampler, InTex); 
} 
 
// Technique: 
technique AffineTechnique 
{ 
   pass P0 
   { 
      VertexShader = compile vs_2_0 DiffuseVS(); 
      PixelShader  = compile ps_2_0 DiffusePS(); 
   } 
} 


Just the most basic texture mapping, no lights, no sun, no ambient. Only difference is OutPos /= OutPos.w; line.

Explanation here: https://webglfundamentals.org/webgl/lessons/webgl-3d-perspective-correct-texturemapping.html

Last edited by Quad; 02/25/20 21:39.

3333333333
Re: PS1 texturing bubbling ? [Re: 3run] #479164
02/25/20 22:05
02/25/20 22:05
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
Salam aleykum, Quad!

Thank you very much for the working example and a link to the article! I guess acknex is pretty awesome for ps1 styled games since it provides outdated graphics out of the box grin

My best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479169
02/26/20 00:26
02/26/20 00:26
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
Wow, this get's messed up when I try to apply this material on the plane grin
[Linked Image]
[Linked Image]
What would you suggest guys? I love results on the first screen, but the second one is just a mess grin

It's awesome to see that it only takes one line of code to get this retro look but one line isn't probably enough to get it suitable for games?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479170
02/26/20 08:18
02/26/20 08:18
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
After playing around I've got even more weird results, but now with fog and perpixel lightning grin
[Linked Image]
Any ideas on how to fix that mess on previous screens are welcome! It would be great to get something like this working for oldschool projects.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479173
02/26/20 10:38
02/26/20 10:38
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
I've found this pxs_retroshader for Unity.

And there was this part in it:
Code
#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)

float distance = length(mul(UNITY_MATRIX_MV,v.vertex));

//Affine Texture Mapping
float4 affinePos = vertex;//vertex;				
o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv_MainTex *= distance + (vertex.w*(UNITY_LIGHTMODEL_AMBIENT.a * 8)) / distance / 2;
o.normal = distance + (vertex.w*(UNITY_LIGHTMODEL_AMBIENT.a * 8)) / distance / 2;
After googling around, I came up with this results:
Code
const float4x4 matWorldViewProj;
const float4x4 matWorld; 
texture entSkin1; 

// Color map sampler
sampler ColorMapSampler = sampler_state 
{ 
	Texture = <entSkin1>; 
}; 

// Vertex Shader: 
void DiffuseVS( 
in float4 InPos: POSITION, 
in float3 InNormal: NORMAL, 
in float2 InTex: TEXCOORD0, 
out float4 OutPos: POSITION, 
out float2 OutTex: TEXCOORD0, 
out float3 OutNormal: TEXCOORD1) 
{
	float distance = length(mul(InPos, matWorldViewProj));
	OutPos = mul(InPos, matWorldViewProj); 
	OutPos *= distance + (OutPos.w * (0.1)) / distance / 2;
	//OutNormal = distance + (OutPos.w * (0.1)) / distance / 2;
	OutNormal = normalize(mul(InNormal, matWorld));
	OutTex = InTex; 
} 

// Pixel Shader: 
float4 DiffusePS( 
in float2 InTex: TEXCOORD0, 
in float3 InNormal: TEXCOORD1): COLOR 
{ 
	return tex2D(ColorMapSampler, InTex); 
} 

// Technique: 
technique AffineTechnique 
{ 
	pass P0 
	{ 
		VertexShader = compile vs_2_0 DiffuseVS(); 
		PixelShader  = compile ps_2_0 DiffusePS(); 
	} 
}
But I'm not sure, if I've done it correctly grin
[Linked Image]


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479178
02/26/20 16:16
02/26/20 16:16
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
I came up with this code at the end (vertex lightning):
Code
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <light>
#include <color>

#define DXLIGHTING
#define DXFOG

struct vertexOut
{
	float4 Pos : POSITION;
	float Fog : FOG;
	float4 Color : COLOR0;
	float2 Tex : TEXCOORD0;
	float2 LM : TEXCOORD1;
};

vertexOut solid_VS (
in float4 inPos : POSITION, 
in float3 inNormal : NORMAL,
in float2 inTex : TEXCOORD0,
in float2 inLM : TEXCOORD1
)
{
	vertexOut Out;
	Out.Pos = DoTransform(inPos);
	Out.Pos *= inPos.w / length(mul(inPos, matWorldViewProj));
	Out.Tex = inTex;
	Out.LM = inLM;
	Out.Fog = DoFog(inPos);
	float3 P = DoPos(inPos);
	float3 N = DoNormal(inNormal);

	float3 Color = 0; 
	for (int i = 0; i < 8; i++)  // add 8 dynamic lights
	{
		Color += DoLight(P, N, i);
	}

	Out.Color = 0.5 * DoAmbient() + 0.5 * float4(Color, 1) * vecDiffuse;

	return Out;		
}

technique solid
{
	pass one
	{		
		CullMode = None;
		ZWriteEnable = True;
		AlphaBlendEnable = False;
		AlphaTestEnable = False;
		
		VertexShader = compile vs_2_0 solid_VS();
	}
}

technique fallback { pass one { } }
However for unknown (for me) reasons, this line:
Code
Out.Pos *= inPos.w / length(mul(inPos, matWorldViewProj));
Removes the fog.. Also, I don't know how to add static lightmap to this lightning using default.fx grin
Code
		#ifdef DXFOG
			float DoFog(float4 Pos)
			{
				float3 P = mul(Pos,matWorldView).xyz; // convert vector to view space to get it's depth (.z)
				return saturate((vecFog.y-P.z) * vecFog.z); // apply the linear fog formula
			}
			#else // distance based fog
			float DoFog(float4 Pos)
			{
				float3 P = mul(Pos,matWorld).xyz;
				return 1 - (distance(P,vecViewPos.xyz)-vecFog.x) * vecFog.z;
			}
		#endif


[Linked Image]


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479181
02/27/20 01:01
02/27/20 01:01
Joined: Oct 2007
Posts: 5,176
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,176
İstanbul, Turkey
Hey that looks great, proper ps1 look except for the screen resoluıion.

Also as far as i know static lightmaps requires you use second skin or something, not sure.


3333333333
Re: PS1 texturing bubbling ? [Re: 3run] #479182
02/27/20 08:17
02/27/20 08:17
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
Thank you!

Yes, screen resolution is too low, changed it to 640x480. Also, there are some other stuff needs to be added to get proper ps1 look, f.e.:
Quote
- vertex inaccuracy;
- screen-space dithering;

With all of them working together this could look really awesome! I think acknex is only suitable for oldschool styled games, compared to up-to-date game engines.

Take a look at this video showing PSXEffects in Unity engine:
PSXEffects - Retro PlayStation 1 Graphics in Unity

As for static lightmap, yes I know it's stored in the entSkin2 but I don't know how to use it properly... I wish there were original mtl_shaded and mtl_model .fx files, so I could modify them directly, instead of trying to write everything on my own (since I'm not good at shaders at all). I just couldn't find them.. They are defined as ENGINE_MATERIAL mtl_shaded in avars.h and that's all...

So far I got working:
Quote
-affine texture mapping
-vertex lightning + static lightmap (too dark, I'm probably using it incorrectly.. but at least I see lightmap)

Not working:
Quote
-fog
-spotlights


Any ideas on how to calculate vertex spotlight or how to fix fog are welcome! laugh The fog one is really strange, since I don't change inPos at all..

[Linked Image]

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: PS1 texturing bubbling ? [Re: 3run] #479183
02/27/20 10:12
02/27/20 10:12
Joined: May 2009
Posts: 5,192
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
I guess I got fog working.. grin carried it out into PixelShader. Testing now.
[Linked Image]

The only thing left is spotlight calculations. Got to think how to make it work..

Edit:

I also found this on github
Code
//Vertex snapping
float4 snapToPixel = mul(UNITY_MATRIX_MVP,v.vertex);
float4 vertex = snapToPixel;
vertex.xyz = snapToPixel.xyz / snapToPixel.w;
vertex.x = floor(160 * vertex.x) / 160;
vertex.y = floor(120 * vertex.y) / 120;
vertex.xyz *= snapToPixel.w;
o.pos = vertex;
Would be awesome if I could get it to work too !

Edit2: damn.. I didn't think that it would be so easy to implement vertex snapping... man I love results I'm getting !

Edit3: added shader cut off on distance!

Last edited by 3run; 02/27/20 10:52.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Page 1 of 2 1 2

Moderated by  Blink, Hummel, Superku 

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