NormalMapping + TRANSLUCENT or UVmovement ??

Posted By: darkinferno

NormalMapping + TRANSLUCENT or UVmovement ?? - 01/27/12 00:33

ah yes, something am not fond of doing but here goes:

i'm seeking a Norm+Spec shader with support for:
translucent or uv movement, maybe tanslucent AND uv movement?

Ive been searching but no luck so far? so maybe one of you knows of such a shader ? or can *cough* tweak one for us ?


Posted By: HeelX

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/27/12 10:35

For translucent parts you just have to read out the .a part of the texture and print it put to screen. For uv-movement, you have to put into skills for example the uv-shift parameters; in the vertex shader you have to add this to the uv-coords you'll get.
Posted By: darkinferno

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/27/12 13:33

ok i know it sounds simple but i have never looked into shader code, i do have solutions in mind though, just not along the lines of tweaking shaders, which i know would be the right path..
Posted By: darkinferno

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 18:25

so, noone interested?
Posted By: Uhrwerk

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 19:26

Why don't you post a Norm+Spec shader? We'll then see if once can change it.
Posted By: darkinferno

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 20:01

well we could use the NM shader from the massive shader collection:

Code:
/*********************************************************************NVMH3****
File: $Id: //sw/devtools/ShaderLibrary/main/HLSL/relief_mapping.fx#1 $

Copyright NVIDIA Corporation 2007
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

% This material shows and compares results from four popular and
% advanced schemes for emulating displaement mapping.  They are:
% Relief Mapping, Parallax Mapping, Normal Mapping, and Relief
% Mapping with Shadows.  Original File by Fabio Policarpo.

keywords: material bumpmap
date: 070305

Note: Strong discontinuties in the model geometric normal (e.g., very sharp
    differences from the normals in two or more parts of the same triangle)
    can cause unusual overall light-attentuation errors. Re-normalizing the
    rasterized normals in the pixel shader can correct this, but the case
    was considered rare enough that these extra steps were eliminated for
    code efficiency. If you see off lighting near sharp model edges, just
    normalize "IN.normal" in the calculation of the varible "att" (shared
    by all techniques).

******************************************************************************/

//// UN-TWEAKABLES - AUTOMATICALLY-TRACKED TRANSFORMS ////////////////

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matView;
float4x4 matWorldView;

float4 vecViewPos;
float4 vecFog;
float4 vecSunPos;
float4 vecLight;
float4 vecLightPos[8];
float4 vecLightColor[8];

float3 vecDiffuse;
float3 vecSpecular;

/////////////// Tweakables //////////

float PhongExp = 128.0;
float TileCount = 2;
float Depth = 0.1;

/*********** TEXTURES ***************/

texture entSkin1;

sampler2D ColorSampler = sampler_state
{
    Texture = <entSkin1>;
    MinFilter = Linear;
    MipFilter = Linear;
    MagFilter = Linear;
    AddressU = Wrap;
    AddressV = Wrap;
};

texture entSkin2;

sampler2D ReliefSampler = sampler_state
{
    Texture = <entSkin2>;
    MinFilter = Linear;
    MipFilter = Linear;
    MagFilter = Linear;
    AddressU = Wrap;
    AddressV = Wrap;
};

/********** CONNECTOR STRUCTURES *****************/

struct AppVertexData
{
    float4 pos		: POSITION;
    float4 color	: COLOR0;
    float3 normal	: NORMAL; // expected to be normalized
    float2 txcoord: TEXCOORD0;
    float3 tangent: TEXCOORD2; // pre-normalized
};

struct VertexOutput
{
	float4 color	: COLOR0;
	float4 hpos		: POSITION;
	float2 UV		: TEXCOORD0;
	float3 vpos		: TEXCOORD1;
	float3 tangent	: TEXCOORD2;
	float3 binormal: TEXCOORD3;
	float3 normal	: TEXCOORD4;
	float4 Sun		: TEXCOORD5;
	float4 Light1	: TEXCOORD6;
	float4 Light2	: TEXCOORD7;
	
	float Fog		: FOG;
};


/*** SHADER FUNCTIONS **********************************************/

VertexOutput view_spaceVS(AppVertexData IN)
{
	VertexOutput OUT = (VertexOutput)0;
	
	float3 binormal = cross(IN.normal,IN.tangent);
	
   // isolate matWorldView rotation-only part
   float3x3 modelViewRotXf;
   modelViewRotXf[0] = matWorldView[0].xyz;
   modelViewRotXf[1] = matWorldView[1].xyz;
   modelViewRotXf[2] = matWorldView[2].xyz;
   OUT.hpos = mul(IN.pos,matWorldViewProj);
   
   // vertex position in view space (with model transformations)
   OUT.vpos = mul(IN.pos,matWorldView).xyz;
   
   // vertex position in world space
   float3 PosWorld = mul(IN.pos, matWorld);
   
   // sun position in view space
   float4 Sun = float4(vecSunPos.xyz,1); // this point in world space
   OUT.Sun = mul(Sun,matView); // this point in view space
   
   // Light 1
   float4 Light1 = float4(vecLightPos[0].xyz,1); // this point in world space
   OUT.Light1 = mul(Light1,matView); // this point in view space
   OUT.Light1.w = distance(PosWorld,vecLightPos[0])/vecLightPos[0].w;
   
   // Light 2
   float4 Light2 = float4(vecLightPos[1].xyz,1); // this point in world space
   OUT.Light2 = mul(Light2,matView); // this point in view space
   OUT.Light2.w = distance(PosWorld,vecLightPos[1])/vecLightPos[1].w;
   
   // tangent space vectors in view space (with model transformations)
   OUT.tangent = mul(IN.tangent,modelViewRotXf);
   OUT.binormal = mul(binormal,modelViewRotXf);
   OUT.normal = mul(IN.normal,modelViewRotXf);
   
   // copy color and texture coordinates
   OUT.color = IN.color; // currently ignored by all techniques
   OUT.UV = TileCount * IN.txcoord.xy;

   // calculate Fog
   OUT.Fog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);

   return OUT;
}


