Simple per-pixel lighting shader not compiling

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
JJJohan
Gnoblar
Posts: 14
Joined: Tue Nov 11, 2008 1:02 pm
Location: Brisbane, Australia
Contact:

Simple per-pixel lighting shader not compiling

Post by JJJohan »

Hello,

I'm at the stage I would like to implement some simple per-pixel lighting into my scene. I noticed there was already an existing snippet on the Wiki's shaders page so I decided to give that a try. It works well on DirectX 11 (with some simple changes - SV_Target output, using a Texture2D object, etc.) however it fails to compile in DirectX 9. The error? Well..

Code: Select all

12:43:28: OGRE EXCEPTION(3:RenderingAPIException): Cannot assemble D3D9 high-level shader Simple_PerPixel_Frag_DX9 Errors:
error X4541: vertex shader must minimally write all four components of POSITION
Okay, fair enough. Sounds like I'm not returning a POSITION variable. Or am I?

Code: Select all

 void main_vp(
	 // in
	 in float4 iPosition : POSITION,
	 in float3 iNorm : NORMAL,
	 // out
	 out float4 oPosition : POSITION,
     out float4 oPositionPS : TEXCOORD0,
     out float3 oNorm : TEXCOORD1, 
	 out float4 oLightPos : TEXCOORD2,	 
     out float3 oEyePos : TEXCOORD3,
	 // uniform
	 uniform float4 lightPosition,
	 uniform float3 eyePosition,
	 uniform float4x4 uWorldViewProj)
 {  
	oPosition = mul(uWorldViewProj, iPosition);
	oPositionPS = iPosition.xyz;
	oLightPos = lightPosition;
    oEyePos = eyePosition;
	oNorm = iNorm;
 } 
I've taken out some stuff and have passed some variables directly by input which no doubt ruins the lighting effect, but I can't for the life of me figure out why it won't pick up the output position. I've tried SV_POSITION, POSITION, POSITION0. I've tried returning the POSITION directly as part of the function. I've even tried returning a struct with the position defined in there.

I'm either overlooking something stupidly simple or something is wrong here. For reference I'm running Ogre 1.10.
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Simple per-pixel lighting shader not compiling

Post by areay »

I've no experience with Ogre 1.10 but looking at that error message I see it's complaining about compiling "Simple_PerPixel_Frag_DX9". It *looks* like you're trying to compile a frag shader as a vertex shader.
User avatar
JJJohan
Gnoblar
Posts: 14
Joined: Tue Nov 11, 2008 1:02 pm
Location: Brisbane, Australia
Contact:

Re: Simple per-pixel lighting shader not compiling

Post by JJJohan »

Aaah, I knew it was something stupid! So that's why it worked in DX11, since I was using a unified vertex/frag program and I somehow mixed the two up. Thanks!
Post Reply