Shader Model 2 Plastic        

Shader Model 2 Plastic Shader

Description

This shader is exported from rendermonkey 1.61 with one change to one line of code in the .material file as noted below. Can't find the rm exporter on the web? It's posted to the bottom of this page.

It should work with gpu's that support shader model 2 and above. A live Openspace scene (that uses Ogre for 3d, Newton for physics, OpenAL for sound) is posted to: http://www.ifam.net/openspace/rmplastic2/web/. You need win os or linux running wine and the scol voyager plugin (from http://scolring.org/index.php/logiciels ) to view the scene. If the plugin is not installed on your system you will be prompted for an install. Openspace like Ogre is opensource.

The upside to this shader like any of the rendermonkey shaders is that you can fool around with the variables in rendermonkey and preview them instantly in that app.

I think there is a bug in the rendermonkey exporter. With some help of one of the developers of openspace, I found that you should change the line:

param_named_auto 0 world_viewProj viewproj_matrix


to

param_indexed_auto 0  worldviewproj_matrix


otherwise if you transform the object that is painted with the shader, the shader won't move or scale along with the node that holds the entity on which the shader is painted.


colleagues: feel free to remove my commented out code, -h



Here is one of my monsters painted in red plastic:
Image

Usage


Just add the material rmplastic to your object.I have not modified it to work with hardware skinnig. Anyone who wants to do that go ahead and edit this page an add the hardware skinning version below mine.


Material file

//DirectX 9.0 HLSL Vertex Shader vs_1_1
vertex_program plasticvertex hlsl
{
	source plasticvertex.hlsl
	target vs_1_1
	entry_point main
}

//DirectX 9.0 HLSL Pixel Shader ps_2_0
fragment_program plasticpixel hlsl
{
	source plasticpixel.hlsl
	target ps_2_0
	entry_point main
}


//Effect: Plastic
material rmplastic
{
	technique
	{
		//Rendering Pass: Single Pass (pass index: #0 )
		pass
		{
			//DirectX 9.0 HLSL Pixel Shader ps_2_0
			fragment_program_ref plasticpixel
			{
				//Shader Constant: color
				param_indexed 0 float4 1.000000 0.300752 0.000000 1.000000
			}
			//DirectX 9.0 HLSL Vertex Shader vs_1_1
			vertex_program_ref plasticvertex
			{
				//Shader Constant: view_position
				//param_named_auto eyePositionWorld camera_position 
				param_indexed_auto 4 camera_position_object_space	
				param_indexed_auto 0  worldviewproj_matrix
			}
		}
	}
}

plasticvertex.hlsl

float4x4 viewproj_matrix : register(c0);
float4 view_position: register(c4);
struct VS_OUTPUT {
   float4 Pos:     POSITION;
   float3 normal:  TEXCOORD0;
   float3 viewVec: TEXCOORD1;
};

VS_OUTPUT main(float4 Pos: POSITION, float3 normal: NORMAL){
   VS_OUTPUT Out;

   Out.Pos = mul(viewproj_matrix, Pos);

   // World-space lighting
   Out.normal = normal;
   Out.viewVec = view_position - Pos;

   return Out;
}

plasticpixel.hlsl

float4 color: register(c0);
float4 main(float3 normal: TEXCOORD0, float3 viewVec: TEXCOORD1) : COLOR {
   // Simple lighting lighting model for a dull plastic appearance.
   float v = 0.5 * (1 + dot(normalize(viewVec), normal));

   return v * color;
}

Alias: Shader Model 2 Plastic