CGTalk > Techniques > Lighting and Shaders
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 09-22-2012, 07:10 PM   #1
Puterich
Bad Boy
 
Puterich's Avatar
Vincent Schmid
Zurich, Switzerland
 
Join Date: Jul 2007
Posts: 7
CGFX Shader: Normalmap problems in Maya

Hi So I started scripting cgfx shaders in Maya and somehow I cant get the Normal map to work for my cgfx shaders. I even loaded in a shader wich I didn't write myself.
No success...

also the lod function for the cube map gives me weird results.

Script:
Code:
// CGFX Matrices Section float4x4 WorldViewProjection : WorldViewProjection < string UIWidget = "None"; >; float4x4 WorldInverseTranspose : WorldInverseTranspose < string UIWidget = "None"; >; float4x4 ViewInverse : ViewInverse < string UIWidget = "None"; >; float4x4 World : World < string UIWidget = "None"; >; // Maya Description string description = "Phong"; ////////////////////////////////////////////////////////////// // Parameters section float3 shaderColor : Diffuse < string UIName = "Shader Color"; > = {1.0f, 1.0f, 1.0f}; float3 lightDirection : Direction < string UIName = "Light Direction"; > = {0.0f, 1.0f, 0.0f}; float3 ambientColor : Diffuse < string UIName = "Ambient Color"; > = {0.1f, 0.15f, 0.15f}; float fresnelPower < string UIWidget = "slider"; string UIName = "Fresnel Power"; float UIMin = 0.0f; float UIMax = 10.0f; float UIStep = 0.01f; > = 3.0f; float specularPower < string UIWidget = "slider"; string UIName = "Specular Power"; float UIMin = 0.05f; float UIMax = 100.0f; float UIStep = 0.01f; > = 30.0f; float3 specularColor : Diffuse < string UIName = "Specular Color"; > = {1.0f, 1.0f, 1.0f}; texture diffuseTexture < string name = "default_color.dds"; string UIName = "Diffuse Texture"; string TextureType = "2D"; >; sampler2D diffuseMap = sampler_state { Texture = <diffuseTexture>; AddressU = Wrap; AddressV = Wrap; }; texture specTexture < string name = "default_color.dds"; string UIName = "Specualr Texture"; string TextureType = "2D"; >; sampler2D specMap = sampler_state { Texture = <specTexture>; AddressU = Wrap; AddressV = Wrap; }; texture normalTexture < string name = "default_color.dds"; string UIName = "Normal Texture"; string TextureType = "2D"; >; sampler2D normalMap = sampler_state { Texture = <normalTexture>; AddressU = Wrap; AddressV = Wrap; }; ////////////////////////////////////////////////////////////// // Structs section // input from application struct a2v { float4 position : POSITION; float2 texCoord : TEXCOORD0; float4 normal : NORMAL; float4 binormal : BINORMAL; float4 tangent : TANGENT; }; // output to fragment program struct v2f { float4 position : POSITION; float2 texCoord : TEXCOORD0; float3 worldNormal : TEXCOORD1; float3 worldBinormal : TEXCOORD2; float3 worldTangent : TEXCOORD3; float3 eyeVector : TEXCOORD4; }; ////////////////////////////////////////////////////////////// // Vertex Shader v2f vShader(a2v In) { v2f Out; Out.position = mul(WorldViewProjection, In.position); Out.worldNormal = mul(WorldInverseTranspose, In.normal).xyz; Out.worldBinormal = (mul(WorldInverseTranspose, In.binormal).xyz); Out.worldTangent = (mul(WorldInverseTranspose, In.tangent).xyz); float3 worldSpacePos = mul(World, In.position); float3 worldCameraPos = float3(ViewInverse[0].w, ViewInverse[1].w, ViewInverse[2].w); Out.eyeVector = worldCameraPos - worldSpacePos; Out.texCoord = In.texCoord; return Out; } ////////////////////////////////////////////////////////////// // Pixel Shader float4 pShader(v2f In) : COLOR { float4 outColor; float3 worldNormal = tex2D(normalMap, In.texCoord) * 2 -1; worldNormal = normalize((worldNormal.x * In.worldTangent) + (worldNormal.y * In.worldBinormal) + (worldNormal.z * In.worldNormal)); float3 lightDir = normalize(-lightDirection); float3 eyeVector = normalize(In.eyeVector); float4 colorMap = tex2D(diffuseMap, In.texCoord); float4 specularMap = tex2D(specMap, In.texCoord); float3 reflectionVector = -reflect(eyeVector, worldNormal); float3 specular = pow(saturate(dot(reflectionVector, lightDir)), specularPower) * specularColor; float3 lambert = saturate(dot(lightDir, worldNormal)); float3 fresnel = pow(1- saturate(dot(eyeVector, worldNormal)) ,fresnelPower) * lambert; float3 totalSpec = (fresnel * specularMap.r) + (specular * specularMap.g); outColor.rgb = (lambert + ambientColor) * (shaderColor * colorMap.rgb) + totalSpec; outColor.a = 1.0f; return outColor; } ////////////////////////////////////////////////////////////// // Techniques technique Simple { pass one { VertexShader = compile vp40 vShader(); PixelShader = compile fp40 pShader(); } }


hope someone can help me here, because I'm kind of stuck here. no use writing shaders if I can't apply normalmaps :(

cheers
 
Old 10-10-2012, 12:45 PM   #2
Narann
Rendering, Pipeline, etc.
 
Narann's Avatar
portfolio
Dorian FEVRIER
Lighting/Pipeline TD
Atelier Animation
Montreal, Canada
 
Join Date: Mar 2005
Posts: 414
Have you an AMD graphic card? Try to put:

Code:
VertexShader = compile arbvp1 vShader(); PixelShader = compile arbfp1 pShader();


Instead of:

Code:
VertexShader = compile vp40 vShader(); PixelShader = compile fp40 pShader();


Hope this help.

There is a link to a shader I've made:

http://www.fevrierdorian.com/blog/p...gfx_tuto_009.7z

Tutorial is here (french):

http://www.fevrierdorian.com/blog/p...rt-Maya!-Part-5
__________________
My blog (fr)
 
Old 10-17-2012, 03:57 PM   #3
Puterich
Bad Boy
 
Puterich's Avatar
Vincent Schmid
Zurich, Switzerland
 
Join Date: Jul 2007
Posts: 7
Thank you

This is my graphc card:

ATI Radeon HD 5700 Series

I have tried this new tecnique but this doesnt work neither.
I think its because of the graphic card though.
 
Old 10-17-2012, 04:36 PM   #4
Narann
Rendering, Pipeline, etc.
 
Narann's Avatar
portfolio
Dorian FEVRIER
Lighting/Pipeline TD
Atelier Animation
Montreal, Canada
 
Join Date: Mar 2005
Posts: 414
You graphic card should be ok.

You're example is a little complex. You should try a simpler one.
__________________
My blog (fr)
 
Old 10-17-2012, 04:36 PM   #5
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:19 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.