/************ PIXEL SHADERS ******************/

float4 normal_mapPS(VertexOutput IN) : COLOR
{
	float3 tNorm = tex2D(ReliefSampler,IN.UV).xyz - float3(0.5,0.5,0.5);

	// transform tNorm to world space
	tNorm = normalize(tNorm.x*IN.tangent -
	tNorm.y*IN.binormal + 
	tNorm.z*IN.normal);
	float4 texCol = tex2D(ColorSampler,IN.UV);

	// view and light directions
	float3 Vn = normalize(IN.vpos);
	float3 Sn = normalize(IN.Sun.xyz-IN.vpos);
	float3 L1n = normalize(IN.Light1.xyz-IN.vpos);
	float3 L2n = normalize(IN.Light2.xyz-IN.vpos);

	// compute diffuse and specular terms
	float attS = saturate(dot(Sn,IN.normal));
	float diffS = saturate(dot(Sn,tNorm));
	float specS = saturate(dot(normalize(Sn-Vn),tNorm));
	specS = pow(specS,PhongExp);
	
	float att1 = 1-dot(IN.Light1.w,IN.Light1.w);
	float diff1 = saturate(dot(L1n,tNorm));
	float spec1 = saturate(dot(normalize(L1n-Vn),tNorm));
	spec1 = pow(spec1,PhongExp);
	
	float att2 = 1-dot(IN.Light2.w,IN.Light2.w);
	float diff2 = saturate(dot(L2n,tNorm));
	float spec2 = saturate(dot(normalize(L2n-Vn),tNorm));
	spec1 = pow(spec2,PhongExp);

	// compute final color
	
	float3 finalcolor = vecLight.xyz*texCol.xyz
								+attS*(texCol.xyz*vecDiffuse.xyz*diffS+vecSpecular*specS*texCol.w)
								+att1*(texCol.xyz*vecDiffuse.xyz*diff1+vecSpecular*spec1*texCol.w)
								+att2*(texCol.xyz*vecDiffuse.xyz*diff2+vecSpecular*spec2*texCol.w);
	return float4(finalcolor.rgb,1.0);
}


/////////////////Techniques/////////////////

technique normal_mapping
{
	pass p0
	{
		// CullMode = CW;
		VertexShader = compile vs_2_0 view_spaceVS();
		ZEnable = true;
		ZWriteEnable = true;
		ZFunc = LessEqual;
		CullMode = None;
		PixelShader  = compile ps_2_a normal_mapPS();
	}
}


Posted By: Uhrwerk

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 21:57

Code:
return float4(finalcolor.rgb,1.0);


The 1.0 is the alpha value. You can write 0.5 instead and you'll get a semi-transparent model. Alternatively you can write "texCol.a" which will take the alpha value from the diffuse texture.
Code:
float3 tNorm = tex2D(ReliefSampler,IN.UV).xyz - float3(0.5,0.5,0.5);


Code:
float4 texCol = tex2D(ColorSampler,IN.UV);


This is where the texture lookups happen, one for the diffuse texture, one for the normal map (The normal map is the one on top). You can do a simple uv shift by adding the following line in front of the two above:
Code:
IN.UV.x += vecTime.w;


Posted By: alibaba

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 21:59

Hahah grin He is not german
Posted By: Rondidon

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 22:05

Yes, you should translate your post. Darkinferno comes from Jamaica
Posted By: darkinferno

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 23:01

lol thanks man, the translucency worked perfect... that will be so useful for us later

however the uv movement gave me a "cant compile effect" error, if i replace the vecTime.w with say "1", it runs, no results ofcourse though.

oh and thanks for the translation request guys =]

Posted By: Uhrwerk

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 23:09

That sounds as if you forgot to declare vecTime. The following line is already there:
Code:
float4 vecLightColor[8];


Right after that line insert:
Code:
float4 vecTime;


Does that fix the error message?
Posted By: darkinferno

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 23:20

yes it does, thanks man, ive only started looking at shaders recently, didnt think i would have to declare vecTime, anyways, thanks much, this helps us alot more than you'd think ^^
Posted By: Uhrwerk

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 01/31/12 23:43

You're welcome! :-)

(I pretty much had to with that cat picture ^^)
Posted By: Tempelbauer

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 02/01/12 01:02

Spiegeln sich da die Dreamworks-Studios in den Augen der Katze?
Posted By: darkinferno

Re: NormalMapping + TRANSLUCENT or UVmovement ?? - 02/01/12 01:15

Originally Posted By: Uhrwerk
You're welcome! :-)

(I pretty much had to with that cat picture ^^)


xD
© 2024 lite-C Forums