I'd like to share with you a real-time HLSL Shader for Maya’s Viewport that I wrote as part of my exploration into the wonderful world of HLSL.
Try it out, and if you like it, let me know!
Updated - 11/30/2009: lcNextGenShader_1.2.fxUpdated: lcNextGenShader_1.15.fxMy Original Blog PostlcNextGenShader_1.1.fx
Download:
lcNextGenShader_1.1.fx
Sample Cube Map:
default_env_map.ddsTexture Support: the most compatible formats are tga and dds (other 8 bit formats may work - no guarantees)
Techniques:NextGen_SM3 – full shading (requires shader model 3 capable graphics card)
Diffuse_Texture_Only – only the diffuse texture or color, without any other effects
Normal_Map_As_Color – only the normal map color values (helps to find seams)
Specular_Only_SM3 – only the specular effects, light and specular map contributions (requires shader model 3 capable graphics)
Parameters:backFaceLighting – for single sided polygon objects, the back sides will be lit correctly
ambientColor – a color ‘added’ on top of the final effect
diffuseColor – the Lambert diffuse shading color
specularColor – the Phong specular shading color
glossiness – controls the size of the Phong specular highlight
useDiffuseTexture – use the diffuse texture from ‘diffuseMap’ instead of diffuseColor
transparencyInDiffuse – use the diffuseMap’s alpha channel for transparency
specularInDiffuse – use the diffuseMap’s alpha channel for specular masking
diffuseMap – a diffuse texture
useNormalTexture – use a tangent space normal map texture
specularInNormal – use the normalMap’s alpha channel for specular masking
normalPower – intensity of the normal map effect, 0=no effect
flipGreen – invert the green channel of the normal map (default = true)
normalMap – a tangent space normal map texture
useSpecularMap – use a specularMap for specular coloring and masking
specularMap – a specular texture for highlight coloring and masking
useAmbEnv – use cubeEnvMap for ambient environment lighting – cube map is forced down in mip levels – make sure to use a cube map processed by
ATI CubeMapGen for proper filtering
ambPower – intensity of the ambient environment lighting – also multiplied with the ambientColor
useReflEnv - use cubeEnvMap for environment reflections
reflPower – intensity of the environment reflections (has a slight hardcoded Fresnel effect)
cubeEnvMap – a cube map – preferably one processed by ATI CubeMapGen for proper filtering
useGlowTexture – use glowMap for self illumination effects
glowPower – the intensity of the self illumination effect
glowMap – a texture that is ‘added’ on top of the final shader result – self illumination/incandescence
useLightFalloff – use falloff on the point lights
decayScale – scale of the light falloff for the point lights
Light1 is a directional light, lights 2 and 3 are point lightsNote: There are some issues with overlapping transparency planes in Maya’s viewport when using realtime shaders – unfortunately this seems to be a problem with Maya and not the HLSL code itself – so there is no fix available.
Replies
link the proper light type to the light 1, 2, 3 slots.
i really should fix the Fresnel code in the shader, currently its hard-coded into the reflection component only, i'll fix it later in the week to be more fully exposed and tweak-able.
Download: lcNextGenShader_1.15.fx
Update to the shader includes:
Fresnel attributes (fresnel no longer hard coded and now affects both cubemap reflections and specularity)
frBias changes how far across the surface the effect occurs
frETA bumps up the intensity in the center area
frPower Power/intensity multiplier on the entire effect
the main limitations would come from your graphics card, the shader requires a graphics card capable of shader model 3.0 - anything in the past few years should be good, expect for integrated graphics.
And it works on my ATI card unlike the CgFX shader...
11/30/2009
Download: lcNextGenShader_1.2.fx
Added a few things as per requests and my own experimentation
New Features: An experiment in SSS for skin like materials, this could still use some work. A Gloss Map option for modulating the specular shape with a texture - also as a bonus, if you have an environment cube-map it will blur the reflections based on the glossiness.
New Attributes:
sssWeight - the overall intensity of the SSS effect
sssBack - Color of the SSS edge bleed effect
sssRadius - how far across the surface the SSS effect will bleed
useGlossMap - use a gloss map texture yes/no
glossBlurWeight - the overall amount of blurring to the env cube map reflections - 0 turns off the blurring effect
glossBlurMax - the specular glossiness value after which no blurring will happen - usefull for tweaking the blur amount based on your spec glossiness value
glossMap - the gloss map texture (darker values dont work very well here - black turn off specularity)
special thanks to Joel Styles - reading over your hlsl code makes for good learning
No, you dont have to have any of the slots filled in, that is one thing i dont like about most of the realtime shaders out there - with mine, texture slots must be activated. TGA is the format I use.
Other things i can think of: light 1 must be a directional light
your graphics card must be able to run shader model 3
If you still cant get it to work, post a screenshot for me so i can see what you are getting.
this shader seems quite cool. I have it working pretty well. ... but i can't get the env maps to work as lighting. I downloaded your .dds file and used that with no other lights and the model just appears black, and with lights it makes no difference to the 3 light set up look.
i'm on maya 2011. Any idea what could be going wrong here?
cheers
That said, i'll take a look and see what could be going wrong as soon as I have some free time.
yeah i saw that shader thread a few days ago. It looks awesome. Unfortunately, CGFX shaders with Maya and ATI cards seems to be a bit of a "NO GO". I can't get that CGFX shader to work at all .
If future updates can include reflection cosine power mapping and reflectivity mapping would be great.