Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Nymphodora), 490 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
NormalMapping + TRANSLUCENT or UVmovement ?? #392748
01/27/12 00:33
01/27/12 00:33
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
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 ?



Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: darkinferno] #392759
01/27/12 10:35
01/27/12 10:35
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
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.

Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: HeelX] #392774
01/27/12 13:33
01/27/12 13:33
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
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..

Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: darkinferno] #393124
01/31/12 18:25
01/31/12 18:25
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
so, noone interested?

Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: darkinferno] #393132
01/31/12 19:26
01/31/12 19:26
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Why don't you post a Norm+Spec shader? We'll then see if once can change it.


Always learn from history, to be sure you make the same mistakes again...
Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: Uhrwerk] #393138
01/31/12 20:01
01/31/12 20:01
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
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();
	}
}



Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: darkinferno] #393145
01/31/12 21:57
01/31/12 21:57
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
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;



Last edited by Uhrwerk; 01/31/12 22:05. Reason: Argh, sry for posting in german in the first place.

Always learn from history, to be sure you make the same mistakes again...
Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: Uhrwerk] #393146
01/31/12 21:59
01/31/12 21:59
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
Hahah grin He is not german

Last edited by alibaba; 01/31/12 22:00.
Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: alibaba] #393148
01/31/12 22:05
01/31/12 22:05
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline
Expert
Rondidon  Offline
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Yes, you should translate your post. Darkinferno comes from Jamaica

Re: NormalMapping + TRANSLUCENT or UVmovement ?? [Re: Rondidon] #393154
01/31/12 23:01
01/31/12 23:01
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
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 =]


Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

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