1 registered members (AndrewAMD),
1,018
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
PS1 texturing bubbling ?
#479155
02/25/20 15:22
02/25/20 15:22
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
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!
|
|
|
Re: PS1 texturing bubbling ?
[Re: 3run]
#479161
02/25/20 21:36
02/25/20 21:36
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
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,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
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 My best regards!
|
|
|
Re: PS1 texturing bubbling ?
[Re: 3run]
#479173
02/26/20 10:38
02/26/20 10:38
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I've found this pxs_retroshader for Unity. And there was this part in it: #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: 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
|
|
|
Re: PS1 texturing bubbling ?
[Re: 3run]
#479178
02/26/20 16:16
02/26/20 16:16
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I came up with this code at the end (vertex lightning):
#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: 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 #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
|
|
|
Re: PS1 texturing bubbling ?
[Re: 3run]
#479181
02/27/20 01:01
02/27/20 01:01
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İ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,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
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.: - 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 UnityAs 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: -affine texture mapping -vertex lightning + static lightmap (too dark, I'm probably using it incorrectly.. but at least I see lightmap) Not working: Any ideas on how to calculate vertex spotlight or how to fix fog are welcome! The fog one is really strange, since I don't change inPos at all.. Best regards!
|
|
|
Re: PS1 texturing bubbling ?
[Re: 3run]
#479183
02/27/20 10:12
02/27/20 10:12
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I guess I got fog working.. carried it out into PixelShader. Testing now. The only thing left is spotlight calculations. Got to think how to make it work.. Edit: I also found this on github //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.
|
|
|
|