|
Re: pp_set/add setting obscure screen size
[Re: Stansmedia]
#442113
06/11/14 19:04
06/11/14 19:04
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Is it normal for mirror planes and water reflections to mirror the view at a higher inverted z? Like, if something was halfway in the water, and the reflection didn't match up with the model. Is that normal? Or can this be fixed. This sounds like your reflection view z or the waterheight is not set correctly. Just don't set NOSHADER for the reflection view, it's stupid that this flag is there anyway.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: pp_set/add setting obscure screen size
[Re: Superku]
#442174
06/14/14 03:11
06/14/14 03:11
|
Joined: Mar 2003
Posts: 1,524 Canada
Stansmedia
OP
Serious User
|
OP
Serious User
Joined: Mar 2003
Posts: 1,524
Canada
|
Where should I slip the clip(..) into the shader code?
//////////////////////////////////////////////////////////////////////
// Blinn / Phong bump mapping
// (c) oP group 2010 Version 2.3
//////////////////////////////////////////////////////////////////////
#include <bump_vs>
#include <phong>
bool REQUIRE_NORMAL;
texture entSkin1; // texture
texture entSkin2; // normal map or lightmap
texture entSkin3; // normal map on blocks
sampler sBaseTex = sampler_state { Texture = <entSkin1>; MipFilter = Linear; };
sampler sSkin2 = sampler_state { Texture = <entSkin2>; MipFilter = None; };
sampler sSkin3 = sampler_state { Texture = <entSkin3>; MipFilter = None; };
float3 DoSpecular(bumpOut In,float3 Normal,float fSpecular)
{
#ifdef BLINN
float3 viewDir = -normalize(In.ViewDir);
float fLight = dot(In.LightDir1.xyz,Normal);
float3 R = reflect(In.LightDir1.xyz,Normal);
float3 Diffuse = DoPhong(In.Diffuse1,fLight,dot(R,viewDir),fSpecular);
fLight = dot(In.LightDir2.xyz,Normal);
R = reflect(In.LightDir2.xyz,Normal);
Diffuse += DoPhong(In.Diffuse2,fLight,dot(R,viewDir),fSpecular);
fLight = dot(In.LightDir3.xyz,Normal);
R = reflect(In.LightDir3.xyz,Normal);
Diffuse += DoPhong(In.Diffuse3,fLight,dot(R,viewDir),fSpecular);
#else // PHONG
float fLight = dot(In.LightDir1.xyz,Normal);
float3 Diffuse = DoPhong(In.Diffuse1,fLight,fLight,fSpecular);
fLight = dot(In.LightDir2.xyz,Normal);
Diffuse += DoPhong(In.Diffuse2,fLight,fLight,fSpecular);
fLight = dot(In.LightDir3.xyz,Normal);
Diffuse += DoPhong(In.Diffuse3,fLight,fLight,fSpecular);
#endif
return Diffuse;
}
float4 specBump_PS(bumpOut In): COLOR
{
float4 Base = tex2D(sBaseTex,In.Tex12.xy);
float3 Normalmap = tex2D(sSkin2,In.Tex12.xy)*2-1;
float3 Diffuse = DoSpecular(In,Normalmap,Base.w);
return Base * DoColor(Diffuse,In.Ambient);
}
float4 specBumpLM_PS(bumpOut In): COLOR
{
float4 Base = tex2D(sBaseTex,In.Tex12.xy);
float4 Lightmap = tex2D(sSkin2,In.Tex12.zw);
float3 Normalmap = tex2D(sSkin3,In.Tex12.xy)*2-1;
float3 Diffuse = DoSpecular(In,Normalmap,Base.w);
return Base * DoLightmap(Diffuse,Lightmap,In.Ambient);
}
technique spec
{
pass one
{
ZWriteEnable = True;
AlphaBlendEnable = False;
VertexShader = compile vs_2_0 bump_VS();
PixelShader = compile ps_2_0 specBump_PS();
}
}
technique spec_lm
{
pass one
{
ZWriteEnable = True;
AlphaBlendEnable = False;
VertexShader = compile vs_2_0 bump_VS();
PixelShader = compile ps_2_0 specBumpLM_PS();
}
}
technique fallback { pass one { } }
|
|
|
Re: pp_set/add setting obscure screen size
[Re: Superku]
#442186
06/14/14 16:18
06/14/14 16:18
|
Joined: Mar 2003
Posts: 1,524 Canada
Stansmedia
OP
Serious User
|
OP
Serious User
Joined: Mar 2003
Posts: 1,524
Canada
|
Thank you. Being able to switch the material in the view has made this a lot frickin creepier. But it is not clipping at the water plane :'(
// Tweakables:
static const float AmbientIntensity = 1.0f; // The intensity of the ambient light.
static const float DiffuseIntensity = 1.0f; // The intensity of the diffuse light.
static const float SpecularIntensity = 1.0f; // The intensity of the specular light.
static const float SpecularPower = 8.0f; // The specular power. Used as 'glossyness' factor.
static const float4 SunColor = {0.9f, 0.9f, 0.5f, 1.0f}; // Color vector of the sunlight.
float water_height_var;
// Application fed data:
const float4x4 matWorldViewProj; // World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4 vecAmbient; // Ambient color.
const float4 vecSunDir; // Sun light direction vector.
const float4 vecViewPos; // View position.
float3x3 matTangent; // hint for the engine to create tangents in TEXCOORD2
texture mtlSkin1;
sampler ColorMapSampler = sampler_state // Color map sampler.
{
Texture = <mtlSkin1>;
MipFilter = Linear; // required for mipmapping
};
texture mtlSkin2; // Normal map.
sampler NormalMapSampler = sampler_state // Normal map sampler.
{
Texture = <mtlSkin2>;
MipFilter = None; // a normal map usually has no mipmaps
};
// Vertex Shader:
void NormalMapVS( in float4 InPos: POSITION,
in float3 InNormal: NORMAL,
in float3 InTex: TEXCOORD0,
in float4 InTangent: TEXCOORD2,
out float4 OutPos: POSITION,
out float3 OutTex: TEXCOORD0,
out float3 OutViewDir: TEXCOORD1,
out float3 OutSunDir: TEXCOORD2)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);
// Pass the texture coordinate to the pixel shader:
OutTex = InTex;
OutTex.z = mul(InPos,matWorld).y;
// Compute 3x3 matrix to transform from world space to tangent space:
matTangent[0] = mul(InTangent.xyz, matWorld);
matTangent[1] = mul(cross(InTangent.xyz, InNormal)*InTangent.w, matWorld);
matTangent[2] = mul(InNormal, matWorld);
// Calculate the view direction vector in tangent space:
OutViewDir = normalize(mul(matTangent, (vecViewPos - mul(InPos,matWorld))));
// Calculate the light direction vector in tangent space:
OutSunDir = normalize(mul(matTangent, -vecSunDir));
}
// Pixel Shader:
float4 NormalMapPS(
in float3 InTex: TEXCOORD0,
in float3 InViewDir: TEXCOORD1,
in float3 InSunDir: TEXCOORD2): COLOR
{
clip(InTex.z-water_height_var);
// Read the normal from the normal map and convert from [0..1] to [-1..1] range
float3 BumpNormal = tex2D(NormalMapSampler, InTex)*2 - 1;
// Calculate the ambient term:
float4 Ambient = AmbientIntensity * vecAmbient;
// Calculate the diffuse term:
float4 Diffuse = DiffuseIntensity * SunColor * saturate(dot(InSunDir, BumpNormal));
// Calculate the reflection vector:
float3 R = normalize(2 * dot(BumpNormal, InSunDir) * BumpNormal - InSunDir);
// Calculate the specular term:
InViewDir = normalize(InViewDir);
float Specular = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;
// Fetch the pixel color from the color map:
float4 Color = tex2D(ColorMapSampler, InTex);
// Calculate final color:
return (Ambient + Diffuse + Specular) * Color;
}
// Technique:
technique NormalMapTechnique
{
pass P0
{
VertexShader = compile vs_2_0 NormalMapVS();
PixelShader = compile ps_2_0 NormalMapPS();
}
}
EDIT: Works! The water_heigh_var isn't making its way into the shader properly.. I just set my water plan height directly in the shader and it works
Last edited by Stansmedia; 06/14/14 19:59.
|
|
|
|