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
9 registered members (AndrewAMD, jbhunter, alibaba, 3run, buttcorgi, Ayumi, marsz, Lozoteva, 1 invisible), 669 guests, and 6 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 2 of 2 1 2
Re: PS1 texturing bubbling ? [Re: 3run] #479184
02/27/20 11:08
02/27/20 11:08
Joined: May 2009
Posts: 5,192
Caucasus
3run Online OP
Senior Expert
3run  Online OP
Senior Expert

Joined: May 2009
Posts: 5,192
Caucasus
This is what I came up with so far

mtl_shaded.fx
Code
#include <pos>
#include <normal>
#include <lights>

float4x4 matWorldViewProj;
float4 vecViewPos;

float4 vecLightDir[8];

float4 vecFog;
float4 vecFogColor;
float4 vecSkill1;

Texture entSkin1;
Texture entSkin2;

sampler ColorSampler = sampler_state
{
	Texture = <entSkin1>;
	Mipfilter = None;
	Minfilter = None;
	Magfilter = None;
};

sampler ShadowSampler = sampler_state
{
	Texture = <entSkin2>;
	Mipfilter = Linear;
	Minfilter = Linear;
	Magfilter = Linear;
};

struct vertexOut
{
	float4 Pos : POSITION;
	float4 Color : COLOR0;
	float3 Normal : NORMAL;
	float4 Tex : TEXCOORD0;
	float4 WorldPos : TEXCOORD1;
};

vertexOut VS (
in float4 inPos : POSITION,
in float3 inNormal : NORMAL,
in float2 inTex1 : TEXCOORD0,
in float2 inTex2 : TEXCOORD1
)
{
	inPos.w = 1.0f;	
	vertexOut Out;
	
	// vertex snapping
	float4 snapToPixel = mul(inPos, matWorldViewProj);
	float4 vertex = snapToPixel;
	vertex.xyz = snapToPixel.xyz / snapToPixel.w;
	vertex.x = floor((vecSkill1.y + 40) * vertex.x) / (vecSkill1.y + 40); // default 160
	vertex.y = floor(vecSkill1.y * vertex.y) / vecSkill1.y; // default 120
	vertex.xyz *= snapToPixel.w;
	Out.Pos = vertex;
	
	// affine texture mapping
	Out.Pos *= inPos.w / length(mul(inPos, matWorldViewProj));
	
	Out.Normal = normalize (mul(inNormal, (float3x3)matWorld));
	Out.Tex.xy = inTex1.xy;
	Out.Tex.zw = inTex2.xy;
	Out.WorldPos = mul(inPos, matWorld);
	Out.Color = 0;
	
	float3 P = DoPos(inPos);
	float3 N = DoNormal(inNormal);
	
	for(int i = 0; i < 8; i++)
	{
		if(vecLightDir[i].w > 0 && vecLightDir[i].w <= 1000) // spotlight ?
		{
			
		}
		else // pointlight ?
		{
			Out.Color += DoLight(P,N,i);
		}
	}
	
	// cut out polygons
	float distance = length(mul(inPos, matWorldViewProj));
	
	if(vecSkill1.z == 0){ vecSkill1.z = 512; }
	
	if (distance > vecSkill1.z)
	{
		Out.Pos.w = 0;
	}
	
	return Out;
}

float4 PS(vertexOut In) : COLOR0
{
	float4 textureColor = tex2D(ColorSampler, In.Tex.xy);
	float4 color = tex2D(ShadowSampler, In.Tex.zw);
	float fDepth = distance(vecViewPos.xyz, In.WorldPos.xyz);
	
	color += In.Color; // add dynamic lights
	
	color.rgb = saturate(color.rgb);
	color.rgb = pow(color.rgb, vecSkill1.x);
	color.rgb *= textureColor.rgb;
	
	float Fog = saturate((fDepth - vecFog.x) * vecFog.z);
	color.rgb = lerp(color.rgb, vecFogColor, Fog);
	
	color.a = 1;
	
	return color;
}

technique mtl_shaded
{
	pass one
	{
		ZWriteEnable = True;
		AlphaBlendEnable = False;
		AlphaTestEnable = False;
		
		VertexShader = compile vs_3_0 VS();
		PixelShader = compile ps_3_0 PS();
	}
}

Thanks to txesmi, in the past he made perpixel lightning pipeline for me, it helped a lot!
[Linked Image]
Screenshot sadly can't show vertex snapping, but it looks awesome! Next thing to add is a spotlight, but I don't know yet how to do that.

Greets!


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

Joined: May 2009
Posts: 5,192
Caucasus
Multitexture terrain (up to 16 textures? grin ) and now sky supports FOG (thanks to txesmi! he made this awesome stuff for me back in the days)
[Linked Image]


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

Joined: May 2009
Posts: 5,192
Caucasus
I found a very nasty problem in my shaders. The way I handle dynamic (vertex) lights. I calculate everything in VS and then add results to the color in PS.. this results in a weird-looking bug when luminescence lag behind of an actual light source... crazy


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

Joined: May 2009
Posts: 5,192
Caucasus
Lag seems to happen only in VS+PS 3.0 and in 2.0 it seems to work fine... This means that I won't be able to use spotlights -__- Or maybe I'll figure out how to get rid of this lag in 3.0 somehow. OR I'll need to switch to per pixel lighting...

Edit: nahh... it actually seems, that it's related to the way I add calculated lights in VS to the texture in PS. If light calculations are complex, it lags out. So the one with spotlight won't work for me, if I go with the current setup. If I use default.fx's DoLight function for light calculations (without spotlight) it works pretty normally. I guess I got to think of a better way to pass lights from VS to PS.

Last edited by 3run; 03/01/20 19:21.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Page 2 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